APIs for links and references in the ATmosphere

slingshot fmt

+ci

Changed files
+36 -43
.github
workflows
slingshot
+1 -1
.github/workflows/checks.yml
··· 28 28 - name: get nightly toolchain for jetstream fmt 29 29 run: rustup toolchain install nightly --allow-downgrade -c rustfmt 30 30 - name: fmt 31 - run: cargo fmt --package links --package constellation --package ufos --package spacedust --package who-am-i -- --check 31 + run: cargo fmt --package links --package constellation --package ufos --package spacedust --package who-am-i --package slingshot -- --check 32 32 - name: fmt jetstream (nightly) 33 33 run: cargo +nightly fmt --package jetstream -- --check 34 34 - name: clippy
+1 -1
Makefile
··· 5 5 cargo test --all-features 6 6 7 7 fmt: 8 - cargo fmt --package links --package constellation --package ufos --package spacedust --package who-am-i 8 + cargo fmt --package links --package constellation --package ufos --package spacedust --package who-am-i --package slingshot 9 9 cargo +nightly fmt --package jetstream 10 10 11 11 clippy:
+1 -1
slingshot/src/consumer.rs
··· 1 1 use crate::CachedRecord; 2 - use foyer::HybridCache; 3 2 use crate::error::ConsumerError; 3 + use foyer::HybridCache; 4 4 use jetstream::{ 5 5 DefaultJetstreamEndpoints, JetstreamCompression, JetstreamConfig, JetstreamConnector, 6 6 events::{CommitOp, Cursor, EventKind},
+5 -4
slingshot/src/firehose_cache.rs
··· 1 + use crate::CachedRecord; 2 + use foyer::{DirectFsDeviceOptions, Engine, HybridCache, HybridCacheBuilder}; 1 3 use std::path::Path; 2 - use crate::CachedRecord; 3 - use foyer::{HybridCache, DirectFsDeviceOptions, Engine, HybridCacheBuilder}; 4 4 5 - 6 - pub async fn firehose_cache(dir: impl AsRef<Path>) -> Result<HybridCache<String, CachedRecord>, String> { 5 + pub async fn firehose_cache( 6 + dir: impl AsRef<Path>, 7 + ) -> Result<HybridCache<String, CachedRecord>, String> { 7 8 let cache = HybridCacheBuilder::new() 8 9 .with_name("firehose") 9 10 .memory(64 * 2_usize.pow(20))
-3
slingshot/src/main.rs
··· 6 6 use clap::Parser; 7 7 use tokio_util::sync::CancellationToken; 8 8 9 - 10 9 /// Slingshot record edge cache 11 10 #[derive(Parser, Debug, Clone)] 12 11 #[command(version, about, long_about = None)] ··· 65 64 Ok(()) 66 65 }); 67 66 68 - 69 67 tokio::select! { 70 68 _ = shutdown.cancelled() => log::warn!("shutdown requested"), 71 69 Some(r) = tasks.join_next() => { ··· 111 109 ); 112 110 Ok(()) 113 111 } 114 -
+4 -3
slingshot/src/record.rs
··· 1 - use serde_json::value::RawValue; 2 - use serde::{Serialize, Deserialize}; 3 1 use jetstream::exports::Cid; 2 + use serde::{Deserialize, Serialize}; 3 + use serde_json::value::RawValue; 4 4 5 5 #[derive(Debug, Serialize, Deserialize)] 6 6 pub struct RawRecord { ··· 23 23 fn from(RawRecord { cid, record }: &RawRecord) -> Self { 24 24 ( 25 25 cid.clone(), 26 - RawValue::from_string(record.to_string()).expect("stored string from RawValue to be valid"), 26 + RawValue::from_string(record.to_string()) 27 + .expect("stored string from RawValue to be valid"), 27 28 ) 28 29 } 29 30 }
+24 -30
slingshot/src/server.rs
··· 1 + use crate::{CachedRecord, error::ServerError}; 1 2 use foyer::HybridCache; 2 - use crate::{error::ServerError, CachedRecord}; 3 3 use tokio_util::sync::CancellationToken; 4 4 5 - use poem::{listener::TcpListener, Route, Server}; 5 + use poem::{Route, Server, listener::TcpListener}; 6 6 use poem_openapi::{ 7 - payload::Json, 8 - param::Query, 9 - OpenApi, OpenApiService, 10 - ApiResponse, 11 - Object, 12 - types::Example, 7 + ApiResponse, Object, OpenApi, OpenApiService, param::Query, payload::Json, types::Example, 13 8 }; 14 9 15 10 fn example_did() -> String { ··· 39 34 } 40 35 } 41 36 42 - 43 37 fn bad_request_handler(err: poem::Error) -> GetRecordResponse { 44 38 GetRecordResponse::BadRequest(Json(XrpcErrorResponseObject { 45 39 error: "InvalidRequest".to_string(), ··· 63 57 impl Example for FoundRecordResponseObject { 64 58 fn example() -> Self { 65 59 Self { 66 - uri: format!("at://{}/{}/{}", example_did(), example_collection(), example_rkey()), 60 + uri: format!( 61 + "at://{}/{}/{}", 62 + example_did(), 63 + example_collection(), 64 + example_rkey() 65 + ), 67 66 cid: Some("bafyreialv3mzvvxaoyrfrwoer3xmabbmdchvrbyhayd7bga47qjbycy74e".to_string()), 68 67 value: serde_json::json!({ 69 68 "$type": "app.bsky.feed.like", ··· 130 129 cid: Query<Option<String>>, 131 130 ) -> GetRecordResponse { 132 131 // TODO: yeah yeah 133 - let at_uri = format!( 134 - "at://{}/{}/{}", 135 - &*repo, &*collection, &*rkey 136 - ); 132 + let at_uri = format!("at://{}/{}/{}", &*repo, &*collection, &*rkey); 137 133 138 - let entry = self.cache 139 - .fetch(at_uri.clone(), || async move { 140 - todo!() 141 - }) 134 + let entry = self 135 + .cache 136 + .fetch(at_uri.clone(), || async move { todo!() }) 142 137 .await 143 138 .unwrap(); 144 139 ··· 151 146 if cid.clone().map(|c| c != found_cid).unwrap_or(false) { 152 147 return GetRecordResponse::BadRequest(Json(XrpcErrorResponseObject { 153 148 error: "RecordNotFound".to_string(), 154 - message: "A record was found but its CID did not match that requested".to_string(), 149 + message: "A record was found but its CID did not match that requested" 150 + .to_string(), 155 151 })); 156 152 } 157 153 // TODO: thank u stellz: https://gist.github.com/stella3d/51e679e55b264adff89d00a1e58d0272 158 - let value = serde_json::from_str(raw_value.get()).expect("RawValue to be valid json"); 154 + let value = 155 + serde_json::from_str(raw_value.get()).expect("RawValue to be valid json"); 159 156 GetRecordResponse::Ok(Json(FoundRecordResponseObject { 160 157 uri: at_uri, 161 158 cid: Some(found_cid), 162 159 value, 163 160 })) 164 - }, 165 - CachedRecord::Deleted => { 166 - GetRecordResponse::BadRequest(Json(XrpcErrorResponseObject { 167 - error: "RecordNotFound".to_string(), 168 - message: "This record was deleted".to_string(), 169 - })) 170 161 } 162 + CachedRecord::Deleted => GetRecordResponse::BadRequest(Json(XrpcErrorResponseObject { 163 + error: "RecordNotFound".to_string(), 164 + message: "This record was deleted".to_string(), 165 + })), 171 166 } 172 167 } 173 168 } ··· 176 171 cache: HybridCache<String, CachedRecord>, 177 172 _shutdown: CancellationToken, 178 173 ) -> Result<(), ServerError> { 179 - let api_service = 180 - OpenApiService::new(Xrpc { cache }, "Slingshot", env!("CARGO_PKG_VERSION")) 181 - .server("http://localhost:3000") 182 - .url_prefix("/xrpc"); 174 + let api_service = OpenApiService::new(Xrpc { cache }, "Slingshot", env!("CARGO_PKG_VERSION")) 175 + .server("http://localhost:3000") 176 + .url_prefix("/xrpc"); 183 177 184 178 let app = Route::new() 185 179 .nest("/", api_service.scalar())