Skip to content

Commit

Permalink
Split the server into three crates (#56)
Browse files Browse the repository at this point in the history
This will make it easier to build variations on the server, or embed it
into larger projects.
  • Loading branch information
djmitche authored Nov 17, 2024
1 parent 5769781 commit 47ce4c1
Show file tree
Hide file tree
Showing 22 changed files with 1,243 additions and 57 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,24 @@ jobs:
override: true
minimal: true

- uses: actions-rs/[email protected]
- name: taskchampion-sync-server
uses: actions-rs/[email protected]
with:
command: rustdoc
args: -p taskchampion-sync-server --all-features -- -Z unstable-options --check -Dwarnings

- name: taskchampion-sync-server-core
uses: actions-rs/[email protected]
with:
command: rustdoc
args: -p taskchampion-sync-server-core --all-features -- -Z unstable-options --check -Dwarnings

- name: taskchampion-sync-server-storage-sqlite
uses: actions-rs/[email protected]
with:
command: rustdoc
args: -p taskchampion-sync-server-storage-sqlite --all-features -- -Z unstable-options --check -Dwarnings

fmt:
runs-on: ubuntu-latest
name: "Formatting"
Expand Down
41 changes: 34 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "taskchampion-sync-server"
version = "0.4.1"
authors = ["Dustin J. Mitchell <[email protected]>"]
edition = "2021"
publish = false
[workspace]
resolver = "2"
members = [
"core",
"server",
"sqlite",
]

[dependencies]
[workspace.dependencies]
uuid = { version = "^1.11.0", features = ["serde", "v4"] }
actix-web = "^4.9.0"
anyhow = "1.0"
Expand All @@ -18,8 +19,6 @@ log = "^0.4.17"
env_logger = "^0.11.5"
rusqlite = { version = "0.32", features = ["bundled"] }
chrono = { version = "^0.4.38", features = ["serde"] }

[dev-dependencies]
actix-rt = "2"
tempfile = "3"
pretty_assertions = "1"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ This repository was spun off from Taskwarrior itself after the 3.0.0
release. It is still under development and currently best described as
a reference implementation of the Taskchampion sync protocol.

It is comprised of three crates:

- `taskchampion-sync-server-core` implements the core of the protocol
- `taskchmpaion-sync-server-sqlite` implements an SQLite backend for the core
- `taskchampion-sync-server` implements a simple HTTP server for the protocol

## Installation

### From binary
Expand Down
15 changes: 15 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "taskchampion-sync-server-core"
version = "0.4.1"
authors = ["Dustin J. Mitchell <[email protected]>"]
edition = "2021"

[dependencies]
uuid.workspace = true
anyhow.workspace = true
log.workspace = true
env_logger.workspace = true
chrono.workspace = true

[dev-dependencies]
pretty_assertions.workspace = true
8 changes: 8 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# taskchampion-sync-server-core

This crate implements the core logic of the taskchampion sync protocol.

This should be considered a reference implementation, with [the protocol
documentation](https://gothenburgbitfactory.org/taskchampion/sync-protocol.html).
representing the authoritative definition of the protocol. Other
implementations are encouraged.
11 changes: 7 additions & 4 deletions src/storage/inmemory.rs → core/src/inmemory.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Client, Snapshot, Storage, StorageTxn, Uuid, Version};
use super::{Client, Snapshot, Storage, StorageTxn, Version};
use std::collections::HashMap;
use std::sync::{Mutex, MutexGuard};
use uuid::Uuid;

struct Inner {
/// Clients, indexed by client_id
Expand All @@ -16,6 +17,11 @@ struct Inner {
children: HashMap<(Uuid, Uuid), Uuid>,
}

/// In-memory storage for testing and experimentation.
///
/// This is not for production use, but supports testing of sync server implementations.
///
/// NOTE: this does not implement transaction rollback.
pub struct InMemoryStorage(Mutex<Inner>);

impl InMemoryStorage {
Expand All @@ -32,9 +38,6 @@ impl InMemoryStorage {

struct InnerTxn<'a>(MutexGuard<'a, Inner>);

/// In-memory storage for testing and experimentation.
///
/// NOTE: this does not implement transaction rollback.
impl Storage for InMemoryStorage {
fn txn<'a>(&'a self) -> anyhow::Result<Box<dyn StorageTxn + 'a>> {
Ok(Box::new(InnerTxn(self.0.lock().expect("poisoned lock"))))
Expand Down
32 changes: 32 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! This crate implements the core logic of the taskchampion sync protocol.
//!
//! This should be considered a reference implementation, with [the protocol
//! documentation](https://gothenburgbitfactory.org/taskchampion/sync-protocol.html). representing
//! the authoritative definition of the protocol. Other implementations are encouraged.
//!
//! This crate uses an abstract storage backend. Note that this does not implement the
//! HTTP-specific portions of the protocol, nor provide any storage implementations.
//!
//! ## API Methods
//!
//! The following API methods are implemented. These methods are documented in more detail in
//! the protocol documentation.
//!
//! * [`add_version`]
//! * [`get_child_version`]
//! * [`add_snapshot`]
//! * [`get_snapshot`]
//!
//! Each API method takes:
//!
//! * [`StorageTxn`] to access storage. Methods which modify storage will commit the transaction before returning.
//! * [`ServerConfig`] providing basic configuration for the server's behavior.
//! * `client_id` and a [`Client`] providing the client metadata.
mod inmemory;
mod server;
mod storage;

pub use inmemory::*;
pub use server::*;
pub use storage::*;
Loading

0 comments on commit 47ce4c1

Please sign in to comment.