pub const OWN_PROVIDER: &str = "self";
pub const WORKSPACE_PROVIDER: &str = "workspace";
pub const APPLICATION_RESOURCE_PREFIX: &str = "app.";
pub const APPLICATION_RESOURCE_KIND: &str = "applications.app";
pub const APPLICATION_OPEN_ACTION: &str = "open";
pub const APPLICATION_START_ACTION: &str = "start";
pub const SHARE_LINK_ACTION: &str = "share-link";
pub const RESOURCE_PROVIDER: &str = "record";
#[must_use]
pub fn is_resource_provider(provider: &str) -> bool {
provider
.strip_prefix(RESOURCE_PROVIDER)
.is_some_and(|rest| rest.starts_with(':'))
}
#[must_use]
pub fn resource_parts(provider: &str) -> Option<(&str, &str)> {
provider
.strip_prefix(RESOURCE_PROVIDER)?
.strip_prefix(':')?
.split_once(':')
.filter(|(app, _)| !app.is_empty())
}
#[cfg(test)]
mod tests {
#![allow(
clippy::unwrap_used,
clippy::panic,
reason = "in a test these are the assertion, not a hazard"
)]
use super::*;
#[test]
fn a_record_provider_names_its_app_and_record() {
assert_eq!(
resource_parts("record:so.tilo.notes:uuid:7"),
Some(("so.tilo.notes", "uuid:7"))
);
assert_eq!(
resource_parts("record:so.tilo.chat:"),
Some(("so.tilo.chat", ""))
);
assert_eq!(resource_parts("record:so.tilo.chat"), None);
assert_eq!(resource_parts("record::main"), None);
assert_eq!(resource_parts("workspace:6b3f9a10"), None);
assert_eq!(resource_parts("4711"), None);
assert!(!is_resource_provider("4711"));
assert!(is_resource_provider("record:so.tilo.chat:"));
}
}