Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

bucket sums, more samples, export json

Changed files
+181 -38
constellation
links
+3 -2
Cargo.lock
···
"ratelimit",
"rocksdb",
"serde",
"serde_with",
"tempfile",
"tinyjson",
···
[[package]]
name = "serde_json"
-
version = "1.0.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949"
dependencies = [
"itoa",
"memchr",
···
"ratelimit",
"rocksdb",
"serde",
+
"serde_json",
"serde_with",
"tempfile",
"tinyjson",
···
[[package]]
name = "serde_json"
+
version = "1.0.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "44f86c3acccc9c65b153fe1b85a3be07fe5515274ec9f0653b4a0875731c72a6"
dependencies = [
"itoa",
"memchr",
+1
constellation/Cargo.toml
···
ratelimit = "0.10.0"
rocksdb = { version = "0.23.0", optional = true }
serde = { version = "1.0.215", features = ["derive"] }
serde_with = { version = "3.12.0", features = ["hex"] }
tinyjson = "2.5.1"
tokio-util = "0.7.13"
···
ratelimit = "0.10.0"
rocksdb = { version = "0.23.0", optional = true }
serde = { version = "1.0.215", features = ["derive"] }
+
serde_json = "1.0.139"
serde_with = { version = "3.12.0", features = ["hex"] }
tinyjson = "2.5.1"
tokio-util = "0.7.13"
+3 -1
constellation/readme.md
···
- [ ] read ops (api)
- [ ] expose internal stats?
- [ ] figure out what's the right thing to do if merge op fails. happened on startup after an unclean reboot.
-
cache
- [ ] set api response headers
···
- [ ] read ops (api)
- [ ] expose internal stats?
- [ ] figure out what's the right thing to do if merge op fails. happened on startup after an unclean reboot.
+
- [x] backups!
+
- [x] manual backup on startup
+
- [x] background task to create backups on an interval
cache
- [ ] set api response headers
+1 -1
constellation/src/storage/rocks_store.rs
···
}
fn get_db_read_opts() -> Options {
let mut opts = Options::default();
-
opts.optimize_for_point_lookup(128); // mb
opts
}
···
}
fn get_db_read_opts() -> Options {
let mut opts = Options::default();
+
opts.optimize_for_point_lookup(16_384); // mb (run this on big machines)
opts
}
+67
links/src/at_uri.rs
···
// there's a more normalization to do still. ugh.
}
#[cfg(test)]
mod tests {
use super::*;
···
] {
assert_eq!(
parse_at_uri(case),
expected.map(|s| s.to_string()),
"{detail}"
);
···
// there's a more normalization to do still. ugh.
}
+
pub fn at_uri_collection(at_uri: &str) -> Option<String> {
+
let (proto, rest) = at_uri.split_at_checked(5)?;
+
if !proto.eq_ignore_ascii_case("at://") {
+
return None;
+
}
+
let (_did, rest) = rest.split_once('/')?;
+
if let Some((collection, _path_rest)) = rest.split_once('/') {
+
return Some(collection.to_string());
+
}
+
if let Some((collection, _query_rest)) = rest.split_once('?') {
+
return Some(collection.to_string());
+
}
+
if let Some((collection, _hash_rest)) = rest.split_once('#') {
+
return Some(collection.to_string());
+
}
+
Some(rest.to_string())
+
}
+
#[cfg(test)]
mod tests {
use super::*;
···
] {
assert_eq!(
parse_at_uri(case),
+
expected.map(|s| s.to_string()),
+
"{detail}"
+
);
+
}
+
}
+
+
#[test]
+
fn test_at_uri_collection() {
+
for (case, expected, detail) in vec![
+
("", None, "empty"),
+
("at://did:plc:vc7f4oafdgxsihk4cry2xpze", None, "did only"),
+
(
+
"at://did:plc:vc7f4oafdgxsihk4cry2xpze/collec.tion",
+
Some("collec.tion"),
+
"no path (weird)",
+
),
+
(
+
"at://did:plc:vc7f4oafdgxsihk4cry2xpze/collec.tion/path",
+
Some("collec.tion"),
+
"normal at-uri",
+
),
+
(
+
"at://did:plc:vc7f4oafdgxsihk4cry2xpze/collec.tion?query",
+
Some("collec.tion"),
+
"colleciton with query",
+
),
+
(
+
"at://did:plc:vc7f4oafdgxsihk4cry2xpze/collec.tion#hash",
+
Some("collec.tion"),
+
"colleciton with hash",
+
),
+
(
+
"at://did:plc:vc7f4oafdgxsihk4cry2xpze/collec.tion/path?query#hash",
+
Some("collec.tion"),
+
"colleciton with everything",
+
),
+
(
+
"at://did:web:example.com/collec.tion/path",
+
Some("collec.tion"),
+
"did:web",
+
),
+
(
+
"at://did:web:example.com/col.lec.tio.ns.so.long.going.on.and.on",
+
Some("col.lec.tio.ns.so.long.going.on.and.on"),
+
"long collection",
+
),
+
] {
+
assert_eq!(
+
at_uri_collection(case),
expected.map(|s| s.to_string()),
"{detail}"
);
+29
links/src/lib.rs
···
Link::Did(_) => "did",
}
}
}
#[derive(Debug, PartialEq)]
···
parse_any_link("did:plc:44ybard66vv44zksje25o7dz"),
Some(Link::Did("did:plc:44ybard66vv44zksje25o7dz".into()))
)
}
}
···
Link::Did(_) => "did",
}
}
+
pub fn at_uri_collection(&self) -> Option<String> {
+
if let Link::AtUri(at_uri) = self {
+
at_uri::at_uri_collection(at_uri)
+
} else {
+
None
+
}
+
}
}
#[derive(Debug, PartialEq)]
···
parse_any_link("did:plc:44ybard66vv44zksje25o7dz"),
Some(Link::Did("did:plc:44ybard66vv44zksje25o7dz".into()))
)
+
}
+
+
#[test]
+
fn test_at_uri_collection() {
+
assert_eq!(
+
parse_any_link("https://example.com")
+
.unwrap()
+
.at_uri_collection(),
+
None
+
);
+
assert_eq!(
+
parse_any_link("did:web:bad-example.com")
+
.unwrap()
+
.at_uri_collection(),
+
None
+
);
+
assert_eq!(
+
parse_any_link("at://did:web:bad-example.com/my.collection/3jwdwj2ctlk26")
+
.unwrap()
+
.at_uri_collection(),
+
Some("my.collection".into())
+
);
}
}