chore: update validator crate

This commit is contained in:
khorshuheng 2024-12-11 12:33:46 +08:00
parent 7cd7ea1f9e
commit 719b95b94a
16 changed files with 605 additions and 222 deletions

671
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -58,7 +58,7 @@ reqwest = { workspace = true, features = [
unicode-segmentation = "1.10" unicode-segmentation = "1.10"
lazy_static.workspace = true lazy_static.workspace = true
fancy-regex = "0.11.0" fancy-regex = "0.11.0"
validator = "0.16.1" validator.workspace = true
bytes = "1.5.0" bytes = "1.5.0"
rcgen = { version = "0.10.0", features = ["pem", "x509-parser"] } rcgen = { version = "0.10.0", features = ["pem", "x509-parser"] }
mime = "0.3.17" mime = "0.3.17"
@ -283,6 +283,7 @@ sanitize-filename = "0.5.0"
base64 = "0.22" base64 = "0.22"
md5 = "0.7.0" md5 = "0.7.0"
pin-project = "1.1.5" pin-project = "1.1.5"
validator = "0.19"
zstd = { version = "0.13.2", features = [] } zstd = { version = "0.13.2", features = [] }
# collaboration # collaboration

View File

@ -19,7 +19,11 @@ askama = "0.12"
axum-extra = { version = "0.9", features = ["cookie"] } axum-extra = { version = "0.9", features = ["cookie"] }
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
redis = { version = "0.25.2", features = ["aio", "tokio-comp", "connection-manager"] } redis = { version = "0.25.2", features = [
"aio",
"tokio-comp",
"connection-manager",
] }
uuid = { workspace = true, features = ["v4"] } uuid = { workspace = true, features = ["v4"] }
dotenvy = "0.15" dotenvy = "0.15"
reqwest = "0.11.27" reqwest = "0.11.27"

View File

@ -17,7 +17,7 @@ sqlx = { workspace = true, default-features = false, features = [
"postgres", "postgres",
"json", "json",
], optional = true } ], optional = true }
validator = { version = "0.16", optional = true } validator = { workspace = true, optional = true }
url = { version = "2.5.0" } url = { version = "2.5.0" }
actix-web = { version = "4.4.1", optional = true } actix-web = { version = "4.4.1", optional = true }
reqwest.workspace = true reqwest.workspace = true

View File

@ -6,7 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
reqwest = { version = "0.12", features = ["json", "rustls-tls", "cookies", "stream"], optional = true } reqwest = { version = "0.12", features = [
"json",
"rustls-tls",
"cookies",
"stream",
], optional = true }
serde = { version = "1.0.199", features = ["derive"], optional = true } serde = { version = "1.0.199", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true } serde_json = { version = "1.0", optional = true }
thiserror = "1.0.58" thiserror = "1.0.58"
@ -20,11 +25,24 @@ pin-project = "1.1.5"
[dev-dependencies] [dev-dependencies]
appflowy-ai-client = { path = ".", features = ["dto", "client-api"] } appflowy-ai-client = { path = ".", features = ["dto", "client-api"] }
tokio = { version = "1.37.0", features = ["macros", "test-util"] } tokio = { version = "1.37.0", features = ["macros", "test-util"] }
tracing-subscriber = { version = "0.3.18", features = ["registry", "env-filter", "ansi", "json"] } tracing-subscriber = { version = "0.3.18", features = [
"registry",
"env-filter",
"ansi",
"json",
] }
uuid = { workspace = true, features = ["v4"] } uuid = { workspace = true, features = ["v4"] }
infra.workspace = true infra.workspace = true
[features] [features]
default = ["client-api"] default = ["client-api"]
client-api = ["dto", "reqwest", "serde", "serde_json", "tracing", "serde_repr", "infra/request_util"] client-api = [
dto = ["serde", "serde_json", "serde_repr"] "dto",
"reqwest",
"serde",
"serde_json",
"tracing",
"serde_repr",
"infra/request_util",
]
dto = ["serde", "serde_json", "serde_repr"]

View File

@ -8,12 +8,12 @@ edition = "2021"
native-tls = ["tokio-tungstenite/native-tls"] native-tls = ["tokio-tungstenite/native-tls"]
native-tls-vendored = ["native-tls", "tokio-tungstenite/native-tls-vendored"] native-tls-vendored = ["native-tls", "tokio-tungstenite/native-tls-vendored"]
rustls-tls-native-roots = [ rustls-tls-native-roots = [
"__rustls-tls", "__rustls-tls",
"tokio-tungstenite/rustls-tls-native-roots", "tokio-tungstenite/rustls-tls-native-roots",
] ]
rustls-tls-webpki-roots = [ rustls-tls-webpki-roots = [
"__rustls-tls", "__rustls-tls",
"tokio-tungstenite/rustls-tls-webpki-roots", "tokio-tungstenite/rustls-tls-webpki-roots",
] ]
__rustls-tls = [] __rustls-tls = []
@ -22,8 +22,8 @@ thiserror = "1"
http = "0.2" http = "0.2"
httparse = "1.8" httparse = "1.8"
futures-util = { version = "0.3", default-features = false, features = [ futures-util = { version = "0.3", default-features = false, features = [
"sink", "sink",
"std", "std",
] } ] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
@ -39,11 +39,11 @@ percent-encoding = "2.3.1"
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys] [target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3" version = "0.3"
features = [ features = [
"WebSocket", "WebSocket",
"MessageEvent", "MessageEvent",
"CloseEvent", "CloseEvent",
"Event", "Event",
"ErrorEvent", "ErrorEvent",
"BinaryType", "BinaryType",
"Blob", "Blob",
] ]

View File

@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"]
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
collab-entity = { workspace = true } collab-entity = { workspace = true }
validator = { version = "0.16", features = ["validator_derive", "derive"] } validator = { workspace = true, features = ["validator_derive", "derive"] }
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
uuid = { workspace = true, features = ["serde", "v4"] } uuid = { workspace = true, features = ["serde", "v4"] }
thiserror = "1.0.56" thiserror = "1.0.56"

View File

@ -24,13 +24,13 @@ pub const ZSTD_COMPRESSION_LEVEL: i32 = 3;
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct CreateCollabParams { pub struct CreateCollabParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub object_id: String, pub object_id: String,
#[validate(custom = "validate_not_empty_payload")] #[validate(custom(function = "validate_not_empty_payload"))]
pub encoded_collab_v1: Vec<u8>, pub encoded_collab_v1: Vec<u8>,
pub collab_type: CollabType, pub collab_type: CollabType,
@ -88,9 +88,9 @@ impl PendingCollabWrite {
#[derive(Debug, Clone, Validate, Serialize, Deserialize, PartialEq)] #[derive(Debug, Clone, Validate, Serialize, Deserialize, PartialEq)]
pub struct CollabParams { pub struct CollabParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub object_id: String, pub object_id: String,
#[validate(custom = "validate_not_empty_payload")] #[validate(custom(function = "validate_not_empty_payload"))]
pub encoded_collab_v1: Bytes, pub encoded_collab_v1: Bytes,
pub collab_type: CollabType, pub collab_type: CollabType,
#[serde(default)] #[serde(default)]
@ -196,7 +196,7 @@ struct CollabParamsV0 {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct BatchCreateCollabParams { pub struct BatchCreateCollabParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
pub params_list: Vec<CollabParams>, pub params_list: Vec<CollabParams>,
} }
@ -219,19 +219,19 @@ pub struct UpdateCollabWebParams {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct DeleteCollabParams { pub struct DeleteCollabParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub object_id: String, pub object_id: String,
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
} }
#[derive(Debug, Clone, Validate)] #[derive(Debug, Clone, Validate)]
pub struct InsertSnapshotParams { pub struct InsertSnapshotParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub object_id: String, pub object_id: String,
#[validate(custom = "validate_not_empty_payload")] #[validate(custom(function = "validate_not_empty_payload"))]
pub data: Bytes, pub data: Bytes,
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
pub collab_type: CollabType, pub collab_type: CollabType,
} }
@ -250,9 +250,9 @@ pub struct QuerySnapshotParams {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct QueryCollabParams { pub struct QueryCollabParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
#[validate] #[validate(nested)]
pub inner: QueryCollab, pub inner: QueryCollab,
} }
@ -295,7 +295,7 @@ impl Deref for QueryCollabParams {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct QueryCollab { pub struct QueryCollab {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub object_id: String, pub object_id: String,
pub collab_type: CollabType, pub collab_type: CollabType,
} }
@ -369,9 +369,9 @@ pub struct WorkspaceUsage {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct InsertCollabMemberParams { pub struct InsertCollabMemberParams {
pub uid: i64, pub uid: i64,
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub object_id: String, pub object_id: String,
pub access_level: AFAccessLevel, pub access_level: AFAccessLevel,
} }
@ -381,9 +381,9 @@ pub type UpdateCollabMemberParams = InsertCollabMemberParams;
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct CollabMemberIdentify { pub struct CollabMemberIdentify {
pub uid: i64, pub uid: i64,
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub object_id: String, pub object_id: String,
} }
@ -406,15 +406,15 @@ pub struct DefaultPublishViewInfoMeta {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct QueryCollabMembers { pub struct QueryCollabMembers {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub object_id: String, pub object_id: String,
} }
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct QueryWorkspaceMember { pub struct QueryWorkspaceMember {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_id: String, pub workspace_id: String,
pub uid: i64, pub uid: i64,
@ -1207,7 +1207,7 @@ pub struct ApproveAccessRequestParams {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct CreateImportTask { pub struct CreateImportTask {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub workspace_name: String, pub workspace_name: String,
pub content_length: u64, pub content_length: u64,
} }

View File

@ -9,7 +9,7 @@ edition = "2021"
collab = { workspace = true } collab = { workspace = true }
collab-entity = { workspace = true } collab-entity = { workspace = true }
collab-rt-entity = { workspace = true } collab-rt-entity = { workspace = true }
validator = { version = "0.16", features = ["validator_derive", "derive"] } validator = { workspace = true, features = ["validator_derive", "derive"] }
database-entity.workspace = true database-entity.workspace = true
shared-entity.workspace = true shared-entity.workspace = true
app-error = { workspace = true, features = ["sqlx_error", "validation_error"] } app-error = { workspace = true, features = ["sqlx_error", "validation_error"] }

View File

@ -15,10 +15,7 @@ bytes = { workspace = true }
tokio = { workspace = true, optional = true } tokio = { workspace = true, optional = true }
pin-project.workspace = true pin-project.workspace = true
futures = "0.3.30" futures = "0.3.30"
validator = { version = "0.16", features = [ validator = { workspace = true, features = ["validator_derive", "derive"] }
"validator_derive",
"derive",
] }
[features] [features]
file_util = ["tokio/fs"] file_util = ["tokio/fs"]

View File

@ -29,10 +29,7 @@ pin-project = "1.1.5"
actix-web = { version = "4.4.1", default-features = false, features = [ actix-web = { version = "4.4.1", default-features = false, features = [
"http2", "http2",
], optional = true } ], optional = true }
validator = { version = "0.16", features = [ validator = { workspace = true, features = ["validator_derive", "derive"] }
"validator_derive",
"derive",
] }
futures = "0.3.30" futures = "0.3.30"
bytes = "1.6.0" bytes = "1.6.0"
log = "0.4.21" log = "0.4.21"

View File

@ -10,7 +10,7 @@ use validator::Validate;
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct CreateChatParams { pub struct CreateChatParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub chat_id: String, pub chat_id: String,
pub name: String, pub name: String,
pub rag_ids: Vec<String>, pub rag_ids: Vec<String>,
@ -18,7 +18,7 @@ pub struct CreateChatParams {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct UpdateChatParams { pub struct UpdateChatParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub name: Option<String>, pub name: Option<String>,
/// Key-value pairs of metadata to be updated. /// Key-value pairs of metadata to be updated.
@ -29,7 +29,7 @@ pub struct UpdateChatParams {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct CreateChatMessageParams { pub struct CreateChatMessageParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub content: String, pub content: String,
pub message_type: ChatMessageType, pub message_type: ChatMessageType,
#[serde(deserialize_with = "deserialize_metadata")] #[serde(deserialize_with = "deserialize_metadata")]
@ -40,7 +40,7 @@ pub struct CreateChatMessageParams {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct CreateChatMessageParamsV2 { pub struct CreateChatMessageParamsV2 {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub content: String, pub content: String,
pub message_type: ChatMessageType, pub message_type: ChatMessageType,
#[serde(deserialize_with = "deserialize_metadata")] #[serde(deserialize_with = "deserialize_metadata")]
@ -361,7 +361,7 @@ pub struct UpdateChatMessageResponse {
#[derive(Debug, Clone, Validate, Serialize, Deserialize)] #[derive(Debug, Clone, Validate, Serialize, Deserialize)]
pub struct CreateAnswerMessageParams { pub struct CreateAnswerMessageParams {
#[validate(custom = "validate_not_empty_str")] #[validate(custom(function = "validate_not_empty_str"))]
pub content: String, pub content: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]

View File

@ -3,7 +3,7 @@
# Generate the current dependency list # Generate the current dependency list
cargo tree > current_deps.txt cargo tree > current_deps.txt
BASELINE_COUNT=642 BASELINE_COUNT=720
CURRENT_COUNT=$(cat current_deps.txt | wc -l) CURRENT_COUNT=$(cat current_deps.txt | wc -l)
echo "Expected dependency count (baseline): $BASELINE_COUNT" echo "Expected dependency count (baseline): $BASELINE_COUNT"

View File

@ -85,7 +85,7 @@ shared-entity = { workspace = true, features = ["cloud"] }
parking_lot = "0.12.1" parking_lot = "0.12.1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
itertools = "0.12.0" itertools = "0.12.0"
validator = "0.16.1" validator.workspace = true
rayon.workspace = true rayon.workspace = true
tiktoken-rs = "0.6.0" tiktoken-rs = "0.6.0"
unicode-segmentation = "1.9.0" unicode-segmentation = "1.9.0"

View File

@ -25,7 +25,12 @@ database.workspace = true
database-entity.workspace = true database-entity.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "net"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros", "net"] }
tokio-stream = { version = "0.1", features = ["net"] } tokio-stream = { version = "0.1", features = ["net"] }
redis = { workspace = true, features = ["aio", "tokio-comp", "connection-manager", "streams"] } redis = { workspace = true, features = [
"aio",
"tokio-comp",
"connection-manager",
"streams",
] }
dotenvy = "0.15.0" dotenvy = "0.15.0"
axum = "0.7.4" axum = "0.7.4"
thiserror = "1.0.58" thiserror = "1.0.58"
@ -33,7 +38,14 @@ tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
serde_repr = "0.1.18" serde_repr = "0.1.18"
futures = "0.3.30" futures = "0.3.30"
infra = { workspace = true, features = ["request_util"] } infra = { workspace = true, features = ["request_util"] }
sqlx = { workspace = true, default-features = false, features = ["runtime-tokio-rustls", "macros", "postgres", "uuid", "chrono", "migrate"] } sqlx = { workspace = true, default-features = false, features = [
"runtime-tokio-rustls",
"macros",
"postgres",
"uuid",
"chrono",
"migrate",
] }
secrecy = { version = "0.8", features = ["serde"] } secrecy = { version = "0.8", features = ["serde"] }
aws-sdk-s3 = { version = "1.36.0", features = [ aws-sdk-s3 = { version = "1.36.0", features = [
"behavior-version-latest", "behavior-version-latest",
@ -51,4 +63,3 @@ base64.workspace = true
prometheus-client = "0.22.3" prometheus-client = "0.22.3"
reqwest = "0.12.5" reqwest = "0.12.5"
zstd.workspace = true zstd.workspace = true

View File

@ -1,4 +1,4 @@
use validator::validate_email; use validator::ValidateEmail;
#[derive(Debug)] #[derive(Debug)]
pub struct UserEmail(pub String); pub struct UserEmail(pub String);
@ -9,7 +9,7 @@ impl UserEmail {
return Err("Email can not be empty or whitespace".to_string()); return Err("Email can not be empty or whitespace".to_string());
} }
if validate_email(&s) { if s.validate_email() {
Ok(Self(s)) Ok(Self(s))
} else { } else {
Err("Invalid email".to_string()) Err("Invalid email".to_string())