nostr_relay.rs (4528B)
1 use radroots_types::types::{IResult, IResultList}; 2 use serde::{Deserialize, Serialize}; 3 use serde_json::Value; 4 #[derive(Serialize, Deserialize)] 5 pub struct NostrRelay { 6 pub id: String, 7 pub created_at: String, 8 pub updated_at: String, 9 pub url: String, 10 pub relay_id: Option<String>, 11 pub name: Option<String>, 12 pub description: Option<String>, 13 pub pubkey: Option<String>, 14 pub contact: Option<String>, 15 pub supported_nips: Option<String>, 16 pub software: Option<String>, 17 pub version: Option<String>, 18 pub data: Option<String>, 19 } 20 #[derive(Clone, Deserialize, Serialize)] 21 pub struct INostrRelayFields { 22 pub url: String, 23 pub relay_id: Option<String>, 24 pub name: Option<String>, 25 pub description: Option<String>, 26 pub pubkey: Option<String>, 27 pub contact: Option<String>, 28 pub supported_nips: Option<String>, 29 pub software: Option<String>, 30 pub version: Option<String>, 31 pub data: Option<String>, 32 } 33 #[derive(Clone, Deserialize, Serialize)] 34 pub struct INostrRelayFieldsPartial { 35 pub url: Option<serde_json::Value>, 36 pub relay_id: Option<serde_json::Value>, 37 pub name: Option<serde_json::Value>, 38 pub description: Option<serde_json::Value>, 39 pub pubkey: Option<serde_json::Value>, 40 pub contact: Option<serde_json::Value>, 41 pub supported_nips: Option<serde_json::Value>, 42 pub software: Option<serde_json::Value>, 43 pub version: Option<serde_json::Value>, 44 pub data: Option<serde_json::Value>, 45 } 46 #[derive(Clone, Deserialize, Serialize)] 47 pub struct INostrRelayFieldsFilter { 48 pub id: Option<String>, 49 pub created_at: Option<String>, 50 pub updated_at: Option<String>, 51 pub url: Option<String>, 52 pub relay_id: Option<String>, 53 pub name: Option<String>, 54 pub description: Option<String>, 55 pub pubkey: Option<String>, 56 pub contact: Option<String>, 57 pub supported_nips: Option<String>, 58 pub software: Option<String>, 59 pub version: Option<String>, 60 pub data: Option<String>, 61 } 62 #[derive(Clone, Deserialize, Serialize)] 63 #[serde(untagged)] 64 pub enum NostrRelayQueryBindValues { 65 Id { id: String }, 66 Url { url: String }, 67 } 68 impl NostrRelayQueryBindValues { 69 pub fn to_filter_param(&self) -> (&'static str, Value) { 70 match self { 71 Self::Id { id } => ("id", Value::from(id.clone())), 72 Self::Url { url } => ("url", Value::from(url.clone())), 73 } 74 } 75 76 pub fn primary_key(&self) -> Option<String> { 77 match self { 78 Self::Id { id } => Some(id.clone()), 79 _ => None, 80 } 81 } 82 83 pub fn lookup_key(&self) -> String { 84 match self { 85 Self::Id { id } => id.clone(), 86 Self::Url { url } => url.clone(), 87 } 88 } 89 } 90 #[derive(Clone, Deserialize, Serialize)] 91 pub struct NostrRelayProfileArgs { 92 pub public_key: String, 93 } 94 95 #[derive(Clone, Deserialize, Serialize)] 96 pub enum NostrRelayFindManyRel { 97 #[serde(rename = "on_profile")] 98 OnProfile(NostrRelayProfileArgs), 99 #[serde(rename = "off_profile")] 100 OffProfile(NostrRelayProfileArgs), 101 } 102 103 pub struct INostrRelayCreateTs; 104 pub type INostrRelayCreate = INostrRelayFields; 105 pub struct INostrRelayCreateResolveTs; 106 pub type INostrRelayCreateResolve = IResult<NostrRelay>; 107 #[derive(Deserialize, Serialize)] 108 pub struct INostrRelayFindOneArgs { 109 pub on: NostrRelayQueryBindValues, 110 } 111 112 #[derive(Deserialize, Serialize)] 113 pub struct INostrRelayFindOneRelArgs { 114 pub rel: NostrRelayFindManyRel, 115 } 116 117 #[derive(Deserialize, Serialize)] 118 #[serde(untagged)] 119 pub enum INostrRelayFindOne { 120 On(INostrRelayFindOneArgs), 121 Rel(INostrRelayFindOneRelArgs), 122 } 123 124 pub struct INostrRelayFindOneResolveTs; 125 pub type INostrRelayFindOneResolve = IResult<Option<NostrRelay>>; 126 #[derive(Deserialize, Serialize)] 127 #[serde(untagged)] 128 pub enum INostrRelayFindMany { 129 Filter { 130 filter: Box<Option<INostrRelayFieldsFilter>>, 131 }, 132 Rel { 133 rel: NostrRelayFindManyRel, 134 }, 135 } 136 pub struct INostrRelayFindManyResolveTs; 137 pub type INostrRelayFindManyResolve = IResultList<NostrRelay>; 138 pub struct INostrRelayDeleteTs; 139 pub type INostrRelayDelete = INostrRelayFindOne; 140 pub struct INostrRelayDeleteResolveTs; 141 pub type INostrRelayDeleteResolve = IResult<String>; 142 #[derive(Deserialize, Serialize)] 143 pub struct INostrRelayUpdateArgs { 144 pub on: NostrRelayQueryBindValues, 145 pub fields: INostrRelayFieldsPartial, 146 } 147 pub type INostrRelayUpdate = INostrRelayUpdateArgs; 148 pub struct INostrRelayUpdateResolveTs; 149 pub type INostrRelayUpdateResolve = IResult<NostrRelay>;