mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 09:54:41 -05:00
Add encoding suffix to the encoding types and revert renaming the post encodings
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
pub mod tests {
|
||||
|
||||
use leptos::{
|
||||
server,
|
||||
server_fn::{codec, Http, ServerFn, ServerFnError},
|
||||
@@ -20,7 +19,7 @@ pub mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
TypeId::of::<<MyServerAction as ServerFn>::Protocol>(),
|
||||
TypeId::of::<Http<codec::PostUrl, codec::PostJson>>()
|
||||
TypeId::of::<Http<codec::PostUrl, codec::Json>>()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,7 +32,7 @@ pub mod tests {
|
||||
assert_eq!(<FooBar as ServerFn>::PATH, "/foo/bar/my_path");
|
||||
assert_eq!(
|
||||
TypeId::of::<<FooBar as ServerFn>::Protocol>(),
|
||||
TypeId::of::<Http<codec::PostCbor, codec::PostCbor>>()
|
||||
TypeId::of::<Http<codec::Cbor, codec::Cbor>>()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,7 +45,7 @@ pub mod tests {
|
||||
assert_eq!(<FooBar as ServerFn>::PATH, "/foo/bar/my_path");
|
||||
assert_eq!(
|
||||
TypeId::of::<<FooBar as ServerFn>::Protocol>(),
|
||||
TypeId::of::<Http<codec::PostCbor, codec::PostCbor>>()
|
||||
TypeId::of::<Http<codec::Cbor, codec::Cbor>>()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,7 +58,7 @@ pub mod tests {
|
||||
assert_eq!(<FooBar as ServerFn>::PATH, "/api/my_path");
|
||||
assert_eq!(
|
||||
TypeId::of::<<FooBar as ServerFn>::Protocol>(),
|
||||
TypeId::of::<Http<codec::PostUrl, codec::PostJson>>()
|
||||
TypeId::of::<Http<codec::PostUrl, codec::Json>>()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ pub mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
TypeId::of::<<FooBar as ServerFn>::Protocol>(),
|
||||
TypeId::of::<Http<codec::PostUrl, codec::PostJson>>()
|
||||
TypeId::of::<Http<codec::PostUrl, codec::Json>>()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -92,7 +91,7 @@ pub mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
TypeId::of::<<MyServerAction as ServerFn>::Protocol>(),
|
||||
TypeId::of::<Http<codec::PostUrl, codec::PostJson>>()
|
||||
TypeId::of::<Http<codec::PostUrl, codec::Json>>()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -109,7 +108,7 @@ pub mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
TypeId::of::<<MyServerAction as ServerFn>::Protocol>(),
|
||||
TypeId::of::<Http<codec::GetUrl, codec::PostJson>>()
|
||||
TypeId::of::<Http<codec::GetUrl, codec::Json>>()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,7 +124,7 @@ pub mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
TypeId::of::<<MyServerAction as ServerFn>::Protocol>(),
|
||||
TypeId::of::<Http<codec::PostUrl, codec::PostJson>>()
|
||||
TypeId::of::<Http<codec::PostUrl, codec::Json>>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ use bytes::Bytes;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
/// Serializes and deserializes CBOR with [`ciborium`].
|
||||
pub struct Cbor;
|
||||
pub struct CborEncoding;
|
||||
|
||||
impl ContentType for Cbor {
|
||||
impl ContentType for CborEncoding {
|
||||
const CONTENT_TYPE: &'static str = "application/cbor";
|
||||
}
|
||||
|
||||
impl<T> Encodes<T> for Cbor
|
||||
impl<T> Encodes<T> for CborEncoding
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -23,7 +23,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decodes<T> for Cbor
|
||||
impl<T> Decodes<T> for CborEncoding
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
@@ -35,4 +35,4 @@ where
|
||||
}
|
||||
|
||||
/// Pass arguments and receive responses using `cbor` in a `POST` request.
|
||||
pub type PostCbor = Post<Cbor>;
|
||||
pub type Cbor = Post<CborEncoding>;
|
||||
|
||||
@@ -4,13 +4,13 @@ use bytes::Bytes;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
/// Serializes and deserializes JSON with [`serde_json`].
|
||||
pub struct Json;
|
||||
pub struct JsonEncoding;
|
||||
|
||||
impl ContentType for Json {
|
||||
impl ContentType for JsonEncoding {
|
||||
const CONTENT_TYPE: &'static str = "application/json";
|
||||
}
|
||||
|
||||
impl<T> Encodes<T> for Json
|
||||
impl<T> Encodes<T> for JsonEncoding
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -21,7 +21,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decodes<T> for Json
|
||||
impl<T> Decodes<T> for JsonEncoding
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
@@ -33,4 +33,4 @@ where
|
||||
}
|
||||
|
||||
/// Pass arguments and receive responses as JSON in the body of a `POST` request.
|
||||
pub type PostJson = Post<Json>;
|
||||
pub type Json = Post<JsonEncoding>;
|
||||
|
||||
@@ -3,13 +3,13 @@ use bytes::Bytes;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
/// Serializes and deserializes MessagePack with [`rmp_serde`].
|
||||
pub struct MsgPack;
|
||||
pub struct MsgPackEncoding;
|
||||
|
||||
impl ContentType for MsgPack {
|
||||
impl ContentType for MsgPackEncoding {
|
||||
const CONTENT_TYPE: &'static str = "application/msgpack";
|
||||
}
|
||||
|
||||
impl<T> Encodes<T> for MsgPack
|
||||
impl<T> Encodes<T> for MsgPackEncoding
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -20,7 +20,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decodes<T> for MsgPack
|
||||
impl<T> Decodes<T> for MsgPackEncoding
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
@@ -32,4 +32,4 @@ where
|
||||
}
|
||||
|
||||
/// Pass arguments and receive responses as MessagePack in a `POST` request.
|
||||
pub type PostMsgPack = Post<MsgPack>;
|
||||
pub type MsgPack = Post<MsgPackEncoding>;
|
||||
|
||||
@@ -3,13 +3,13 @@ use bytes::Bytes;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
/// A codec for Postcard.
|
||||
pub struct Postcard;
|
||||
pub struct PostcardEncoding;
|
||||
|
||||
impl ContentType for Postcard {
|
||||
impl ContentType for PostcardEncoding {
|
||||
const CONTENT_TYPE: &'static str = "application/x-postcard";
|
||||
}
|
||||
|
||||
impl<T> Encodes<T> for Postcard
|
||||
impl<T> Encodes<T> for PostcardEncoding
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -20,7 +20,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decodes<T> for Postcard
|
||||
impl<T> Decodes<T> for PostcardEncoding
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
@@ -32,4 +32,4 @@ where
|
||||
}
|
||||
|
||||
/// Pass arguments and receive responses with postcard in a `POST` request.
|
||||
pub type PostPostcard = Post<Postcard>;
|
||||
pub type Postcard = Post<PostcardEncoding>;
|
||||
|
||||
@@ -15,13 +15,13 @@ type RkyvDeserializer = HighDeserializer<rancor::Error>;
|
||||
type RkyvValidator<'a> = HighValidator<'a, rancor::Error>;
|
||||
|
||||
/// Pass arguments and receive responses using `rkyv` in a `POST` request.
|
||||
pub struct Rkyv;
|
||||
pub struct RkyvEncoding;
|
||||
|
||||
impl ContentType for Rkyv {
|
||||
impl ContentType for RkyvEncoding {
|
||||
const CONTENT_TYPE: &'static str = "application/rkyv";
|
||||
}
|
||||
|
||||
impl<T> Encodes<T> for Rkyv
|
||||
impl<T> Encodes<T> for RkyvEncoding
|
||||
where
|
||||
T: Archive + for<'a> Serialize<RkyvSerializer<'a>>,
|
||||
T::Archived: Deserialize<T, RkyvDeserializer>
|
||||
@@ -35,7 +35,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decodes<T> for Rkyv
|
||||
impl<T> Decodes<T> for RkyvEncoding
|
||||
where
|
||||
T: Archive + for<'a> Serialize<RkyvSerializer<'a>>,
|
||||
T::Archived: Deserialize<T, RkyvDeserializer>
|
||||
@@ -51,4 +51,4 @@ where
|
||||
}
|
||||
|
||||
/// Pass arguments and receive responses as `rkyv` in a `POST` request.
|
||||
pub type PostRkyv = Post<Rkyv>;
|
||||
pub type Rkyv = Post<RkyvEncoding>;
|
||||
|
||||
@@ -5,13 +5,13 @@ use bytes::Bytes;
|
||||
use serde_lite::{Deserialize, Serialize};
|
||||
|
||||
/// Pass arguments and receive responses as JSON in the body of a `POST` request.
|
||||
pub struct SerdeLite;
|
||||
pub struct SerdeLiteEncoding;
|
||||
|
||||
impl ContentType for SerdeLite {
|
||||
impl ContentType for SerdeLiteEncoding {
|
||||
const CONTENT_TYPE: &'static str = "application/json";
|
||||
}
|
||||
|
||||
impl<T> Encodes<T> for SerdeLite
|
||||
impl<T> Encodes<T> for SerdeLiteEncoding
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
@@ -28,7 +28,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decodes<T> for SerdeLite
|
||||
impl<T> Decodes<T> for SerdeLiteEncoding
|
||||
where
|
||||
T: Deserialize,
|
||||
{
|
||||
@@ -45,4 +45,4 @@ where
|
||||
}
|
||||
|
||||
/// Pass arguments and receive responses as JSON in the body of a `POST` request.
|
||||
pub type PostSerdeLite = Post<SerdeLite>;
|
||||
pub type SerdeLite = Post<SerdeLiteEncoding>;
|
||||
|
||||
@@ -255,7 +255,7 @@ pub fn server_macro_impl(
|
||||
}
|
||||
(Some(input), None) => {
|
||||
parse_quote! {
|
||||
#server_fn_path::Http<#input, #server_fn_path::codec::PostJson>
|
||||
#server_fn_path::Http<#input, #server_fn_path::codec::Json>
|
||||
}
|
||||
}
|
||||
(None, Some(output)) => {
|
||||
@@ -270,7 +270,7 @@ pub fn server_macro_impl(
|
||||
}
|
||||
_ => {
|
||||
parse_quote! {
|
||||
#server_fn_path::Http<#server_fn_path::codec::PostUrl, #server_fn_path::codec::PostJson>
|
||||
#server_fn_path::Http<#server_fn_path::codec::PostUrl, #server_fn_path::codec::Json>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1023,23 +1023,23 @@ impl Parse for ServerFnArgs {
|
||||
if let Some(encoding) = encoding {
|
||||
match encoding.to_string().to_lowercase().as_str() {
|
||||
"\"url\"" => {
|
||||
input = Some(type_from_ident(syn::parse_quote!(PostUrl)));
|
||||
output = Some(type_from_ident(syn::parse_quote!(PostJson)));
|
||||
input = Some(type_from_ident(syn::parse_quote!(Url)));
|
||||
output = Some(type_from_ident(syn::parse_quote!(Json)));
|
||||
builtin_encoding = true;
|
||||
}
|
||||
"\"cbor\"" => {
|
||||
input = Some(type_from_ident(syn::parse_quote!(PostCbor)));
|
||||
output = Some(type_from_ident(syn::parse_quote!(PostCbor)));
|
||||
input = Some(type_from_ident(syn::parse_quote!(Cbor)));
|
||||
output = Some(type_from_ident(syn::parse_quote!(Cbor)));
|
||||
builtin_encoding = true;
|
||||
}
|
||||
"\"getcbor\"" => {
|
||||
input = Some(type_from_ident(syn::parse_quote!(GetUrl)));
|
||||
output = Some(type_from_ident(syn::parse_quote!(PostCbor)));
|
||||
output = Some(type_from_ident(syn::parse_quote!(Cbor)));
|
||||
builtin_encoding = true;
|
||||
}
|
||||
"\"getjson\"" => {
|
||||
input = Some(type_from_ident(syn::parse_quote!(GetUrl)));
|
||||
output = Some(syn::parse_quote!(PostJson));
|
||||
output = Some(syn::parse_quote!(Json));
|
||||
builtin_encoding = true;
|
||||
}
|
||||
_ => {
|
||||
|
||||
Reference in New Issue
Block a user