From 7730ef1fac57ef5e67b0fcb380b45bea649695ee Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Sun, 19 Feb 2023 23:13:29 -0800 Subject: repo: don't use leading prefix in MST keys --- CHANGELOG.md | 11 ++++++---- TODO | 3 --- adenosine-pds/src/db_bsky.rs | 48 +++++++++----------------------------------- adenosine-pds/src/lib.rs | 8 ++++---- adenosine/src/repo.rs | 26 ++++++++++++------------ 5 files changed, 33 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df9acdc..17548c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,16 @@ Refactored common library code into `adenosine` crate. Will put common types, helpers, and probably client code and generated Lexicon code there. -## Changed +## Added + +- mst: interop tests with upstream `atproto` (Typescript) repository + +## Fixed - mst: include "empty" intermediate nodes between layers (following upstream behavior) - -## Added -- mst: interop tests with upstream `atproto` (Typescript) repository +- repo: MST keys should not have leading `/` before collection NSID (following + upstream behavior) ## [0.2.0] - 2022-12-19 diff --git a/TODO b/TODO index 7f00de2..139e768 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,4 @@ -PDS: -- keys in MST (repo) should NOT have leading slash (!) - CLI: - register and login commands should do more than just dump JSON => return shell 'export' command (for easier config) diff --git a/adenosine-pds/src/db_bsky.rs b/adenosine-pds/src/db_bsky.rs index dfe8299..834053e 100644 --- a/adenosine-pds/src/db_bsky.rs +++ b/adenosine-pds/src/db_bsky.rs @@ -68,7 +68,7 @@ pub fn bsky_get_profile(srv: &mut AtpService, did: &Did) -> Result Ok(ipld_into_json_value(ipld)), @@ -336,7 +336,7 @@ fn xrpc_get_handler( let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap(); let last_commit = srv.repo.get_commit(commit_cid)?; let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?; - let prefix = format!("/{collection}/"); + let prefix = format!("{collection}/"); for (mst_key, cid) in full_map.iter() { //debug!("{}", mst_key); if mst_key.starts_with(&prefix) { @@ -844,7 +844,7 @@ fn collection_view_handler( let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap(); let last_commit = srv.repo.get_commit(commit_cid)?; let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?; - let prefix = format!("/{collection}/"); + let prefix = format!("{collection}/"); for (mst_key, cid) in full_map.iter() { debug!("{}", mst_key); if mst_key.starts_with(&prefix) { @@ -880,7 +880,7 @@ fn record_view_handler( let rkey = Tid::from_str(tid)?; let mut srv = srv.lock().or(Err(XrpcError::MutexPoisoned))?; - let key = format!("/{collection}/{rkey}"); + let key = format!("{collection}/{rkey}"); let record = match srv.repo.get_atp_record(&did, &collection, &rkey) { Ok(Some(ipld)) => ipld_into_json_value(ipld), Ok(None) => Err(anyhow!(XrpcError::NotFound(format!( diff --git a/adenosine/src/repo.rs b/adenosine/src/repo.rs index 280fe6d..b05a933 100644 --- a/adenosine/src/repo.rs +++ b/adenosine/src/repo.rs @@ -196,7 +196,7 @@ impl RepoStore { } else { return Ok(None); }; - let record_key = format!("/{collection}/{tid}"); + let record_key = format!("{collection}/{tid}"); self.get_mst_record_by_key(&commit.mst_cid, &record_key) } @@ -244,14 +244,14 @@ impl RepoStore { match m { Mutation::Create(collection, tid, val) => { let cid = self.put_ipld(val)?; - cid_map.insert(format!("/{collection}/{tid}"), cid); + cid_map.insert(format!("{collection}/{tid}"), cid); } Mutation::Update(collection, tid, val) => { let cid = self.put_ipld(val)?; - cid_map.insert(format!("/{collection}/{tid}"), cid); + cid_map.insert(format!("{collection}/{tid}"), cid); } Mutation::Delete(collection, tid) => { - cid_map.remove(&format!("/{collection}/{tid}")); + cid_map.remove(&format!("{collection}/{tid}")); } } } @@ -374,14 +374,14 @@ fn test_repo_mst() { let empty_map_cid = repo.mst_from_map(&map).unwrap(); assert_eq!(map, repo.mst_to_map(&empty_map_cid).unwrap()); assert!(repo - .get_mst_record_by_key(&empty_map_cid, "/test.records/44444444444444") + .get_mst_record_by_key(&empty_map_cid, "test.records/44444444444444") .unwrap() .is_none()); - map.insert("/blobs/1".to_string(), blob_cid); - map.insert("/blobs/2".to_string(), blob_cid); - map.insert("/test.records/44444444444444".to_string(), record_cid); - map.insert("/test.records/22222222222222".to_string(), record_cid); + map.insert("blobs/1".to_string(), blob_cid); + map.insert("blobs/2".to_string(), blob_cid); + map.insert("test.records/44444444444444".to_string(), record_cid); + map.insert("test.records/22222222222222".to_string(), record_cid); let simple_map_cid = repo.mst_from_map(&map).unwrap(); assert_eq!(map, repo.mst_to_map(&simple_map_cid).unwrap()); @@ -393,7 +393,7 @@ fn test_repo_mst() { .unwrap(); assert_eq!( Some(record.clone()), - repo.get_mst_record_by_key(&simple_map_cid, "/test.records/44444444444444") + repo.get_mst_record_by_key(&simple_map_cid, "test.records/44444444444444") .unwrap() ); assert_eq!( @@ -406,7 +406,7 @@ fn test_repo_mst() { .unwrap() ); assert!(repo - .get_mst_record_by_key(&simple_map_cid, "/test.records/33333333333333") + .get_mst_record_by_key(&simple_map_cid, "test.records/33333333333333") .unwrap() .is_none()); assert!(repo @@ -419,7 +419,7 @@ fn test_repo_mst() { .is_none()); assert_eq!(Some(simple_commit_cid), repo.lookup_commit(&did).unwrap()); - map.insert("/test.records/33333333333333".to_string(), record_cid); + map.insert("test.records/33333333333333".to_string(), record_cid); let simple3_map_cid = repo.mst_from_map(&map).unwrap(); let simple3_root_cid = repo .write_root(meta_cid, Some(simple_commit_cid), simple3_map_cid) @@ -430,7 +430,7 @@ fn test_repo_mst() { assert_eq!(map, repo.mst_to_map(&simple3_map_cid).unwrap()); assert_eq!( Some(record.clone()), - repo.get_mst_record_by_key(&simple3_map_cid, "/test.records/33333333333333") + repo.get_mst_record_by_key(&simple3_map_cid, "test.records/33333333333333") .unwrap() ); assert_eq!( -- cgit v1.2.3