-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-support-additional-model-field-types-a…
…nd-arrays
- Loading branch information
Showing
17 changed files
with
372 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# To optimize CI runtime: | ||
# A simpler "sanity check" workflow is introduced. | ||
# This workflow only runs if changes in the PR do NOT include | ||
# the `loco-gen` or `loco-new` paths. | ||
# (When changes are made to `loco-gen` or `loco-new`, | ||
# we run comprehensive tests to validate every generator command | ||
# and template option.) | ||
|
||
# Purpose of the sanity check: | ||
# It performs basic validation by comparing the local changes | ||
# against the templates. | ||
# If any breaking changes are detected in the templates, | ||
# the sanity check will fail, signaling an issue. | ||
|
||
name: "[loco_rs:sanity]" | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- "loco-gen/**" | ||
- "loco-new/**" | ||
pull_request: | ||
paths-ignore: | ||
- "loco-gen/**" | ||
- "loco-new/**" | ||
|
||
env: | ||
RUST_TOOLCHAIN: stable | ||
TOOLCHAIN_PROFILE: minimal | ||
|
||
jobs: | ||
sanity: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout the code | ||
uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: ${{ env.RUST_TOOLCHAIN }} | ||
- name: Setup Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Install seaorm cli | ||
run: cargo install sea-orm-cli | ||
|
||
- run: cargo install --path loco-new | ||
|
||
- run: | | ||
loco new -n myappdb --db sqlite --bg async --assets serverside -a | ||
cd myappdb | ||
cargo check | ||
env: | ||
LOCO_DEV_MODE_PATH: ${{ github.workspace }} | ||
- run: | | ||
loco new -n myappnodb --db none --bg none --assets none -a | ||
cd myappdb | ||
cargo check | ||
env: | ||
LOCO_DEV_MODE_PATH: ${{ github.workspace }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod validate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use crate::Error; | ||
use axum::extract::{Form, FromRequest, Json, Request}; | ||
use serde::de::DeserializeOwned; | ||
use validator::Validate; | ||
|
||
#[derive(Debug, Clone, Copy, Default)] | ||
pub struct JsonValidateWithMessage<T>(pub T); | ||
|
||
impl<T, S> FromRequest<S> for JsonValidateWithMessage<T> | ||
where | ||
T: DeserializeOwned + Validate, | ||
S: Send + Sync, | ||
{ | ||
type Rejection = Error; | ||
|
||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> { | ||
let Json(value) = Json::<T>::from_request(req, state).await?; | ||
value.validate()?; | ||
Ok(Self(value)) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Default)] | ||
pub struct FormValidateWithMessage<T>(pub T); | ||
|
||
impl<T, S> FromRequest<S> for FormValidateWithMessage<T> | ||
where | ||
T: DeserializeOwned + Validate, | ||
S: Send + Sync, | ||
{ | ||
type Rejection = Error; | ||
|
||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> { | ||
let Form(value) = Form::<T>::from_request(req, state).await?; | ||
value.validate()?; | ||
Ok(Self(value)) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Default)] | ||
pub struct JsonValidate<T>(pub T); | ||
|
||
impl<T, S> FromRequest<S> for JsonValidate<T> | ||
where | ||
T: DeserializeOwned + Validate, | ||
S: Send + Sync, | ||
{ | ||
type Rejection = Error; | ||
|
||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> { | ||
let Json(value) = Json::<T>::from_request(req, state).await?; | ||
value.validate().map_err(|err| { | ||
tracing::debug!(err = ?err, "request validation error occurred"); | ||
Error::BadRequest(String::new()) | ||
})?; | ||
Ok(Self(value)) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Default)] | ||
pub struct FormValidate<T>(pub T); | ||
|
||
impl<T, S> FromRequest<S> for FormValidate<T> | ||
where | ||
T: DeserializeOwned + Validate, | ||
S: Send + Sync, | ||
{ | ||
type Rejection = Error; | ||
|
||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> { | ||
let Form(value) = Form::<T>::from_request(req, state).await?; | ||
value.validate().map_err(|err| { | ||
tracing::debug!(err = ?err, "request validation error occurred"); | ||
Error::BadRequest(String::new()) | ||
})?; | ||
Ok(Self(value)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.