MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / listing_sort

Function listing_sort

libatomic/src/daemon/services_agent.rs:830–853  ·  view source on GitHub ↗

Validate a `ListVaultEntries` sort against the listing it applies to and resolve UNSPECIFIED to the kind's default key (intents by id, memories by last update). Only the intent and memory listings sort, and only by columns they carry.

(kind: Option<Kind>, raw: Option<i32>)

Source from the content-addressed store, hash-verified

828/// last update). Only the intent and memory listings sort, and only by
829/// columns they carry.
830fn listing_sort(kind: Option<Kind>, raw: Option<i32>) -> Result<VaultListSort, Status> {
831 use VaultListSort as S;
832 let sort = raw
833 .map(|raw| {
834 S::try_from(raw).map_err(|_| Status::invalid_argument("unknown vault list sort"))
835 })
836 .transpose()?
837 .unwrap_or(S::Unspecified);
838 match (kind, sort) {
839 (Some(Kind::Intent), S::Unspecified) => Ok(S::Id),
840 (Some(Kind::Memory), S::Unspecified) => Ok(S::Updated),
841 (_, S::Unspecified) => Ok(S::Unspecified),
842 (Some(Kind::Intent), S::Updated | S::About) | (Some(Kind::Memory), S::Title) => {
843 Err(Status::invalid_argument(format!(
844 "{} is not a sort key for this vault listing",
845 sort.as_str_name()
846 )))
847 }
848 (Some(Kind::Intent | Kind::Memory), _) => Ok(sort),
849 _ => Err(Status::invalid_argument(
850 "sort applies only to the intent and memory listings",
851 )),
852 }
853}
854
855/// Order an intent or memory listing by an already-validated key, with id as
856/// the tiebreak. `reverse` flips the key, not the tiebreak.

Callers 1

list_vault_entriesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected