diff --git a/bindings/nostr-js/src/event/builder.rs b/bindings/nostr-js/src/event/builder.rs index 3d5909f11..ba46e6fdd 100644 --- a/bindings/nostr-js/src/event/builder.rs +++ b/bindings/nostr-js/src/event/builder.rs @@ -385,7 +385,7 @@ impl JsEventBuilder { } #[wasm_bindgen(js_name = stallData)] - pub fn stall_data(data: JsStallData) -> Self { + pub fn stall_data(data: &JsStallData) -> Self { Self { builder: EventBuilder::stall_data(data.deref().clone()), } diff --git a/bindings/nostr-js/src/event/tag.rs b/bindings/nostr-js/src/event/tag.rs index eed2e69ca..ac7a6d1ea 100644 --- a/bindings/nostr-js/src/event/tag.rs +++ b/bindings/nostr-js/src/event/tag.rs @@ -39,8 +39,9 @@ impl From for HttpMethod { #[wasm_bindgen(js_name = Thumbnails)] pub struct JsThumbnails { - url: String, - dimensions: Option, + #[wasm_bindgen(getter_with_clone)] + pub url: String, + pub dimensions: Option, } impl From for (UncheckedUrl, Option) { @@ -52,6 +53,14 @@ impl From for (UncheckedUrl, Option) { } } +#[wasm_bindgen(js_class = Thumbnails)] +impl JsThumbnails { + #[wasm_bindgen(constructor)] + pub fn new(url: String, dimensions: Option) -> Self { + Self { url, dimensions } + } +} + #[derive(Clone, Copy)] #[wasm_bindgen(js_name = ImageDimensions)] pub struct JsImageDimensions { diff --git a/bindings/nostr-js/src/key/public_key.rs b/bindings/nostr-js/src/key/public_key.rs index 4db33e854..fde2786cc 100644 --- a/bindings/nostr-js/src/key/public_key.rs +++ b/bindings/nostr-js/src/key/public_key.rs @@ -9,6 +9,7 @@ use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; +#[derive(Clone, Copy)] #[wasm_bindgen(js_name = PublicKey)] pub struct JsPublicKey { pub(crate) inner: PublicKey, diff --git a/bindings/nostr-js/src/nips/nip15.rs b/bindings/nostr-js/src/nips/nip15.rs index 3369ec56e..abaebda45 100644 --- a/bindings/nostr-js/src/nips/nip15.rs +++ b/bindings/nostr-js/src/nips/nip15.rs @@ -58,10 +58,12 @@ impl Deref for JsShippingMethod { #[wasm_bindgen(js_class = ShippingMethod)] impl JsShippingMethod { + #[wasm_bindgen(constructor)] pub fn new(id: &str, cost: f64) -> Self { ShippingMethod::new(id, cost).into() } + #[wasm_bindgen(js_name = getShuppingCost)] pub fn get_shipping_cost(&self) -> JsShippingCost { ShippingMethod::get_shipping_cost(self.deref()).into() } @@ -108,6 +110,7 @@ impl Deref for JsStallData { #[wasm_bindgen(js_class = StallData)] impl JsStallData { + #[wasm_bindgen(constructor)] pub fn new(id: &str, name: &str, currency: &str) -> Self { StallData::new(id, name, currency).into() } @@ -162,6 +165,7 @@ impl From for ProductData { #[wasm_bindgen(js_class = ProductData)] impl JsProductData { + #[wasm_bindgen(constructor)] pub fn new(id: &str, stall_id: &str, name: &str, currency: &str) -> Self { ProductData::new(id, stall_id, name, currency).into() } diff --git a/bindings/nostr-js/src/nips/nip53.rs b/bindings/nostr-js/src/nips/nip53.rs index 1d9dc7ddd..d7c5a295b 100644 --- a/bindings/nostr-js/src/nips/nip53.rs +++ b/bindings/nostr-js/src/nips/nip53.rs @@ -11,12 +11,13 @@ use crate::event::tag::JsImageDimensions; use crate::key::JsPublicKey; #[wasm_bindgen(js_name = Image)] -pub struct Image { - url: String, - dimensions: Option, +pub struct JsImage { + #[wasm_bindgen(getter_with_clone)] + pub url: String, + pub dimensions: Option, } -impl From<(UncheckedUrl, Option)> for Image { +impl From<(UncheckedUrl, Option)> for JsImage { fn from(value: (UncheckedUrl, Option)) -> Self { Self { url: value.0.to_string(), @@ -25,23 +26,23 @@ impl From<(UncheckedUrl, Option)> for Image { } } -impl Image { - pub fn url(&self) -> String { - self.url.to_string() - } - - pub fn dimensions(&self) -> Option { - self.dimensions.clone().map(|d| d.into()) +#[wasm_bindgen(js_class = Image)] +impl JsImage { + #[wasm_bindgen(constructor)] + pub fn new(url: String, dimensions: Option) -> Self { + Self { url, dimensions } } } #[wasm_bindgen(js_name = User)] -pub struct User { - public_key: JsPublicKey, - url: Option, +pub struct JsUser { + #[wasm_bindgen(js_name = publicKey)] + pub public_key: JsPublicKey, + #[wasm_bindgen(getter_with_clone)] + pub url: Option, } -impl From<(PublicKey, Option)> for User { +impl From<(PublicKey, Option)> for JsUser { fn from(value: (PublicKey, Option)) -> Self { Self { public_key: value.0.into(), @@ -50,13 +51,11 @@ impl From<(PublicKey, Option)> for User { } } -impl User { - pub fn public_key(&self) -> JsPublicKey { - self.public_key.clone().into() - } - - pub fn url(&self) -> Option { - self.url.clone() +#[wasm_bindgen(js_class = User)] +impl JsUser { + #[wasm_bindgen(constructor)] + pub fn new(public_key: JsPublicKey, url: Option) -> Self { + Self { public_key, url } } } @@ -81,24 +80,28 @@ impl Deref for JsLiveEventStatus { #[wasm_bindgen(js_class = LiveEventStatus)] impl JsLiveEventStatus { + #[wasm_bindgen(constructor)] pub fn planned() -> Self { Self { inner: LiveEventStatus::Planned, } } + #[wasm_bindgen(constructor)] pub fn live() -> Self { Self { inner: LiveEventStatus::Live, } } + #[wasm_bindgen(constructor)] pub fn ended() -> Self { Self { inner: LiveEventStatus::Ended, } } + #[wasm_bindgen(constructor)] pub fn custom(string: String) -> Self { Self { inner: LiveEventStatus::Custom(string), @@ -178,7 +181,7 @@ impl JsLiveEvent { } #[wasm_bindgen(getter)] - pub fn image(&self) -> Option { + pub fn image(&self) -> Option { self.inner.image.clone().map(|i| i.into()) } @@ -238,7 +241,7 @@ impl JsLiveEvent { } #[wasm_bindgen(getter)] - pub fn speakers(&self) -> Vec { + pub fn speakers(&self) -> Vec { self.inner .speakers .clone() @@ -248,7 +251,7 @@ impl JsLiveEvent { } #[wasm_bindgen(getter)] - pub fn participants(&self) -> Vec { + pub fn participants(&self) -> Vec { self.inner .participants .clone() diff --git a/bindings/nostr-js/src/nips/nip57.rs b/bindings/nostr-js/src/nips/nip57.rs index 574a48e9c..f4dd2f87a 100644 --- a/bindings/nostr-js/src/nips/nip57.rs +++ b/bindings/nostr-js/src/nips/nip57.rs @@ -63,6 +63,7 @@ impl Deref for JsZapRequestData { #[wasm_bindgen(js_class = ZapRequestData)] impl JsZapRequestData { + #[wasm_bindgen(constructor)] pub fn new( public_key: &JsPublicKey, relays: Vec, diff --git a/bindings/nostr-js/src/nips/nip65.rs b/bindings/nostr-js/src/nips/nip65.rs index e57dc7687..7d18c8a96 100644 --- a/bindings/nostr-js/src/nips/nip65.rs +++ b/bindings/nostr-js/src/nips/nip65.rs @@ -12,8 +12,9 @@ use crate::event::JsEvent; #[wasm_bindgen(js_name = RelayListItem)] pub struct JsRelayListItem { - url: String, - metadata: Option, + #[wasm_bindgen(getter_with_clone)] + pub url: String, + pub metadata: Option, } impl From for (UncheckedUrl, Option) { @@ -27,19 +28,10 @@ impl From for (UncheckedUrl, Option) { #[wasm_bindgen(js_class = RelayListItem)] impl JsRelayListItem { + #[wasm_bindgen(constructor)] pub fn new(url: String, metadata: Option) -> Self { Self { url, metadata } } - - #[wasm_bindgen(getter)] - pub fn url(&self) -> String { - self.url.clone() - } - - #[wasm_bindgen(getter)] - pub fn metadata(&self) -> Option { - self.metadata - } } #[wasm_bindgen(js_name = extractRelayList)] diff --git a/bindings/nostr-js/src/nips/nip94.rs b/bindings/nostr-js/src/nips/nip94.rs index d228b61d9..41e8ea7b3 100644 --- a/bindings/nostr-js/src/nips/nip94.rs +++ b/bindings/nostr-js/src/nips/nip94.rs @@ -14,8 +14,10 @@ use crate::event::tag::JsImageDimensions; #[wasm_bindgen(js_name = Aes256Gcm)] pub struct JsAes256Gcm { - key: String, - iv: String, + #[wasm_bindgen(getter_with_clone)] + pub key: String, + #[wasm_bindgen(getter_with_clone)] + pub iv: String, } impl From for (String, String) { @@ -33,7 +35,9 @@ impl From<(String, String)> for JsAes256Gcm { } } +#[wasm_bindgen(js_class = Aes256Gcm)] impl JsAes256Gcm { + #[wasm_bindgen(constructor)] pub fn new(key: String, iv: String) -> Self { Self { key, iv } } @@ -60,6 +64,7 @@ impl Deref for JsFileMetadata { #[wasm_bindgen(js_class = FileMetadata)] impl JsFileMetadata { + #[wasm_bindgen(constructor)] pub fn new(url: &str, mime_type: String, hash: &str) -> Result { Ok(Self { inner: FileMetadata::new( diff --git a/bindings/nostr-js/src/nips/nip98.rs b/bindings/nostr-js/src/nips/nip98.rs index 111af579f..d535e3b3e 100644 --- a/bindings/nostr-js/src/nips/nip98.rs +++ b/bindings/nostr-js/src/nips/nip98.rs @@ -26,6 +26,7 @@ impl From for HttpData { #[wasm_bindgen(js_class = HttpData)] impl JsHttpData { + #[wasm_bindgen(constructor)] pub fn new(url: &str, method: JsHttpMethod) -> Self { HttpData::new(UncheckedUrl::from(url), method.into()).into() }