mark the params an appview map ignores as any in the site hook's diff lines
74 unmodified lines75767778797980818283848586878889909192939495594 unmodified linesExpand all74 unmodified lines}
pub(crate) fn compare(old: &Answers, new: &Answers, lines: &mut Vec<Line>) { merge(&old.exact, &new.exact, |key, old, new| { let line = match (old, new) { let mut line = match (old, new) { (None, Some(_)) if names_new_oid(&key.1) => return, (None, Some(new)) => Line::of("added", key.clone(), None, Some(new.clone())), (Some(old), None) => Line::of("removed", key.clone(), Some(old.clone()), None), (Some(old), Some(new)) if old != new => { Line::of("changed", key.clone(), Some(old.clone()), Some(new.clone())) } _ => return, }; line.any = crate::xrpc::social::ignored_params(key.0) .iter() .map(|name| name.to_string()) .collect(); lines.push(line); }); merge(&old.bucketed, &new.bucketed, |key, old, new| { let op = match (old, new) {594 unmodified linesExpand all338 unmodified linesExpand all339340341342343344345346347348349350351352157 unmodified linesExpand all338 unmodified linesExpand all params(&[("subject", DID), ("state", "open")]) ), ]) ); assert!( lines(&old, &new) .iter() .all(|line| line.any == ["limit", "offset", "order"]), "a request differing only in params the map ignores reads the same answer" ); let rows_gone = social(vec![issues("social/empty.json", &[])]); let back = lines(&new, &rows_gone); assert!( back.iter()157 unmodified linesExpand all9 unmodified lines10111213141516171819202122232425262728293031323334353637383940414243444532 unmodified lines9 unmodified lines var: "$ks_soc_doc", miss: "not_found", empty: None, refused: &[], ignored: &[],};const PROFILE: Route = Route { nsid: "org.tangled.actor.getProfile", source: "$arg_actor", var: "$ks_soc_profile", miss: "not_found", empty: None, refused: &[], ignored: &[],};const PROFILES: Route = Route { nsid: "org.tangled.actor.getProfiles", source: "$arg_actors", var: "$ks_soc_profiles", miss: "invalid_request", empty: Some(no_items), refused: &[Refused::Distinct("actors")], ignored: &[],};const KEYS: Route = Route { nsid: "org.tangled.publicKey.listKeys", source: "$arg_subject$arg_actor", var: "$ks_soc_keys", miss: "invalid_request", empty: Some(no_items), refused: &[], ignored: &["cursor", "limit", "offset", "order"],};
pub(super) const ROUTES: &[Route] = &[MINIDOC, PROFILE, PROFILES, KEYS];
32 unmodified lines389 unmodified linesExpand all39039139239339439539639739839934 unmodified lines434435436437438439440441442443444445446447105 unmodified linesExpand all553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613389 unmodified linesExpand all var: &'static str, miss: &'static str, empty: Option<fn() -> Value>, refused: &'static [Refused], /// params the lexicon takes that don't key the map and aren't refused unless empty ignored: &'static [&'static str],}
impl Route { fn location(&self) -> Block {34 unmodified lines .chain(repo::ROUTES) .chain(ticket::ROUTES)}
pub(crate) fn ignored_params(nsid: &str) -> &'static [&'static str] { routes() .find(|route| route.nsid == nsid) .map_or(&[], |route| route.ignored)}
pub(crate) fn route_vars() -> impl Iterator<Item = (&'static str, &'static str)> { routes() .map(|route| (route.nsid, route.var)) .chain([(ticket::SEARCH_NSID, ticket::SEARCH)])105 unmodified linesExpand all .into_iter() .chain(routes().map(Route::location)) .collect()}
#[cfg(test)]mod tests { use super::*;
/// what the lexicon takes, less what keys the map and what is refused unless empty #[test] fn ignored_params_are_what_the_lexicon_takes_and_the_map_doesnt_key_on() { fn read(dir: &Path, by_id: &mut BTreeMap<String, Value>) { for entry in std::fs::read_dir(dir).unwrap().flatten() { let path = entry.path(); if path.is_dir() { read(&path, by_id); } else if path.extension().is_some_and(|ext| ext == "json") { let lexicon: Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap(); if let Some(id) = lexicon["id"].as_str() { by_id.insert(id.to_string(), lexicon); } } } } let mut by_id = BTreeMap::new(); read( &Path::new(env!("CARGO_MANIFEST_DIR")).join("vendor/core/lexicons"), &mut by_id, ); for route in routes() { let Some(lexicon) = by_id.get(route.nsid) else { assert!(route.ignored.is_empty(), "{}", route.nsid); continue; }; let keyed: BTreeSet<&str> = route .source .split("$arg_") .skip(1) .map(|name| name.trim_end_matches('|')) .collect(); let refused: BTreeSet<&str> = route .refused .iter() .filter_map(|refused| match refused { Refused::Unless(name, "") => Some(*name), _ => None, }) .collect(); let expected: Vec<&str> = lexicon["defs"]["main"]["parameters"]["properties"] .as_object() .into_iter() .flat_map(|properties| properties.keys()) .map(String::as_str) .filter(|name| !keyed.contains(name) && !refused.contains(name)) .collect(); assert_eq!(route.ignored, expected, "{}", route.nsid); } }}12 unmodified lines1314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374753 unmodified lines798081828384858687161 unmodified linesExpand all12 unmodified lines var: "$ks_soc_by_name", miss: "not_found", empty: None, refused: &[], ignored: &[],};const BY_DID: Route = Route { nsid: "org.tangled.repo.getRepoByRepoDid", source: "$arg_repoDid", var: "$ks_soc_by_did", miss: "not_found", empty: None, refused: &[], ignored: &[],};const BY_DIDS: Route = Route { nsid: "org.tangled.repo.getReposByRepoDids", source: "$arg_dids$arg_repoDids", var: "$ks_soc_by_dids", miss: "invalid_request", empty: Some(no_items), refused: &[Refused::Distinct("dids"), Refused::Distinct("repoDids")], ignored: &[],};const LIST: Route = Route { nsid: "org.tangled.repo.listRepos", source: "$arg_subject$arg_owner", var: "$ks_soc_repos", miss: "invalid_request", empty: Some(no_items), refused: WHOLE_LIST, ignored: &["limit", "offset", "order"],};const COLLABORATORS: Route = Route { nsid: "org.tangled.repo.listCollaborators", source: "$arg_subject$arg_repo", var: "$ks_soc_collaborators", miss: "invalid_request", empty: Some(no_items), refused: WHOLE_LIST, ignored: &["limit", "offset", "order"],};const ARTIFACTS: Route = Route { nsid: "org.tangled.repo.listArtifacts", source: "$arg_subject$arg_repo", var: "$ks_soc_artifacts", miss: "invalid_request", empty: Some(no_items), refused: WHOLE_LIST, ignored: &["limit", "offset", "order"],};const LABELS: Route = Route { nsid: "org.tangled.label.listDefinitions", source: "$arg_subject$arg_repo", var: "$ks_soc_labels", miss: "invalid_request", empty: Some(no_items), refused: WHOLE_LIST, ignored: &["limit", "offset", "order"],};
macro_rules! count_route { ($name:ident, $nsid:literal, $var:literal) => {3 unmodified lines var: $var, miss: "invalid_request", empty: Some(no_count), refused: &[], ignored: &[], }; };}count_route!(STARS, "org.tangled.feed.countStars", "$ks_soc_n_stars");161 unmodified linesExpand all49 unmodified lines5051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112403 unmodified linesExpand all49 unmodified lines var: "$ks_soc_issues", miss: "invalid_request", empty: Some(super::no_items), refused: TICKET_LIST, ignored: &["limit", "offset", "order"],};const PULLS: Route = Route { nsid: "org.tangled.repo.listPulls", source: "$arg_subject$arg_repo|$arg_status$arg_state", var: "$ks_soc_pulls", miss: "invalid_request", empty: Some(super::no_items), refused: TICKET_LIST, ignored: &["limit", "offset", "order"],};const N_ISSUES: Route = Route { nsid: "org.tangled.repo.countIssues", source: "$arg_subject$arg_repo|$arg_state", var: "$ks_soc_n_issues", miss: "invalid_request", empty: Some(super::no_count), refused: &[NO_AUTHOR], ignored: &[],};const N_PULLS: Route = Route { nsid: "org.tangled.repo.countPulls", source: "$arg_subject$arg_repo|$arg_status$arg_state", var: "$ks_soc_n_pulls", miss: "invalid_request", empty: Some(super::no_count), refused: &[NO_AUTHOR], ignored: &[],};const VIEW: Route = Route { nsid: "org.tangled.track.getTicketView", source: "$arg_uri", var: "$ks_soc_ticket", miss: "not_found", empty: None, refused: &[], ignored: &[],};const COMMENTS: Route = Route { nsid: "org.tangled.feed.listComments", source: "$arg_subject|$arg_order", var: "$ks_soc_comments", miss: "invalid_request", empty: Some(no_comments), refused: &[NO_CURSOR, NO_OFFSET], ignored: &["limit", "offset"],};const PATCHES: Route = Route { nsid: "org.tangled.temp.review.listPatches", source: "$arg_ticket|$arg_order", var: "$ks_soc_patches", miss: "invalid_request", empty: Some(super::no_items), refused: &[NO_CURSOR, NO_OFFSET], ignored: &["limit", "offset"],};
pub(super) const ROUTES: &[Route] = &[ISSUES, PULLS, N_ISSUES, N_PULLS, VIEW, COMMENTS, PATCHES];
403 unmodified linesExpand all