pub mod attempts;
mod audit;
mod bookmark;
mod deps;
mod events;
pub(crate) mod footing;
mod links;
mod memory;
pub mod moves;
mod plan;
mod questions;
mod recall;
mod recess;
mod recusal;
mod requirements;
mod scope;
mod tasks;
mod verdict;
mod witness;
pub use attempts::{Attempts, Outcome};
pub use audit::{Audit, AuditEntry, Move, Stamp, TrailEntry};
pub use bookmark::Bookmarks;
pub use deps::{dispatch_waves, Claimable, Deps};
pub use events::{Events, FeedEvent, FeedFilter, ReplayedTask};
pub use footing::Footings;
pub use links::{LinkChange, Links};
pub use memory::{Memory, MemoryQuery, NewAssertion, Recorded};
pub use plan::{Applied, Drift, Placed, Plans};
pub use questions::Questions;
pub use recall::{Recall, RecallReason, Recalled};
pub use recess::{Called, Recesses};
pub use recusal::Recusals;
pub use requirements::Requirements;
pub use scope::{OnConflict, Scopes};
pub use tasks::{Claim, Dispatch, Finished, Subtask, SweepOutcome, Tasks};
pub use verdict::{Delivered, Verdicts};
pub use witness::{Baseline, FileTouch, Witnessed};
pub(crate) use scope::normalize_all;
use ulid::Ulid;
pub(crate) fn new_id() -> String {
Ulid::generate().to_string()
}
pub fn immediate_tx(
conn: &rusqlite::Connection,
) -> crate::error::Result<rusqlite::Transaction<'_>> {
Ok(rusqlite::Transaction::new_unchecked(
conn,
rusqlite::TransactionBehavior::Immediate,
)?)
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ProjectScope {
Only(String),
All,
}
impl ProjectScope {
pub fn resolve(project: &str, all_projects: bool) -> ProjectScope {
if all_projects {
ProjectScope::All
} else {
ProjectScope::Only(project.to_string())
}
}
pub fn is_all(&self) -> bool {
matches!(self, ProjectScope::All)
}
fn clause(&self, column: &str) -> (String, Option<&str>) {
match self {
ProjectScope::All => ("1 = 1".to_string(), None),
ProjectScope::Only(p) => (format!("{column} = ?"), Some(p.as_str())),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn scope_resolves_from_the_all_projects_flag() {
assert_eq!(
ProjectScope::resolve("/tmp/p", false),
ProjectScope::Only("/tmp/p".into())
);
assert_eq!(ProjectScope::resolve("/tmp/p", true), ProjectScope::All);
}
#[test]
fn ids_are_unique_and_time_ordered() {
let a = new_id();
let b = new_id();
assert_ne!(a, b);
assert_eq!(a.len(), b.len());
}
}