Skip to content

Commit

Permalink
Merge pull request #36 from blockscout/bragov4ik/bump-deps
Browse files Browse the repository at this point in the history
Upgrade dependencies to their newest versions
  • Loading branch information
bragov4ik authored Jan 21, 2025
2 parents ec0aa8d + 8ee9622 commit 02e264a
Show file tree
Hide file tree
Showing 23 changed files with 1,346 additions and 763 deletions.
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@ members = [
"actix-prost-build",
"actix-prost-macros",
"convert-trait",
"tests"
"tests",
]

# We need the master branch, because https://github.com/tokio-rs/prost/pull/714 isn't published yet
[patch.crates-io]
prost-build = { git = "https://github.com/tokio-rs/prost" }
16 changes: 8 additions & 8 deletions actix-prost-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "actix-prost-build"
version = "0.1.0"
version = "2.0.0"
edition = "2021"

[dependencies]
convert-trait = { path = "../convert-trait", optional = true}
thiserror = "1.0"
convert-trait = { path = "../convert-trait", optional = true }
thiserror = "2.0"
proc-macro2 = "1.0"
prost-build = "0.11"
prost-build = "0.13"
prettyplease = "0.2"
prost-reflect = "0.12.0"
prost-reflect = "0.14.4"
quote = "1.0"
syn = { version = "2.0", features = ["full"] }
serde = { version = "1", features = ["derive"] }
syn = { version = "2.0", features = [ "full" ] }
serde = { version = "1", features = [ "derive" ] }
serde_yaml = "0.9"

[features]
conversions = ["dep:convert-trait"]
conversions = [ "dep:convert-trait" ]
2 changes: 1 addition & 1 deletion actix-prost-build/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl ConversionsGenerator {
let enum_ident = lit.parse::<syn::Path>().ok();
let conv = match m_type {
MessageType::Input => {
quote!(#enum_ident::try_from(from.#name)?)
quote!(#enum_ident::try_from(from.#name).map_err(|e| e.to_string())?)
}
MessageType::Output => {
quote!(from.#name.into())
Expand Down
4 changes: 2 additions & 2 deletions actix-prost-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "actix-prost-macros"
version = "0.1.1"
version = "2.0.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1.0"
syn = { version = "1.0", features = ["extra-traits", "full"] }
syn = { version = "1.0", features = [ "extra-traits", "full" ] }
quote = "1.0"
19 changes: 3 additions & 16 deletions actix-prost-macros/src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use proc_macro2::TokenStream;

enum Kind {
Enum,
OneOf,
}

pub fn process_enum(item: &mut syn::ItemEnum, maybe_rename: Option<String>) -> Option<TokenStream> {
pub fn process_enum(item: &mut syn::ItemEnum, maybe_rename: Option<String>) {
let derive = item
.attrs
.iter()
Expand All @@ -19,7 +17,7 @@ pub fn process_enum(item: &mut syn::ItemEnum, maybe_rename: Option<String>) -> O
});
let derive = match derive {
Some(syn::Meta::List(derive)) => derive,
_ => return None,
_ => return,
};
let kind = derive
.nested
Expand All @@ -39,29 +37,18 @@ pub fn process_enum(item: &mut syn::ItemEnum, maybe_rename: Option<String>) -> O
.next();
let kind = match kind {
Some(kind) => kind,
None => return None,
None => return,
};
match kind {
Kind::OneOf => {
if let Some(rename) = maybe_rename {
item.attrs
.push(syn::parse_quote!(#[serde(rename_all=#rename)]));
}
None
}
Kind::Enum => {
item.attrs
.push(syn::parse_quote!(#[serde(rename_all="SCREAMING_SNAKE_CASE")]));

let name = &item.ident;
Some(quote::quote!(
impl TryFrom<i32> for #name {
type Error = String;
fn try_from(value: i32) -> Result<Self, Self::Error> {
Self::from_i32(value).ok_or("enum value out of range".into())
}
}
))
}
}
}
6 changes: 2 additions & 4 deletions actix-prost-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub fn serde(attrs: TokenStream, item: TokenStream) -> TokenStream {
None => Some("camelCase".to_owned()),
};

let mut result = quote::quote!();
// Checking that no other `actix_prost_macros::serde` attributes exist for an item
// allows us to override 'rename_all' attribute for the type.
// That allows to specify a default serialization case convention and override it
Expand All @@ -70,8 +69,7 @@ pub fn serde(attrs: TokenStream, item: TokenStream) -> TokenStream {
}
item.attrs
.push(syn::parse_quote!(#[derive(serde::Serialize, serde::Deserialize)]));
let enums = process_enum(item, maybe_rename.clone());
result = quote::quote!(#result #enums);
process_enum(item, maybe_rename.clone());
}
syn::Item::Struct(item) if !has_other_actix_prost_serde_attributes(&item.attrs) => {
let mut need_serde_as = false;
Expand All @@ -94,5 +92,5 @@ pub fn serde(attrs: TokenStream, item: TokenStream) -> TokenStream {
}
_ => {}
}
quote!(#item #result).into()
quote!(#item).into()
}
12 changes: 6 additions & 6 deletions actix-prost/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "actix-prost"
version = "0.1.0"
version = "2.0.0"
edition = "2021"

[dependencies]
http = "0.2"
tonic = "0.8"
http = "1.2"
tonic = "0.12"
actix-web = "4"
actix-http = "3"
serde = { version = "1", features = ["derive"] }
serde_with = { version = "2.0", features = ["base64"] }
prost = "0.11"
serde = { version = "1", features = [ "derive" ] }
serde_with = { version = "3.12", features = [ "base64" ] }
prost = "0.13"
serde_json = "1.0"
8 changes: 5 additions & 3 deletions actix-prost/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use serde_with::{serde_as, FromInto};
use std::fmt::Display;
use tonic::{Code, Status};

use crate::http_compatibility::to_actix_status;

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Error {
Expand Down Expand Up @@ -53,8 +55,8 @@ impl Display for Error {
}

impl ResponseError for Error {
fn status_code(&self) -> StatusCode {
Self::map_tonic_code(self.code)
fn status_code(&self) -> actix_web::http::StatusCode {
to_actix_status(Self::map_tonic_code(self.code))
}

fn error_response(&self) -> HttpResponse<BoxBody> {
Expand All @@ -70,7 +72,7 @@ impl ResponseError for Error {
err,
self
);
HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR)
HttpResponse::build(actix_http::StatusCode::INTERNAL_SERVER_ERROR)
.content_type("application/json")
.body(body)
}
Expand Down
8 changes: 7 additions & 1 deletion actix-prost/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use crate::http_compatibility::from_actix_header;

pub fn map_actix_headers(headers: &actix_http::header::HeaderMap) -> http::HeaderMap {
http::HeaderMap::from_iter(headers.iter().map(|(k, v)| (k.clone(), v.clone())))
http::HeaderMap::from_iter(
headers
.iter()
.map(|(k, v)| from_actix_header((k.clone(), v.clone()))),
)
}

pub fn map_headers(headers: &actix_http::header::HeaderMap) -> tonic::metadata::MetadataMap {
Expand Down
118 changes: 118 additions & 0 deletions actix-prost/src/http_compatibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use std::str::FromStr;

pub fn to_actix_status(status: http::StatusCode) -> actix_web::http::StatusCode {
actix_web::http::StatusCode::from_u16(status.as_u16()).expect("status codes are always valid")
}

pub fn from_actix_header(
header: (
actix_http::header::HeaderName,
actix_http::header::HeaderValue,
),
) -> (http::HeaderName, http::HeaderValue) {
(
http::HeaderName::from_str(header.0.as_str()).expect("was a valid header name"),
http::HeaderValue::from_bytes(header.1.as_bytes()).expect("was a valid header value"),
)
}
#[cfg(test)]
mod tests {
use super::*;
use actix_http::header::{HeaderName, HeaderValue};
use std::str::FromStr;

#[test]
fn test_header_names() {
let a_1 = "a".repeat(1);
let a_8192 = "a".repeat(8192);
let a_8193 = "a".repeat(8193);
let a_16384 = "a".repeat(16384);
let a_16385 = "a".repeat(16385);

let test_cases = vec![
// Empty
"",
// Single characters
"a",
"A",
"-",
// Common headers
"content-type",
"x-custom-header",
"CONTENT-TYPE",
"X-CUSTOM-HEADER",
// Various lengths
&a_1,
&a_8192,
&a_8193,
&a_16384,
&a_16385,
// Special characters
"header\0name",
"header\tname",
"header name",
"headerñame",
"header\r\name",
"header\n\name",
"header:name",
// Mixed case
"Content-Type",
"X-Mixed-Case",
];

for input in test_cases {
if let Ok(name) = HeaderName::from_str(input) {
let dummy_value = HeaderValue::from_static("");
let _ = from_actix_header((name, dummy_value));
}
}
}

#[test]
fn test_header_values() {
let valid_name = HeaderName::from_static("x-test");

let nul = '\u{0}'.to_string();
let us = '\u{1f}'.to_string();
let del = '\u{7f}'.to_string();
let a_8192 = "a".repeat(8192);
let a_16384 = "a".repeat(16384);

let test_cases = vec![
// Empty
"",
// ASCII range
&nul, // NUL
"\t", // TAB
&us, // US
" ", // space
"~", // tilde
&del, // DEL
// ASCII printable
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
// Control characters
"\n",
"\r",
"\x0B", // VT
"\x0C", // FF
// UTF-8 sequences
"Hello™",
"Hello🌍",
"Привет",
// Mixed content
"Hello\nWorld",
"Hello\0World",
"Hello\tWorld",
// Long values
&a_8192,
&a_16384,
];

for input in test_cases {
if let Ok(value) = HeaderValue::from_str(input) {
let _ = from_actix_header((valid_name.clone(), value));
}
}
}
}
1 change: 1 addition & 0 deletions actix-prost/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod error;
pub mod header;
pub mod http_compatibility;
pub mod request;
pub mod serde;

Expand Down
18 changes: 9 additions & 9 deletions convert-trait/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "convert-trait"
version = "0.1.0"
version = "2.0.0"
edition = "2021"

[dependencies]
ethers-core = { version = "2.0.0", optional = true }
bytes = { version = "1.3", optional = true }
hex = { version = "0.4", optional = true}
ethers-core = { version = "2.0.14", optional = true }
bytes = { version = "1.9", optional = true }
hex = { version = "0.4", optional = true }
url = { version = "2", optional = true }

[features]
default = ["conv-full"]
conv-full = ["conv-bytes", "conv-address", "conv-url"]
conv-bytes = ["dep:bytes", "dep:hex"]
conv-address = ["dep:ethers-core"]
conv-url = ["dep:url"]
default = [ "conv-full" ]
conv-full = [ "conv-bytes", "conv-address", "conv-url" ]
conv-bytes = [ "dep:bytes", "dep:hex" ]
conv-address = [ "dep:ethers-core" ]
conv-url = [ "dep:url" ]
Loading

0 comments on commit 02e264a

Please sign in to comment.