chadtmiller.com/monolith
An atproto PDS
0
0
Lay the Rust out as a flat workspace
.knotless/review.md+1−1
| @@ -1,4 +1,4 @@ | ||
This repository builds a PDS from specifications: agents build `server/` from `spec/`, and `harness/` checks it against the reference PDS. Check that: | ||
This repository builds a PDS from specifications: agents build `crates/` from `spec/`, and `harness/` checks it against the reference PDS. Check that: | ||
| ||
- Every change in behaviour is in `spec/` (`SLICE.md` or a lexicon) as well as in the code, and the README says what is built, not how it came to be built. | ||
- A harness change makes a check stricter or fixes it, and never loosens one so that a server passes. A new check says what it compares, and with what. | ||
server/src/data.rs → crates/pds-repo/src/data.rsrenamed+2−2
| @@ -264,7 +264,7 @@ mod tests { | ||
| ||
#[test] | ||
fn fixtures() { | ||
let text = std::fs::read_to_string("../spec/interop/data-model/data-model-fixtures.json").unwrap(); | ||
let text = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/../../spec/interop/data-model/data-model-fixtures.json")).unwrap(); | ||
let fixtures: Vec<Json> = serde_json::from_str(&text).unwrap(); | ||
for f in fixtures { | ||
let v = from_json(&f["json"]).unwrap(); | ||
| @@ -277,7 +277,7 @@ mod tests { | ||
| ||
#[test] | ||
fn invalid() { | ||
let text = std::fs::read_to_string("../spec/interop/data-model/data-model-invalid.json").unwrap(); | ||
let text = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/../../spec/interop/data-model/data-model-invalid.json")).unwrap(); | ||
let cases: Vec<Json> = serde_json::from_str(&text).unwrap(); | ||
for c in cases { | ||
let j = &c["json"]; | ||
server/src/repo.rs → crates/pds-repo/src/lib.rsrenamed+6−2
| @@ -1,7 +1,11 @@ | ||
//! The account's repository: records, MST, signed commits, CAR export. | ||
//! The account's repository: the data model, the MST, signed commits, CAR | ||
//! export. Pure: it does no I/O. | ||
| ||
pub mod data; | ||
pub mod mst; | ||
| ||
use crate::data::*; | ||
use crate::mst::{self, Block}; | ||
use crate::mst::Block; | ||
use k256::ecdsa::SigningKey; | ||
use k256::ecdsa::signature::hazmat::PrehashSigner; | ||
use sha2::{Digest, Sha256}; | ||
server/src/mst.rs → crates/pds-repo/src/mst.rsrenamed+1−1
| @@ -143,7 +143,7 @@ mod tests { | ||
| ||
#[test] | ||
fn heights() { | ||
let text = std::fs::read_to_string("../spec/interop/mst/key_heights.json").unwrap(); | ||
let text = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/../../spec/interop/mst/key_heights.json")).unwrap(); | ||
let cases: Vec<serde_json::Value> = serde_json::from_str(&text).unwrap(); | ||
for c in cases { | ||
assert_eq!(depth(c["key"].as_str().unwrap().as_bytes()), c["height"].as_u64().unwrap() as usize, "{}", c["key"]); | ||
crates/pds-repo/Cargo.tomlnew+12−0
| @@ -0,0 +1,12 @@ | ||
[package] | ||
name = "pds-repo" | ||
version.workspace = true | ||
edition.workspace = true | ||
publish.workspace = true | ||
| ||
[dependencies] | ||
base64.workspace = true | ||
k256.workspace = true | ||
rand.workspace = true | ||
serde_json.workspace = true | ||
sha2.workspace = true | ||
server/src/events.rs → crates/pds-server/src/events.rsrenamed+2−2
| @@ -1,7 +1,7 @@ | ||
//! The firehose: `com.atproto.sync.subscribeRepos` events and the WebSocket that serves them. | ||
| ||
use crate::data::*; | ||
use crate::repo::{Change, car_file}; | ||
use pds_repo::data::*; | ||
use pds_repo::{Change, car_file}; | ||
use crate::Shared; | ||
use axum::extract::ws::{Message, WebSocket, WebSocketUpgrade}; | ||
use axum::extract::{Query, State}; | ||
server/src/main.rs → crates/pds-server/src/main.rsrenamed+4−7
| @@ -1,8 +1,4 @@ | ||
mod data; | ||
mod events; | ||
mod mst; | ||
mod repo; | ||
mod store; | ||
| ||
use axum::{ | ||
Router, | ||
| @@ -12,12 +8,12 @@ use axum::{ | ||
response::{IntoResponse, Response}, | ||
routing::{any, get}, | ||
}; | ||
use data::*; | ||
use repo::*; | ||
use pds_repo::data::*; | ||
use pds_repo::*; | ||
use pds_store::Wal; | ||
use serde_json::{Value as Json, json}; | ||
use std::path::Path as FsPath; | ||
use std::sync::{Arc, Mutex}; | ||
use store::Wal; | ||
| ||
struct Server { | ||
did: String, | ||
| @@ -532,6 +528,7 @@ fn apply_writes(s: &mut Server, b: &serde_json::Map<String, Json>, swap_commit: | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use pds_store as store; | ||
| ||
const DID: &str = "did:plc:test"; | ||
| ||
crates/pds-server/Cargo.tomlnew+15−0
| @@ -0,0 +1,15 @@ | ||
[package] | ||
name = "pds-server" | ||
version.workspace = true | ||
edition.workspace = true | ||
publish.workspace = true | ||
| ||
[dependencies] | ||
pds-repo.workspace = true | ||
pds-store.workspace = true | ||
axum.workspace = true | ||
hex.workspace = true | ||
k256.workspace = true | ||
rand.workspace = true | ||
serde_json.workspace = true | ||
tokio.workspace = true | ||
server/src/store.rs → crates/pds-store/src/lib.rsrenamed+0−0
Moved without changes.
crates/pds-store/Cargo.tomlnew+9−0
| @@ -0,0 +1,9 @@ | ||
[package] | ||
name = "pds-store" | ||
version.workspace = true | ||
edition.workspace = true | ||
publish.workspace = true | ||
| ||
[dependencies] | ||
serde_json.workspace = true | ||
sha2.workspace = true | ||
server/Cargo.tomldeleted+0−19
| @@ -1,19 +0,0 @@ | ||
[package] | ||
name = "pds-server" | ||
version = "0.1.0" | ||
edition = "2024" | ||
publish = false | ||
| ||
[[bin]] | ||
name = "pds-server" | ||
path = "src/main.rs" | ||
| ||
[dependencies] | ||
tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "sync"] } | ||
axum = { version = "0.8", features = ["ws"] } | ||
serde_json = "1" | ||
sha2 = "0.10" | ||
k256 = { version = "0.13", features = ["ecdsa"] } | ||
base64 = "0.22" | ||
rand = "0.8" | ||
hex = "0.4" | ||