chadtmiller.com/group-host
atmosphere group host
0
0
A list's last page names no cursor, never null
.changeset/lists-end-without-a-cursor.mdnew+7−0
| @@ -0,0 +1,7 @@ | ||
--- | ||
default: patch | ||
--- | ||
| ||
# A list's last page names no cursor | ||
| ||
The last page of a list names no `cursor`, where it named `"cursor": null`, which a lexicon's `cursor`, a string, does not allow, so a client checking answers against the lexicons (as `@atproto/lex` does) refused it. That was `com.atproto.repo.listRecords`, `com.atproto.sync.listRepos` and `listBlobs`, `com.atproto.space.listRecords`, `listRepoOps` and `listBlobs`, `org.atgrp.listJoinRequests`, `org.atgrp.internal.listInvites` and `org.atgrp.internal.listSpaceRecords`. | ||
crates/group-host/src/api.rs+13−3
| @@ -41,6 +41,16 @@ pub(crate) fn invalid_cursor() -> XrpcError { | ||
) | ||
} | ||
| ||
/// `body`, a page of a list, with the `cursor` to the next page where there | ||
/// is one. A lexicon's cursor is a string: the last page has none, never | ||
/// null, which a client checking the answer against the lexicon refuses. | ||
pub(crate) fn paged(mut body: Value, cursor: Option<String>) -> Value { | ||
if let Some(cursor) = cursor { | ||
body["cursor"] = cursor.into(); | ||
} | ||
body | ||
} | ||
| ||
/// The parameter `name`, which the method needs. | ||
pub(crate) fn param<'a>(params: &'a Params, name: &str) -> Result<&'a str, XrpcError> { | ||
params | ||
| @@ -174,7 +184,7 @@ pub async fn list_records(State(host): State<Arc<Host>>, Query(p): Query<Params> | ||
.filter(|_| records.len() == limit as usize) | ||
.map(|r| r.rkey.clone()); | ||
let records: Vec<Value> = records.iter().map(|r| view(&did, r)).collect(); | ||
Ok(Json(json!({"records": records, "cursor": cursor}))) | ||
Ok(Json(paged(json!({ "records": records }), cursor))) | ||
} | ||
| ||
pub async fn get_repo( | ||
| @@ -235,7 +245,7 @@ pub async fn list_repos(State(host): State<Arc<Host>>, Query(p): Query<Params>) | ||
repo | ||
}) | ||
.collect(); | ||
Ok(Json(json!({"repos": repos, "cursor": cursor}))) | ||
Ok(Json(paged(json!({ "repos": repos }), cursor))) | ||
} | ||
| ||
/// The DID a handle names: an account's here, or for someone signed in, | ||
| @@ -318,7 +328,7 @@ pub async fn list_blobs(State(host): State<Arc<Host>>, Query(p): Query<Params>) | ||
.filter(|_| cids.len() == limit as usize) | ||
.map(ToString::to_string); | ||
let cids: Vec<String> = cids.iter().map(ToString::to_string).collect(); | ||
Ok(Json(json!({"cids": cids, "cursor": cursor}))) | ||
Ok(Json(paged(json!({ "cids": cids }), cursor))) | ||
} | ||
| ||
/// The host's own DID document, when its DID is a `did:web` of its address. | ||
crates/group-host/src/group_invites.rs+2−2
| @@ -13,7 +13,7 @@ | ||
//! the group's join policy, with its default roles. | ||
| ||
use crate::Host; | ||
use crate::api::{Params, invalid, page, param}; | ||
use crate::api::{Params, invalid, page, paged, param}; | ||
use crate::group::meta_space; | ||
use crate::group_api::{group_of, signed_in}; | ||
use crate::group_members::{Members, acting}; | ||
| @@ -410,7 +410,7 @@ pub async fn list_invites( | ||
view | ||
}) | ||
.collect(); | ||
Ok(Json(json!({"invites": invites, "cursor": cursor}))) | ||
Ok(Json(paged(json!({ "invites": invites }), cursor))) | ||
} | ||
| ||
/// The caller's own invites waiting, from the groups here, newest first; | ||
crates/group-host/src/group_join.rs+2−2
| @@ -12,7 +12,7 @@ | ||
//! ask again and the group need not say. | ||
| ||
use crate::Host; | ||
use crate::api::{Params, invalid_cursor, page, param}; | ||
use crate::api::{Params, invalid_cursor, page, paged, param}; | ||
use crate::group::meta_space; | ||
use crate::group_api::{doing, group_of, signed_in}; | ||
use crate::group_invites::invite_uri; | ||
| @@ -163,7 +163,7 @@ pub async fn list_join_requests( | ||
.filter(|_| waiting.len() == limit as usize) | ||
.map(|r| r.seq.to_string()); | ||
let requests: Vec<Value> = waiting.iter().map(request_view).collect(); | ||
Ok(Json(json!({"requests": requests, "cursor": cursor}))) | ||
Ok(Json(paged(json!({ "requests": requests }), cursor))) | ||
} | ||
| ||
/// Turns down one who asked, for one holding `admit`, or an app signed in | ||
crates/group-host/src/index_api.rs+2−2
| @@ -5,7 +5,7 @@ | ||
//! `!takedown` label (`takedown.rs`) it serves to nobody. | ||
| ||
use crate::Host; | ||
use crate::api::{Params, invalid, page, param}; | ||
use crate::api::{Params, invalid, page, paged, param}; | ||
use crate::authority::Access::Write; | ||
use crate::group_api::{group_of, signed_in}; | ||
use crate::rbac::INTERNAL; | ||
| @@ -162,7 +162,7 @@ pub async fn list_space_records( | ||
break; | ||
} | ||
} | ||
Ok(Json(json!({"records": records, "cursor": cursor}))) | ||
Ok(Json(paged(json!({ "records": records }), cursor))) | ||
} | ||
| ||
/// A picture or file in one of the group's spaces, read from whoever wrote | ||
crates/group-host/src/space_api.rs+4−4
| @@ -5,7 +5,7 @@ | ||
//! credentials are revoked. | ||
| ||
use crate::Host; | ||
use crate::api::{Params, invalid, page, param}; | ||
use crate::api::{Params, invalid, page, paged, param}; | ||
use crate::store::{Account, Record, SpaceHead}; | ||
use crate::time::now_millis; | ||
use crate::xrpc::XrpcError; | ||
| @@ -333,7 +333,7 @@ pub async fn list_records( | ||
entry | ||
}) | ||
.collect(); | ||
let body = json!({"records": records, "cursor": cursor}); | ||
let body = paged(json!({ "records": records }), cursor); | ||
Ok(private(Json(body).into_response(), None)) | ||
} | ||
| ||
| @@ -420,7 +420,7 @@ pub async fn list_repo_ops( | ||
entry | ||
}) | ||
.collect(); | ||
let body = json!({"ops": ops, "cursor": cursor, "commit": commit_json(&commit)}); | ||
let body = paged(json!({"ops": ops, "commit": commit_json(&commit)}), cursor); | ||
Ok(private( | ||
Json(body).into_response(), | ||
Some((&mac, commit.header())), | ||
| @@ -481,7 +481,7 @@ pub async fn list_blobs( | ||
.map(ToString::to_string); | ||
let cids: Vec<String> = cids.iter().map(ToString::to_string).collect(); | ||
Ok(private( | ||
Json(json!({"cids": cids, "cursor": cursor})).into_response(), | ||
Json(paged(json!({ "cids": cids }), cursor)).into_response(), | ||
None, | ||
)) | ||
} | ||
crates/group-host/tests/blobs.rs+5−1
| @@ -69,7 +69,11 @@ async fn serves_a_blob_once_a_record_references_it() { | ||
let (_, listed) = h | ||
.get("com.atproto.sync.listBlobs", &format!("did={did}")) | ||
.await; | ||
assert_eq!(listed, json!({"cids": [cid], "cursor": null})); | ||
assert_eq!( | ||
listed, | ||
json!({ "cids": [cid] }), | ||
"the last page names no cursor" | ||
); | ||
| ||
// The commit's event names the blob. | ||
let events = h.host.store.events_after(0, 100).unwrap(); | ||
crates/group-host/tests/index.rs+5−1
| @@ -310,7 +310,11 @@ async fn pages_filters_and_finds_one() { | ||
&format!("{query}&field=subject.uri&equals=at://s/9"), | ||
) | ||
.await; | ||
assert_eq!(none, json!({"records": [], "cursor": null})); | ||
assert_eq!( | ||
none, | ||
json!({ "records": [] }), | ||
"the last page names no cursor" | ||
); | ||
let (_, numbered) = list(&h, Some(&alice), &format!("{query}&field=subject&equals=x")).await; | ||
assert_eq!(numbered["records"], json!([])); | ||
| ||
crates/group-host/tests/spaces.rs+2−1
| @@ -654,7 +654,8 @@ async fn serves_and_lists_a_spaces_blobs() { | ||
let (listed, _) = f.get("com.atproto.space.listBlobs", "", COMMIT_MAC).await; | ||
assert_eq!( | ||
listed.json(), | ||
json!({"cids": [link(&picture)], "cursor": null}) | ||
json!({ "cids": [link(&picture)] }), | ||
"the last page names no cursor" | ||
); | ||
let (page, _) = f | ||
.get("com.atproto.space.listBlobs", "&limit=1", COMMIT_MAC) | ||