Skip to content

Commit

Permalink
chore: centralize serializer for wasm-bindgen values
Browse files Browse the repository at this point in the history
  • Loading branch information
enmand committed Feb 25, 2024
1 parent 704fc94 commit aec057d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
7 changes: 2 additions & 5 deletions crates/dwn-rs-wasm/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use wasm_bindgen::prelude::*;

use dwn_rs_stores::{Filter as DBFilter, Filters};

use crate::ser::serializer;

#[wasm_bindgen(typescript_custom_section)]
const INDEX_MAP: &'static str = r#"import { Filter } from "@tbd54566975/dwn-sdk-js";
Expand Down Expand Up @@ -52,8 +54,3 @@ impl From<Filters> for Filter {
wasm_bindgen::JsValue::default().into()
}
}

#[inline]
fn serializer() -> serde_wasm_bindgen::Serializer {
serde_wasm_bindgen::Serializer::new().serialize_maps_as_objects(true)
}
1 change: 1 addition & 0 deletions crates/dwn-rs-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod filter;
mod message;
mod query;
pub(crate) mod ser;

#[cfg(feature = "surrealdb")]
mod surrealdb;
7 changes: 2 additions & 5 deletions crates/dwn-rs-wasm/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use wasm_bindgen::prelude::*;

use dwn_rs_core::Message;

use crate::ser::serializer;

#[wasm_bindgen(typescript_custom_section)]
const MESSAGE_IMPORT: &'static str = r#"import { GenericMessage } from "@tbd54566975/dwn-sdk-js";"#;

Expand Down Expand Up @@ -59,8 +61,3 @@ impl From<Vec<Message>> for GenericMessageArray {
wasm_bindgen::JsValue::default().into()
}
}

#[inline]
fn serializer() -> serde_wasm_bindgen::Serializer {
serde_wasm_bindgen::Serializer::new().serialize_maps_as_objects(true)
}
7 changes: 2 additions & 5 deletions crates/dwn-rs-wasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use wasm_bindgen::prelude::*;

use dwn_rs_stores::{MessageSort, Pagination, QueryReturn};

use crate::ser::serializer;

#[wasm_bindgen(typescript_custom_section)]
const QUERY_TYPES: &'static str = r#"
export type QueryReturn = {
Expand Down Expand Up @@ -58,8 +60,3 @@ impl TryFrom<JSPagination> for Pagination {
serde_wasm_bindgen::from_value(value.into())
}
}

#[inline]
fn serializer() -> serde_wasm_bindgen::Serializer {
serde_wasm_bindgen::Serializer::new().serialize_maps_as_objects(true)
}
6 changes: 6 additions & 0 deletions crates/dwn-rs-wasm/src/ser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use serde_wasm_bindgen::Serializer;

#[inline]
pub(crate) fn serializer() -> Serializer {
Serializer::new().serialize_maps_as_objects(true)
}

0 comments on commit aec057d

Please sign in to comment.