diff --git a/Cargo.lock b/Cargo.lock index bfde1090..7bd5a1c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,9 @@ dependencies = [ name = "alexandrie" version = "0.1.0" dependencies = [ + "alexandrie-index 0.1.0", + "alexandrie-rendering 0.1.0", + "alexandrie-storage 0.1.0", "async-std 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "bigdecimal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -57,6 +60,37 @@ dependencies = [ "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "alexandrie-index" +version = "0.1.0" +dependencies = [ + "git2 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "alexandrie-rendering" +version = "0.1.0" +dependencies = [ + "pulldown-cmark 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "syntect 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "alexandrie-storage" +version = "0.1.0" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ansi_term" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 8216e182..61044d83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,87 +1,7 @@ -[package] -name = "alexandrie" -version = "0.1.0" -edition = "2018" -authors = ["Nicolas Polomack "] -description = "An alternative crate registry, implemented in Rust." -repository = "https://github.com/Hirevo/alexandrie" -documentation = "https://crates.polomack.eu/docs/alexandrie" -keywords = ["crates", "cargo", "web", "registry"] -categories = ["development-tools"] -license = "MIT OR Apache-2.0" - -default-run = "alexandrie" - -[dependencies] -# core -tide = { version = "0.5.0" } -http = { version = "0.1.21" } - -# data types -url = { version = "2.1.1" } -semver = { version = "0.9.0", features = ["serde"] } -chrono = { version = "0.4.10", features = ["serde"] } - -# file formats -serde = { version = "1.0.104", features = ["derive"] } -json = { package = "serde_json", version = "1.0.44" } -toml = { version = "0.5.5" } - -# binary parsing -byteorder = { version = "1.3.2" } -bytes = { version = "0.5.3" } - -# (en|de)coding / hashing -ring = { version = "0.16.9" } -hex = { version = "0.4.0" } -base64 = { version = "0.11.0" } -percent-encoding = { version = "2.1.0" } - -# database -diesel = { version = "1.4.3", features = ["r2d2", "chrono", "numeric"] } -diesel_migrations = { version = "1.4.0" } - -# async primitives -async-std = { version = "1.4.0", features = ["unstable", "attributes"] } -futures = { version = "0.3.1" } - -# error handling -thiserror = { version = "1.0.9" } - -# README rendering -syntect = { version = "3.3.0" } -cmark = { package = "pulldown-cmark", version = "0.6.1" } -flate2 = { version = "1.0.13" } -tar = { version = "0.4.26" } - -# frontend -handlebars = { version = "2.0.4", optional = true } -cookie = { version = "0.12.0", features = ["percent-encode"], optional = true } -time = { version = "0.1.42", optional = true } -num-format = { version = "0.4.0", optional = true } -bigdecimal = { version = "0.1.0", features = ["serde"], optional = true } - -# git2 -git2 = { version = "0.11.0", optional = true } - -# logs -log = { version = "0.4.8" } -slog = { version = "2.5.2" } -slog-stdlog = { version = "4.0.0" } -slog-scope = { version = "4.3.0" } -slog-term = { version = "2.4.2" } -slog-async = { version = "2.3.0" } -slog-json = { version = "2.3.0" } - -# miscellaneous -path-absolutize = { version = "1.1.7" } -mime_guess = { version = "2.0.1" } - -[features] -# default = ["frontend", "sqlite"] -# default = ["frontend", "mysql"] -default = ["frontend", "postgres"] -frontend = ["handlebars", "num-format", "bigdecimal", "cookie", "time"] -mysql = ["diesel/mysql", "diesel_migrations/mysql"] -sqlite = ["diesel/sqlite", "diesel_migrations/sqlite"] -postgres = ["diesel/postgres", "diesel_migrations/postgres"] +[workspace] +members = [ + "alexandrie", + "alexandrie-index", + "alexandrie-storage", + "alexandrie-rendering" +] diff --git a/alexandrie-index/Cargo.toml b/alexandrie-index/Cargo.toml new file mode 100644 index 00000000..dba14764 --- /dev/null +++ b/alexandrie-index/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "alexandrie-index" +version = "0.1.0" +edition = "2018" +authors = ["Nicolas Polomack "] +description = "The index management library for Alexandrie, an alternative crate registry." +repository = "https://github.com/Hirevo/alexandrie" +documentation = "https://crates.polomack.eu/docs/alexandrie" +keywords = ["crates", "cargo", "web", "registry"] +categories = ["development-tools"] +license = "MIT OR Apache-2.0" + +[dependencies] +# data types +semver = { version = "0.9.0", features = ["serde"] } + +# file formats +serde = { version = "1.0.104", features = ["derive"] } +json = { package = "serde_json", version = "1.0.44" } + +# error handling +thiserror = { version = "1.0.9" } + +# git2 +git2 = { version = "0.11.0", optional = true } diff --git a/src/index/cli.rs b/alexandrie-index/src/cli.rs similarity index 97% rename from src/index/cli.rs rename to alexandrie-index/src/cli.rs index f8149d0c..bd5d4a2e 100644 --- a/src/index/cli.rs +++ b/alexandrie-index/src/cli.rs @@ -4,8 +4,9 @@ use std::process::{Command, Stdio}; use semver::{Version, VersionReq}; use crate::error::Error; -use crate::index::tree::Tree; -use crate::index::{CrateVersion, Indexer}; +use crate::models::CrateVersion; +use crate::tree::Tree; +use crate::Indexer; /// The 'command-line' crate index management strategy type. /// diff --git a/src/config/index/cli.rs b/alexandrie-index/src/config/cli.rs similarity index 93% rename from src/config/index/cli.rs rename to alexandrie-index/src/config/cli.rs index 5c5d3b06..1b18b341 100644 --- a/src/config/index/cli.rs +++ b/alexandrie-index/src/config/cli.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; -use crate::index::cli::CommandLineIndex; +use crate::cli::CommandLineIndex; /// The configuration struct for the 'command-line' index management strategy. /// diff --git a/src/config/index/git2.rs b/alexandrie-index/src/config/git2.rs similarity index 94% rename from src/config/index/git2.rs rename to alexandrie-index/src/config/git2.rs index ae2c2449..13218486 100644 --- a/src/config/index/git2.rs +++ b/alexandrie-index/src/config/git2.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; -use crate::index::git2::Git2Index; +use crate::git2::Git2Index; /// The configuration struct for the 'git2' index management strategy. /// diff --git a/src/config/index/mod.rs b/alexandrie-index/src/config/mod.rs similarity index 89% rename from src/config/index/mod.rs rename to alexandrie-index/src/config/mod.rs index b864dfc6..9c8d1586 100644 --- a/src/config/index/mod.rs +++ b/alexandrie-index/src/config/mod.rs @@ -7,11 +7,11 @@ pub mod cli; #[cfg(feature = "git2")] pub mod git2; -use crate::config::index::cli::CommandLineIndexConfig; -use crate::index::Index; +use crate::config::cli::CommandLineIndexConfig; +use crate::Index; #[cfg(feature = "git2")] -use crate::config::index::git2::Git2IndexConfig; +use crate::config::git2::Git2IndexConfig; /// The configuration enum for index management strategies. /// diff --git a/alexandrie-index/src/error.rs b/alexandrie-index/src/error.rs new file mode 100644 index 00000000..9c72a51a --- /dev/null +++ b/alexandrie-index/src/error.rs @@ -0,0 +1,43 @@ +use semver::Version; +use thiserror::Error; + +/// The Error type for the registry. +/// +/// It can represent any kind of error the registry might encounter. +#[derive(Error, Debug)] +pub enum Error { + /// An IO error (file not found, access forbidden, etc...). + #[error("IO error: {0}")] + IOError(#[from] std::io::Error), + /// JSON (de)serialization error (invalid JSON parsed, etc...). + #[error("JSON error: {0}")] + JSONError(#[from] json::Error), + /// Git2 error. + #[error("libgit2 error: {0}")] + #[cfg(feature = "git2")] + Git2Error(#[from] git2::Error), + /// Other index-specific error (crate not found, etc...). + #[error("index-specific error: {0}")] + IndexError(#[from] IndexError), +} + +/// The Error type for Alexandrie's own errors. +#[derive(Error, Debug)] +pub enum IndexError { + /// The requested crate cannot be found. + #[error("no crate named '{name}' found")] + CrateNotFound { + /// The requested crate's name. + name: String, + }, + /// The published crate version is lower than the current hosted version. + #[error("the published version is too low (hosted version is {hosted}, and thus {published} <= {hosted})")] + VersionTooLow { + /// The krate's name. + krate: String, + /// The available hosted version. + hosted: Version, + /// The proposed version to be published. + published: Version, + }, +} diff --git a/src/index/git2.rs b/alexandrie-index/src/git2.rs similarity index 98% rename from src/index/git2.rs rename to alexandrie-index/src/git2.rs index 918cfb2d..636ff93f 100644 --- a/src/index/git2.rs +++ b/alexandrie-index/src/git2.rs @@ -4,8 +4,9 @@ use std::sync::Mutex; use semver::{Version, VersionReq}; use crate::error::Error; -use crate::index::tree::Tree; -use crate::index::{CrateVersion, Indexer}; +use crate::models::CrateVersion; +use crate::tree::Tree; +use crate::Indexer; /// The 'git2' crate index management strategy type. /// diff --git a/src/index/mod.rs b/alexandrie-index/src/lib.rs similarity index 96% rename from src/index/mod.rs rename to alexandrie-index/src/lib.rs index 82c27f6f..8295db13 100644 --- a/src/index/mod.rs +++ b/alexandrie-index/src/lib.rs @@ -2,21 +2,26 @@ use semver::{Version, VersionReq}; /// Index management through `git` shell command invocations. pub mod cli; -mod models; -mod tree; +/// Configuration-related types. +pub mod config; +/// Error-handling types. +pub mod error; /// Index management using [**`libgit2`**][libgit2]. /// [libgit2]: https://libgit2.org #[cfg(feature = "git2")] pub mod git2; -pub use models::{CrateDependency, CrateDependencyKind, CrateVersion}; +mod models; +mod tree; + +pub use models::*; +use crate::cli::CommandLineIndex; use crate::error::Error; -use crate::index::cli::CommandLineIndex; #[cfg(feature = "git2")] -use crate::index::git2::Git2Index; +use crate::git2::Git2Index; /// The crate indexing management strategy type. /// diff --git a/src/index/models.rs b/alexandrie-index/src/models.rs similarity index 100% rename from src/index/models.rs rename to alexandrie-index/src/models.rs diff --git a/src/index/tree.rs b/alexandrie-index/src/tree.rs similarity index 91% rename from src/index/tree.rs rename to alexandrie-index/src/tree.rs index 54d281b7..a3a9c551 100644 --- a/src/index/tree.rs +++ b/alexandrie-index/src/tree.rs @@ -1,13 +1,14 @@ -use super::models::CrateVersion; -use crate::error::AlexError; -use crate::Error; -use semver::{Version, VersionReq}; use std::fs; use std::io; use std::io::BufRead; use std::io::Write; use std::path::PathBuf; +use semver::{Version, VersionReq}; + +use crate::error::{Error, IndexError}; +use crate::models::CrateVersion; + #[derive(Debug, Clone, PartialEq)] pub struct Tree { path: PathBuf, @@ -30,7 +31,7 @@ impl Tree { pub fn match_record(&self, name: &str, req: VersionReq) -> Result { let path = self.compute_record_path(name); let file = fs::File::open(path).map_err(|err| match err.kind() { - io::ErrorKind::NotFound => Error::from(AlexError::CrateNotFound { + io::ErrorKind::NotFound => Error::from(IndexError::CrateNotFound { name: String::from(name), }), _ => Error::from(err), @@ -41,7 +42,7 @@ impl Tree { .flat_map(|ret: Option| ret.into_iter()) .filter(|krate| req.matches(&krate.vers)) .max_by(|k1, k2| k1.vers.cmp(&k2.vers)); - Ok(found.ok_or_else(|| AlexError::CrateNotFound { + Ok(found.ok_or_else(|| IndexError::CrateNotFound { name: String::from(name), })?) } @@ -77,7 +78,7 @@ impl Tree { .max_by(|k1, k2| k1.vers.cmp(&k2.vers)) .expect("at least one record should exist"); if record.vers <= latest.vers { - return Err(Error::from(AlexError::VersionTooLow { + return Err(Error::from(IndexError::VersionTooLow { krate: record.name, hosted: latest.vers, published: record.vers, @@ -106,7 +107,7 @@ impl Tree { { let path = self.compute_record_path(name); let file = fs::File::open(path.as_path()).map_err(|err| match err.kind() { - io::ErrorKind::NotFound => Error::from(AlexError::CrateNotFound { + io::ErrorKind::NotFound => Error::from(IndexError::CrateNotFound { name: String::from(name), }), _ => Error::from(err), @@ -123,7 +124,7 @@ impl Tree { .iter_mut() .find(|krate| krate.vers == version) .ok_or_else(|| { - Error::from(AlexError::CrateNotFound { + Error::from(IndexError::CrateNotFound { name: String::from(name), }) })?; diff --git a/alexandrie-rendering/Cargo.toml b/alexandrie-rendering/Cargo.toml new file mode 100644 index 00000000..5c51b130 --- /dev/null +++ b/alexandrie-rendering/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "alexandrie-rendering" +version = "0.1.0" +edition = "2018" +authors = ["Nicolas Polomack "] +description = "The markdown rendering library for Alexandrie, an alternative crate registry." +repository = "https://github.com/Hirevo/alexandrie" +documentation = "https://crates.polomack.eu/docs/alexandrie" +keywords = ["crates", "cargo", "web", "registry"] +categories = ["development-tools"] +license = "MIT OR Apache-2.0" + +[dependencies] +# data types +semver = { version = "0.9.0", features = ["serde"] } + +# file formats +serde = { version = "1.0.104", features = ["derive"] } + +# error handling +thiserror = { version = "1.0.9" } + +# README rendering +syntect = { version = "3.3.0" } +cmark = { package = "pulldown-cmark", version = "0.6.1" } diff --git a/src/config/syntect.rs b/alexandrie-rendering/src/config.rs similarity index 100% rename from src/config/syntect.rs rename to alexandrie-rendering/src/config.rs diff --git a/src/utils/rendering.rs b/alexandrie-rendering/src/lib.rs similarity index 97% rename from src/utils/rendering.rs rename to alexandrie-rendering/src/lib.rs index 7019bcfc..0d169316 100644 --- a/src/utils/rendering.rs +++ b/alexandrie-rendering/src/lib.rs @@ -4,7 +4,10 @@ use syntect::html::{ start_highlighted_html_snippet, styled_line_to_highlighted_html, IncludeBackground, }; -use crate::config::syntect::SyntectState; +/// Configuration-related types. +pub mod config; + +use crate::config::SyntectState; /// Stores the location and level of an header tag inside a Markdown document. #[derive(Debug, Clone, PartialEq)] diff --git a/alexandrie-storage/Cargo.toml b/alexandrie-storage/Cargo.toml new file mode 100644 index 00000000..34cb7622 --- /dev/null +++ b/alexandrie-storage/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "alexandrie-storage" +version = "0.1.0" +edition = "2018" +authors = ["Nicolas Polomack "] +description = "The crate storage library for Alexandrie, an alternative crate registry." +repository = "https://github.com/Hirevo/alexandrie" +documentation = "https://crates.polomack.eu/docs/alexandrie" +keywords = ["crates", "cargo", "web", "registry"] +categories = ["development-tools"] +license = "MIT OR Apache-2.0" + +[dependencies] +# data types +semver = { version = "0.9.0", features = ["serde"] } + +# file formats +serde = { version = "1.0.104", features = ["derive"] } + +# error handling +thiserror = { version = "1.0.9" } diff --git a/src/config/storage/disk.rs b/alexandrie-storage/src/config/disk.rs similarity index 93% rename from src/config/storage/disk.rs rename to alexandrie-storage/src/config/disk.rs index 59421d35..497d1cf2 100644 --- a/src/config/storage/disk.rs +++ b/alexandrie-storage/src/config/disk.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; -use crate::storage::disk::DiskStorage; +use crate::disk::DiskStorage; /// The configuration struct for the 'disk' storage strategy. /// diff --git a/src/config/storage/mod.rs b/alexandrie-storage/src/config/mod.rs similarity index 89% rename from src/config/storage/mod.rs rename to alexandrie-storage/src/config/mod.rs index da23dcdb..f396eb8c 100644 --- a/src/config/storage/mod.rs +++ b/alexandrie-storage/src/config/mod.rs @@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize}; /// The 'disk' configuration. pub mod disk; -use crate::config::storage::disk::DiskStorageConfig; -use crate::storage::Storage; +use crate::config::disk::DiskStorageConfig; +use crate::Storage; /// The configuration enum for storage strategies. /// diff --git a/src/storage/disk.rs b/alexandrie-storage/src/disk.rs similarity index 97% rename from src/storage/disk.rs rename to alexandrie-storage/src/disk.rs index 700e7916..e2bfbccf 100644 --- a/src/storage/disk.rs +++ b/alexandrie-storage/src/disk.rs @@ -5,9 +5,9 @@ use std::path::PathBuf; use semver::Version; use crate::error::Error; -use crate::storage::Store; +use crate::Store; -/// The local on-disk storage strategy. +/// The local on-disk storage strategy. /// /// It stores the crates as files in the given directory. /// It names the crates as `"{name}-{version}.crate"`. diff --git a/alexandrie-storage/src/error.rs b/alexandrie-storage/src/error.rs new file mode 100644 index 00000000..04b52cfd --- /dev/null +++ b/alexandrie-storage/src/error.rs @@ -0,0 +1,11 @@ +use thiserror::Error; + +/// The Error type for the registry. +/// +/// It can represent any kind of error the registry might encounter. +#[derive(Error, Debug)] +pub enum Error { + /// An IO error (file not found, access forbidden, etc...). + #[error("IO error: {0}")] + IOError(#[from] std::io::Error), +} diff --git a/src/storage/mod.rs b/alexandrie-storage/src/lib.rs similarity index 95% rename from src/storage/mod.rs rename to alexandrie-storage/src/lib.rs index 49e38bab..fbebefe8 100644 --- a/src/storage/mod.rs +++ b/alexandrie-storage/src/lib.rs @@ -2,13 +2,17 @@ use std::io::{self, Read}; use semver::Version; +/// Configuration-related types. +pub mod config; /// Local on-disk crate storage mechanism. pub mod disk; +/// Error-handling types. +pub mod error; +use crate::disk::DiskStorage; use crate::error::Error; -use crate::storage::disk::DiskStorage; -/// The crate storage strategy enum type. +/// The crate storage strategy enum type. /// /// It represents which storage strategy is currently used. #[derive(Debug, Clone, PartialEq)] @@ -17,7 +21,6 @@ pub enum Storage { Disk(DiskStorage), // TODO: Add a `Store` implementation using S3. // S3(S3Storage), - // TODO: Add a `Store` implementation using a git repository. // Git(GitStorage), } diff --git a/alexandrie/Cargo.toml b/alexandrie/Cargo.toml new file mode 100644 index 00000000..220fe04b --- /dev/null +++ b/alexandrie/Cargo.toml @@ -0,0 +1,92 @@ +[package] +name = "alexandrie" +version = "0.1.0" +edition = "2018" +authors = ["Nicolas Polomack "] +description = "An alternative crate registry, implemented in Rust." +repository = "https://github.com/Hirevo/alexandrie" +documentation = "https://crates.polomack.eu/docs/alexandrie" +keywords = ["crates", "cargo", "web", "registry"] +categories = ["development-tools"] +license = "MIT OR Apache-2.0" + +default-run = "alexandrie" + +[dependencies] +# internal +alexandrie-index = { version = "0.1.0", path = "../alexandrie-index" } +alexandrie-storage = { version = "0.1.0", path = "../alexandrie-storage" } +alexandrie-rendering = { version = "0.1.0", path = "../alexandrie-rendering" } + +# core +tide = { version = "0.5.0" } +http = { version = "0.1.21" } + +# data types +url = { version = "2.1.1" } +semver = { version = "0.9.0", features = ["serde"] } +chrono = { version = "0.4.10", features = ["serde"] } + +# file formats +serde = { version = "1.0.104", features = ["derive"] } +json = { package = "serde_json", version = "1.0.44" } +toml = { version = "0.5.5" } + +# binary parsing +byteorder = { version = "1.3.2" } +bytes = { version = "0.5.3" } + +# (en|de)coding / hashing +ring = { version = "0.16.9" } +hex = { version = "0.4.0" } +base64 = { version = "0.11.0" } +percent-encoding = { version = "2.1.0" } + +# database +diesel = { version = "1.4.3", features = ["r2d2", "chrono", "numeric"] } +diesel_migrations = { version = "1.4.0" } + +# async primitives +async-std = { version = "1.4.0", features = ["unstable", "attributes"] } +futures = { version = "0.3.1" } + +# error handling +thiserror = { version = "1.0.9" } + +# README rendering +syntect = { version = "3.3.0" } +cmark = { package = "pulldown-cmark", version = "0.6.1" } +flate2 = { version = "1.0.13" } +tar = { version = "0.4.26" } + +# frontend +handlebars = { version = "2.0.4", optional = true } +cookie = { version = "0.12.0", features = ["percent-encode"], optional = true } +time = { version = "0.1.42", optional = true } +num-format = { version = "0.4.0", optional = true } +bigdecimal = { version = "0.1.0", features = ["serde"], optional = true } + +# git2 +git2 = { version = "0.11.0", optional = true } + +# logs +log = { version = "0.4.8" } +slog = { version = "2.5.2" } +slog-stdlog = { version = "4.0.0" } +slog-scope = { version = "4.3.0" } +slog-term = { version = "2.4.2" } +slog-async = { version = "2.3.0" } +slog-json = { version = "2.3.0" } + +# miscellaneous +path-absolutize = { version = "1.1.7" } +mime_guess = { version = "2.0.1" } + +[features] +# default = ["frontend", "sqlite"] +# default = ["frontend", "mysql"] +default = ["frontend", "postgres"] +frontend = ["handlebars", "num-format", "bigdecimal", "cookie", "time"] +mysql = ["diesel/mysql", "diesel_migrations/mysql"] +sqlite = ["diesel/sqlite", "diesel_migrations/sqlite"] +postgres = ["diesel/postgres", "diesel_migrations/postgres"] diff --git a/src/api/categories.rs b/alexandrie/src/api/categories.rs similarity index 100% rename from src/api/categories.rs rename to alexandrie/src/api/categories.rs diff --git a/src/api/download.rs b/alexandrie/src/api/download.rs similarity index 98% rename from src/api/download.rs rename to alexandrie/src/api/download.rs index 6ea936c0..ac35e73b 100644 --- a/src/api/download.rs +++ b/alexandrie/src/api/download.rs @@ -4,9 +4,10 @@ use diesel::prelude::*; use semver::Version; use tide::{Request, Response}; +use alexandrie_storage::Store; + use crate::db::schema::*; use crate::error::{AlexError, Error}; -use crate::storage::Store; use crate::State; /// Route to download a crate's tarball (used by `cargo build`). diff --git a/src/api/mod.rs b/alexandrie/src/api/mod.rs similarity index 100% rename from src/api/mod.rs rename to alexandrie/src/api/mod.rs diff --git a/src/api/owners.rs b/alexandrie/src/api/owners.rs similarity index 100% rename from src/api/owners.rs rename to alexandrie/src/api/owners.rs diff --git a/src/api/publish.rs b/alexandrie/src/api/publish.rs similarity index 98% rename from src/api/publish.rs rename to alexandrie/src/api/publish.rs index 7e15b0f7..bf75e462 100644 --- a/src/api/publish.rs +++ b/alexandrie/src/api/publish.rs @@ -15,6 +15,9 @@ use serde::{Deserialize, Serialize}; use tar::Archive; use tide::{Request, Response}; +use alexandrie_index::{CrateDependency, CrateDependencyKind, CrateVersion, Indexer}; +use alexandrie_storage::Store; + use crate::db::models::{ Crate, NewBadge, NewCrate, NewCrateAuthor, NewCrateCategory, NewCrateKeyword, }; @@ -22,8 +25,6 @@ use crate::db::schema::*; use crate::db::Connection; use crate::db::DATETIME_FORMAT; use crate::error::{AlexError, Error}; -use crate::index::{CrateDependency, CrateDependencyKind, CrateVersion, Indexer}; -use crate::storage::Store; use crate::utils; use crate::State; @@ -350,7 +351,7 @@ pub(crate) async fn put(mut req: Request) -> Result { let mut contents = String::new(); found?.read_to_string(&mut contents)?; - let rendered = utils::rendering::render_readme(&state.syntect, contents.as_str()); + let rendered = alexandrie_rendering::render_readme(&state.syntect, contents.as_str()); state.storage.store_readme( &crate_desc.name, diff --git a/src/api/search.rs b/alexandrie/src/api/search.rs similarity index 99% rename from src/api/search.rs rename to alexandrie/src/api/search.rs index e8a628ff..fd23d2ea 100644 --- a/src/api/search.rs +++ b/alexandrie/src/api/search.rs @@ -6,11 +6,12 @@ use semver::Version; use serde::{Deserialize, Serialize}; use tide::{Request, Response}; +use alexandrie_index::Indexer; + use crate::db::models::Crate; use crate::db::schema::*; use crate::db::DATETIME_FORMAT; use crate::error::{AlexError, Error}; -use crate::index::Indexer; use crate::utils; use crate::State; diff --git a/src/api/unyank.rs b/alexandrie/src/api/unyank.rs similarity index 98% rename from src/api/unyank.rs rename to alexandrie/src/api/unyank.rs index d6d2609d..5614f503 100644 --- a/src/api/unyank.rs +++ b/alexandrie/src/api/unyank.rs @@ -3,8 +3,9 @@ use json::json; use semver::Version; use tide::{Request, Response}; +use alexandrie_index::Indexer; + use crate::error::{AlexError, Error}; -use crate::index::Indexer; use crate::utils; use crate::State; diff --git a/src/api/yank.rs b/alexandrie/src/api/yank.rs similarity index 98% rename from src/api/yank.rs rename to alexandrie/src/api/yank.rs index 38967736..c9b056f8 100644 --- a/src/api/yank.rs +++ b/alexandrie/src/api/yank.rs @@ -3,8 +3,9 @@ use json::json; use semver::Version; use tide::{Request, Response}; +use alexandrie_index::Indexer; + use crate::error::{AlexError, Error}; -use crate::index::Indexer; use crate::utils; use crate::State; diff --git a/src/bin/dump.rs b/alexandrie/src/bin/dump.rs similarity index 100% rename from src/bin/dump.rs rename to alexandrie/src/bin/dump.rs diff --git a/src/config/database.rs b/alexandrie/src/config/database.rs similarity index 100% rename from src/config/database.rs rename to alexandrie/src/config/database.rs diff --git a/src/config/frontend.rs b/alexandrie/src/config/frontend.rs similarity index 100% rename from src/config/frontend.rs rename to alexandrie/src/config/frontend.rs diff --git a/src/config/mod.rs b/alexandrie/src/config/mod.rs similarity index 81% rename from src/config/mod.rs rename to alexandrie/src/config/mod.rs index 251f1fcb..36b9ab91 100644 --- a/src/config/mod.rs +++ b/alexandrie/src/config/mod.rs @@ -4,25 +4,21 @@ use serde::{Deserialize, Serialize}; /// Database configuration (`[database]` section). pub mod database; -/// Index management strategy configuration (`[index]` section). -pub mod index; -/// Crate storage configuration (`[storage]` section). -pub mod storage; -/// Syntax-highlighting configurations (`[syntect.syntaxes]` and `[syntect.themes]` sections). -pub mod syntect; /// Frontend configuration (`[frontend]` section). #[cfg(feature = "frontend")] pub mod frontend; -use crate::index::Index; -use crate::storage::Storage; +use alexandrie_index::Index; +use alexandrie_storage::Storage; + +use alexandrie_index::config::IndexConfig; +use alexandrie_rendering::config::{SyntectConfig, SyntectState}; +use alexandrie_storage::config::StorageConfig; + use crate::Repo; use crate::config::database::DatabaseConfig; -use crate::config::index::IndexConfig; -use crate::config::storage::StorageConfig; -use crate::config::syntect::{SyntectConfig, SyntectState}; #[cfg(feature = "frontend")] pub use crate::config::frontend::*; diff --git a/src/db/mod.rs b/alexandrie/src/db/mod.rs similarity index 100% rename from src/db/mod.rs rename to alexandrie/src/db/mod.rs diff --git a/src/db/models.rs b/alexandrie/src/db/models.rs similarity index 100% rename from src/db/models.rs rename to alexandrie/src/db/models.rs diff --git a/src/db/schema.rs b/alexandrie/src/db/schema.rs similarity index 100% rename from src/db/schema.rs rename to alexandrie/src/db/schema.rs diff --git a/src/error.rs b/alexandrie/src/error.rs similarity index 95% rename from src/error.rs rename to alexandrie/src/error.rs index da61b702..9c71a55d 100644 --- a/src/error.rs +++ b/alexandrie/src/error.rs @@ -14,6 +14,9 @@ use git2::Error as Git2Error; use tide::{IntoResponse, Response}; +use alexandrie_index::error::Error as IndexError; +use alexandrie_storage::error::Error as StorageError; + use crate::db::models::Author; use crate::utils; @@ -43,6 +46,12 @@ pub enum Error { /// Alexandrie's custom errors (crate not found, invalid token, etc...). #[error("alexandrie error: {0}")] AlexError(#[source] AlexError), + /// Index-specific errors. + #[error("{0}")] + IndexError(#[from] IndexError), + /// Storage-specific errors. + #[error("{0}")] + StorageError(#[from] StorageError), /// Git2 error. #[error("libgit2 error: {0}")] #[cfg(feature = "git2")] diff --git a/src/frontend/account/login.rs b/alexandrie/src/frontend/account/login.rs similarity index 100% rename from src/frontend/account/login.rs rename to alexandrie/src/frontend/account/login.rs diff --git a/src/frontend/account/logout.rs b/alexandrie/src/frontend/account/logout.rs similarity index 100% rename from src/frontend/account/logout.rs rename to alexandrie/src/frontend/account/logout.rs diff --git a/src/frontend/account/manage/mod.rs b/alexandrie/src/frontend/account/manage/mod.rs similarity index 100% rename from src/frontend/account/manage/mod.rs rename to alexandrie/src/frontend/account/manage/mod.rs diff --git a/src/frontend/account/manage/passwd.rs b/alexandrie/src/frontend/account/manage/passwd.rs similarity index 100% rename from src/frontend/account/manage/passwd.rs rename to alexandrie/src/frontend/account/manage/passwd.rs diff --git a/src/frontend/account/manage/tokens/mod.rs b/alexandrie/src/frontend/account/manage/tokens/mod.rs similarity index 100% rename from src/frontend/account/manage/tokens/mod.rs rename to alexandrie/src/frontend/account/manage/tokens/mod.rs diff --git a/src/frontend/account/manage/tokens/revoke.rs b/alexandrie/src/frontend/account/manage/tokens/revoke.rs similarity index 100% rename from src/frontend/account/manage/tokens/revoke.rs rename to alexandrie/src/frontend/account/manage/tokens/revoke.rs diff --git a/src/frontend/account/mod.rs b/alexandrie/src/frontend/account/mod.rs similarity index 100% rename from src/frontend/account/mod.rs rename to alexandrie/src/frontend/account/mod.rs diff --git a/src/frontend/account/register.rs b/alexandrie/src/frontend/account/register.rs similarity index 100% rename from src/frontend/account/register.rs rename to alexandrie/src/frontend/account/register.rs diff --git a/src/frontend/helpers.rs b/alexandrie/src/frontend/helpers.rs similarity index 100% rename from src/frontend/helpers.rs rename to alexandrie/src/frontend/helpers.rs diff --git a/src/frontend/index.rs b/alexandrie/src/frontend/index.rs similarity index 100% rename from src/frontend/index.rs rename to alexandrie/src/frontend/index.rs diff --git a/src/frontend/krate.rs b/alexandrie/src/frontend/krate.rs similarity index 99% rename from src/frontend/krate.rs rename to alexandrie/src/frontend/krate.rs index bdeb089f..252d9b2a 100644 --- a/src/frontend/krate.rs +++ b/alexandrie/src/frontend/krate.rs @@ -3,13 +3,14 @@ use json::json; use serde::{Deserialize, Serialize}; use tide::{Request, Response}; +use alexandrie_index::Indexer; +use alexandrie_storage::Store; + use crate::db::models::{Badge, Crate, CrateAuthor, CrateCategory, CrateKeyword, Keyword}; use crate::db::schema::*; use crate::db::DATETIME_FORMAT; use crate::error::Error; use crate::frontend::helpers; -use crate::index::Indexer; -use crate::storage::Store; use crate::utils; use crate::utils::auth::AuthExt; use crate::State; diff --git a/src/frontend/last_updated.rs b/alexandrie/src/frontend/last_updated.rs similarity index 99% rename from src/frontend/last_updated.rs rename to alexandrie/src/frontend/last_updated.rs index b4d30975..d072af6d 100644 --- a/src/frontend/last_updated.rs +++ b/alexandrie/src/frontend/last_updated.rs @@ -6,12 +6,13 @@ use json::json; use serde::{Deserialize, Serialize}; use tide::{Request, Response}; +use alexandrie_index::Indexer; + use crate::db::models::Crate; use crate::db::schema::*; use crate::db::DATETIME_FORMAT; use crate::error::Error; use crate::frontend::helpers; -use crate::index::Indexer; use crate::utils; use crate::utils::auth::AuthExt; use crate::State; diff --git a/src/frontend/me.rs b/alexandrie/src/frontend/me.rs similarity index 100% rename from src/frontend/me.rs rename to alexandrie/src/frontend/me.rs diff --git a/src/frontend/mod.rs b/alexandrie/src/frontend/mod.rs similarity index 100% rename from src/frontend/mod.rs rename to alexandrie/src/frontend/mod.rs diff --git a/src/frontend/most_downloaded.rs b/alexandrie/src/frontend/most_downloaded.rs similarity index 99% rename from src/frontend/most_downloaded.rs rename to alexandrie/src/frontend/most_downloaded.rs index f285b175..9fcd1c19 100644 --- a/src/frontend/most_downloaded.rs +++ b/alexandrie/src/frontend/most_downloaded.rs @@ -6,12 +6,13 @@ use json::json; use serde::{Deserialize, Serialize}; use tide::{Request, Response}; +use alexandrie_index::Indexer; + use crate::db::models::Crate; use crate::db::schema::*; use crate::db::DATETIME_FORMAT; use crate::error::Error; use crate::frontend::helpers; -use crate::index::Indexer; use crate::utils; use crate::utils::auth::AuthExt; use crate::State; diff --git a/src/frontend/search.rs b/alexandrie/src/frontend/search.rs similarity index 99% rename from src/frontend/search.rs rename to alexandrie/src/frontend/search.rs index 61901ff3..7dd89e63 100644 --- a/src/frontend/search.rs +++ b/alexandrie/src/frontend/search.rs @@ -6,12 +6,13 @@ use json::json; use serde::{Deserialize, Serialize}; use tide::{Request, Response}; +use alexandrie_index::Indexer; + use crate::db::models::Crate; use crate::db::schema::*; use crate::db::DATETIME_FORMAT; use crate::error::Error; use crate::frontend::helpers; -use crate::index::Indexer; use crate::utils; use crate::utils::auth::AuthExt; use crate::State; diff --git a/src/logs.rs b/alexandrie/src/logs.rs similarity index 100% rename from src/logs.rs rename to alexandrie/src/logs.rs diff --git a/src/main.rs b/alexandrie/src/main.rs similarity index 97% rename from src/main.rs rename to alexandrie/src/main.rs index dcf4c7a3..52d1ecdd 100644 --- a/src/main.rs +++ b/alexandrie/src/main.rs @@ -49,12 +49,8 @@ pub mod config; pub mod db; /// Error-related type definitions. pub mod error; -/// Crate index management strategies. -pub mod index; /// Logs initialisation. pub mod logs; -/// Crate storage strategies. -pub mod storage; /// Various utilities and helpers. pub mod utils; @@ -80,11 +76,11 @@ pub type Repo = db::Repo; pub type State = Arc; #[cfg(feature = "mysql")] -embed_migrations!("migrations/mysql"); +embed_migrations!("../migrations/mysql"); #[cfg(feature = "sqlite")] -embed_migrations!("migrations/sqlite"); +embed_migrations!("../migrations/sqlite"); #[cfg(feature = "postgres")] -embed_migrations!("migrations/postgres"); +embed_migrations!("../migrations/postgres"); use futures::future::{BoxFuture, FutureExt}; use std::future::Future; diff --git a/src/utils/auth.rs b/alexandrie/src/utils/auth.rs similarity index 100% rename from src/utils/auth.rs rename to alexandrie/src/utils/auth.rs diff --git a/src/utils/checks.rs b/alexandrie/src/utils/checks.rs similarity index 100% rename from src/utils/checks.rs rename to alexandrie/src/utils/checks.rs diff --git a/src/utils/cookies.rs b/alexandrie/src/utils/cookies.rs similarity index 100% rename from src/utils/cookies.rs rename to alexandrie/src/utils/cookies.rs diff --git a/src/utils/flash.rs b/alexandrie/src/utils/flash.rs similarity index 100% rename from src/utils/flash.rs rename to alexandrie/src/utils/flash.rs diff --git a/src/utils/mod.rs b/alexandrie/src/utils/mod.rs similarity index 87% rename from src/utils/mod.rs rename to alexandrie/src/utils/mod.rs index 2bab3f73..f7bbe91a 100644 --- a/src/utils/mod.rs +++ b/alexandrie/src/utils/mod.rs @@ -1,7 +1,5 @@ /// Various utilities to check for common properties. pub mod checks; -/// Various utilities to assist Markdown rendering to HTML. -pub mod rendering; /// Utilities to issue logs about requests. pub mod request_log; /// Various utilities to assist building HTTP responses. diff --git a/src/utils/request_log.rs b/alexandrie/src/utils/request_log.rs similarity index 100% rename from src/utils/request_log.rs rename to alexandrie/src/utils/request_log.rs diff --git a/src/utils/response/common.rs b/alexandrie/src/utils/response/common.rs similarity index 100% rename from src/utils/response/common.rs rename to alexandrie/src/utils/response/common.rs diff --git a/src/utils/response/mod.rs b/alexandrie/src/utils/response/mod.rs similarity index 100% rename from src/utils/response/mod.rs rename to alexandrie/src/utils/response/mod.rs diff --git a/src/utils/static_files.rs b/alexandrie/src/utils/static_files.rs similarity index 100% rename from src/utils/static_files.rs rename to alexandrie/src/utils/static_files.rs