very fast at protocol indexer with flexible filtering, xrpc queries, cursor-backed event stream, and more, built on fjall
rust fjall at-protocol atproto indexer
58
fork

Configure Feed

Select the types of activity you want to include in your feed.

[api] make marshallable evt use better types

dawn 6dd9a8ce a3169128

+43 -16
+10 -6
src/control.rs
··· 7 7 8 8 use chrono::{DateTime, Utc}; 9 9 use futures::{FutureExt, Stream}; 10 + use jacquard_common::cowstr::ToCowStr; 10 11 use jacquard_common::types::cid::{ATP_CID_HASH, IpldCid}; 11 - use jacquard_common::types::string::{Did, Handle}; 12 + use jacquard_common::types::nsid::Nsid; 13 + use jacquard_common::types::string::{Did, Handle, Rkey}; 12 14 use jacquard_common::types::tid::Tid; 13 15 use jacquard_common::{CowStr, IntoStatic, RawData}; 14 16 use jacquard_repo::DAG_CBOR_CID_CODEC; ··· 1410 1412 1411 1413 Some(MarshallableEvt { 1412 1414 id, 1413 - event_type: "record".into(), 1415 + kind: crate::types::EventType::Record, 1414 1416 record: Some(RecordEvt { 1415 1417 live, 1416 1418 did: did.to_did(), 1417 - rev: CowStr::Owned(rev.to_tid().into()), 1418 - collection: CowStr::Owned(collection.as_ref().to_string().into()), 1419 - rkey: CowStr::Owned(rkey.to_smolstr().into()), 1419 + rev: rev.to_tid(), 1420 + collection: Nsid::new_cow(collection.clone().into_static()) 1421 + .expect("that collection is already validated"), 1422 + rkey: Rkey::new_cow(rkey.to_cowstr().into_static()) 1423 + .expect("that rkey is already validated"), 1420 1424 action: CowStr::Borrowed(action.as_str()), 1421 1425 record, 1422 - cid: cid.map(|c| jacquard_common::types::cid::Cid::ipld(c).into()), 1426 + cid, 1423 1427 }), 1424 1428 identity: None, 1425 1429 account: None,
+2 -2
src/ops.rs
··· 47 47 let event_id = db.next_event_id.fetch_add(1, Ordering::SeqCst); 48 48 let marshallable = MarshallableEvt { 49 49 id: event_id, 50 - event_type: "identity".into(), 50 + kind: crate::types::EventType::Identity, 51 51 record: None, 52 52 identity: Some(evt), 53 53 account: None, ··· 59 59 let event_id = db.next_event_id.fetch_add(1, Ordering::SeqCst); 60 60 let marshallable = MarshallableEvt { 61 61 id: event_id, 62 - event_type: "account".into(), 62 + kind: crate::types::EventType::Account, 63 63 record: None, 64 64 identity: None, 65 65 account: Some(evt),
+31 -8
src/types.rs
··· 1 1 use std::fmt::{Debug, Display}; 2 2 3 3 use jacquard_common::types::cid::IpldCid; 4 - use jacquard_common::types::string::Did; 4 + use jacquard_common::types::nsid::Nsid; 5 + use jacquard_common::types::string::{Did, Rkey}; 6 + use jacquard_common::types::tid::Tid; 5 7 use jacquard_common::{CowStr, IntoStatic, types::string::Handle}; 6 - use serde::{Deserialize, Serialize}; 8 + use serde::{Deserialize, Serialize, Serializer}; 7 9 use serde_json::Value; 8 10 use smol_str::{SmolStr, ToSmolStr}; 9 11 ··· 161 163 } 162 164 } 163 165 164 - // from src/api/event.rs 166 + #[derive(Debug, Serialize, Clone)] 167 + pub enum EventType { 168 + Record, 169 + Identity, 170 + Account, 171 + } 172 + 173 + impl AsRef<str> for EventType { 174 + fn as_ref(&self) -> &str { 175 + match self { 176 + Self::Record => "record", 177 + Self::Identity => "identity", 178 + Self::Account => "account", 179 + } 180 + } 181 + } 182 + 183 + fn event_type_ser_str<S: Serializer>(v: &EventType, s: S) -> Result<S::Ok, S::Error> { 184 + s.serialize_str(v.as_ref()) 185 + } 165 186 166 187 #[derive(Debug, Serialize, Clone)] 167 188 pub struct MarshallableEvt<'i> { 168 189 pub id: u64, 169 190 #[serde(rename = "type")] 170 - pub event_type: SmolStr, 191 + #[serde(serialize_with = "event_type_ser_str")] 192 + pub kind: EventType, 171 193 #[serde(borrow)] 172 194 #[serde(skip_serializing_if = "Option::is_none")] 173 195 pub record: Option<RecordEvt<'i>>, ··· 191 213 pub live: bool, 192 214 #[serde(borrow)] 193 215 pub did: Did<'i>, 194 - pub rev: CowStr<'i>, 195 - pub collection: CowStr<'i>, 196 - pub rkey: CowStr<'i>, 216 + pub rev: Tid, 217 + pub collection: Nsid<'i>, 218 + pub rkey: Rkey<'i>, 197 219 pub action: CowStr<'i>, 198 220 #[serde(skip_serializing_if = "Option::is_none")] 199 221 pub record: Option<Value>, 200 222 #[serde(skip_serializing_if = "Option::is_none")] 201 - pub cid: Option<CowStr<'i>>, 223 + #[serde(serialize_with = "crate::util::opt_cid_serialize_str")] 224 + pub cid: Option<IpldCid>, 202 225 } 203 226 204 227 #[derive(Debug, Serialize, Clone)]