From a42853ac5a87daa739e03519f314db4e135c8c4d Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 12:05:43 -0800 Subject: [PATCH 1/8] score, initialize core functionality and types Adds Chrono package Adds a "Result" type to lib.rs creates helpful type aliases for Score, Boost, and Gravity. Creates a "TimedScore" which is a value and time data for calculating score over time. There are two forms of this, Boosted and Decaying. Since a Score can either be decaying over time or have been boosted recently and be kept from decaying for some time. Also implements a BoostedScore and a DecayingScore, which are both TimedScores which represent the different states. These are important because you can't boost a BoostedScore for instance. --- koucha/Cargo.lock | 507 ++++++++++++++++++++++++++++++++++++++++++++ koucha/Cargo.toml | 2 + koucha/src/lib.rs | 5 + koucha/src/score.rs | 193 +++++++++++++++++ 4 files changed, 707 insertions(+) create mode 100644 koucha/src/score.rs diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index 476c80f..cfc34e4 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -2,6 +2,513 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + +[[package]] +name = "bumpalo" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "js-sys" +version = "0.3.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "koucha" version = "0.1.0" +dependencies = [ + "chrono", + "tokio", +] + +[[package]] +name = "libc" +version = "0.2.180" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "syn" +version = "2.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index b58c658..fbf4602 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -4,3 +4,5 @@ version = "0.1.0" edition = "2024" [dependencies] +tokio = { version = "1.49.0", features = ["full"] } +chrono = "0.4.43" diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index e69de29..ceed6cb 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -0,0 +1,5 @@ +use std::error::Error; + +type Result = std::result::Result>; + +pub mod score; diff --git a/koucha/src/score.rs b/koucha/src/score.rs new file mode 100644 index 0000000..8b27b09 --- /dev/null +++ b/koucha/src/score.rs @@ -0,0 +1,193 @@ +use chrono::{DateTime, Utc, TimeDelta}; +use crate::{Result}; +use std::ops::{Add, Sub}; + +mod default { + use crate::score::SECONDS_IN_A_DAY; + + pub const INITIAL_SCORE: i64 = 70; + pub const GRAVITY: i64 = -10; + pub const BOOST: i64 = 12; + pub const BOOST_FREEZE_IN_SECONDS: i64 = SECONDS_IN_A_DAY; +} +const SECONDS_IN_A_DAY: i64 = 60 * 60 * 24; + +macro_rules! rich_i64 { + ($name:ident) => { + #[derive(PartialOrd, PartialEq, Debug, Copy, Clone)] + pub struct $name(i64); + impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } + }; +} + +macro_rules! defaulting_i64 { + ($name:ident, $default:expr) => { + rich_i64!($name); + impl $name { + pub fn new(value: Option) -> Self { + Self(value.unwrap_or($default)) + } + } + }; +} + +macro_rules! addable_i64s { + ($lhs:ident, $rhs:ident) => { + impl Add<$rhs> for $lhs { + type Output = Self; + fn add(self, other: $rhs) -> Self::Output { Self(self.0 + other.0) } + } + } +} + +defaulting_i64!(Score, default::INITIAL_SCORE); +addable_i64s!(Score, Score); +addable_i64s!(Score, Boost); +impl Sub for Score { + type Output = Self; + fn sub(self, other: Boost) -> Self::Output { Self(self.0 - other.0) } +} +addable_i64s!(Score, GravityOverDuration); +defaulting_i64!(Boost, default::BOOST); +defaulting_i64!(Gravity, default::GRAVITY); +rich_i64!(GravityOverDuration); +impl Gravity { + fn over_duration( + &self, start: DateTime, end: DateTime + ) -> GravityOverDuration { + let elapsed_time = end.signed_duration_since(start); + GravityOverDuration( + self.0 * (elapsed_time.num_seconds() / SECONDS_IN_A_DAY) + ) + } +} + +#[derive(Clone)] +pub enum TimedScore { + Decaying(DecayingScore), + Boosted(BoostedScore), +} + +impl TimedScore { + pub fn new() -> DecayingScore { + Self::new_with_initial(Score::new(None)) + } + + pub fn new_with_initial(initial_score: Score) -> DecayingScore { + Self::new_with_initial_and_time(initial_score, Utc::now()) + } + + pub fn new_with_initial_and_time( + initial: Score, time: DateTime + ) -> DecayingScore { + DecayingScore { + value: initial, + last_updated: time, + } + } + + pub fn get_score(&self) -> Score { + match self { + Self::Decaying(s) => s.get_score(), + Self::Boosted(b) => b.get_score(), + } + } + + pub fn update_score(self, gravity: Gravity) -> Self { + self.update_score_at_time(gravity, Utc::now()) + } + + fn update_score_at_time(self, gravity: Gravity, time: DateTime) -> Self { + match self { + Self::Decaying(d) => TimedScore::Decaying( + d.apply_gravity_to_time(gravity, time) + ), + Self::Boosted(b) => { + let try_unfrozen = b.try_unfreeze_at_time(time); + match try_unfrozen { + Self::Decaying(s) => TimedScore::Decaying( + s.apply_gravity_to_time(gravity, time) + ), + Self::Boosted(b) => TimedScore::Boosted(b), + } + } + } + } + + pub fn get_decaying(self) -> Result { + match self { + Self::Decaying(s) => Ok(s), + Self::Boosted(_) => Err("Attempted to get_decaying() of a boosted score".into()), + } + } + + pub fn get_boosted(self) -> Result { + match self { + Self::Decaying(_) => Err("Attempted to get_boosted() of a decaying score".into()), + Self::Boosted(b) => Ok(b), + } + } +} + +#[derive(Clone)] +pub struct BoostedScore { + value: Score, + boosted_at: DateTime, +} + +#[derive(Clone)] +pub struct DecayingScore { + value: Score, + last_updated: DateTime, +} + +impl DecayingScore { + fn get_score(&self) -> Score { + self.value + } + + fn apply_gravity_to_time( + self, gravity: Gravity, update_time: DateTime + ) -> Self { + Self { + last_updated: update_time, + value: self.value + gravity.over_duration(self.last_updated, update_time), + } + } + + pub fn boost(self, boost: Boost) -> BoostedScore { + self.boost_at_time(boost, Utc::now()) + } + + fn boost_at_time(self, boost: Boost, boost_time: DateTime) -> BoostedScore { + BoostedScore { + value: self.value + boost, + boosted_at: boost_time, + } + } +} + +impl BoostedScore { + fn get_score(&self) -> Score { + self.value + } + + pub fn unboost(self, boost: Boost) -> DecayingScore { + DecayingScore { + value: self.value - boost, + last_updated: self.boosted_at, + } + } + + fn try_unfreeze_at_time(self, update_time: DateTime) -> TimedScore { + let boost_end = self.boosted_at + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + if boost_end < update_time { + TimedScore::Decaying(DecayingScore { + value: self.value, + last_updated: boost_end, + }) + } else { + TimedScore::Boosted(self) + } + } +} -- 2.52.0 From dac085756af6b7123d1fc6d52d1b84549b7ea5c7 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 12:23:27 -0800 Subject: [PATCH 2/8] db&adapter, add sqlx + schema & add adapter Adds SQLX for database management, and an Adapter interface for interacting with it. Through the type "AdapterPool" Creates an initial_schema with everything I think I'll need. --- flake.lock | 8 +- flake.nix | 4 +- koucha/.gitignore | 1 + koucha/Cargo.lock | 1419 ++++++++++++++++- koucha/Cargo.toml | 1 + .../20260115003047_initial_schema.sql | 62 + koucha/src/lib.rs | 33 + 7 files changed, 1514 insertions(+), 14 deletions(-) create mode 100644 koucha/migrations/20260115003047_initial_schema.sql diff --git a/flake.lock b/flake.lock index 2972d8a..c4fa525 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,16 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1768127708, - "narHash": "sha256-1Sm77VfZh3mU0F5OqKABNLWxOuDeHIlcFjsXeeiPazs=", + "lastModified": 1769933782, + "narHash": "sha256-GlZemJ2dxhXMMq6TNyt588OFv4/jIt3J1QVBO9MspBE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ffbc9f8cbaacfb331b6017d5a5abb21a492c9a38", + "rev": "64728753f1a42c81c5688a136a6bee173665acc9", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "nixos-25.11-small", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index c3fa77f..f48d72e 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Koucha rust flake"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11-small"; }; outputs = { self, nixpkgs }: @@ -24,6 +24,8 @@ rustc cargo rust-analyzer + + sqlx-cli ]; RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; diff --git a/koucha/.gitignore b/koucha/.gitignore index ea8c4bf..6dfb7e0 100644 --- a/koucha/.gitignore +++ b/koucha/.gitignore @@ -1 +1,2 @@ +*.db /target diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index cfc34e4..ff859af 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -11,17 +17,50 @@ dependencies = [ "libc", ] +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + [[package]] name = "autocfg" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + [[package]] name = "bitflags" version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +dependencies = [ + "serde_core", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] [[package]] name = "bumpalo" @@ -29,6 +68,12 @@ version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.11.1" @@ -64,12 +109,131 @@ dependencies = [ "windows-link", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "errno" version = "0.3.14" @@ -80,12 +244,218 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + [[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "iana-time-zone" version = "0.1.65" @@ -110,6 +480,124 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + [[package]] name = "js-sys" version = "0.3.85" @@ -125,15 +613,59 @@ name = "koucha" version = "0.1.0" dependencies = [ "chrono", + "sqlx", "tokio", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + [[package]] name = "libc" version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + +[[package]] +name = "libredox" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +dependencies = [ + "bitflags", + "libc", + "redox_syscall 0.7.0", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + [[package]] name = "lock_api" version = "0.4.14" @@ -149,6 +681,22 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + [[package]] name = "mio" version = "1.1.1" @@ -160,6 +708,42 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -167,6 +751,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -175,6 +760,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.5" @@ -193,17 +784,83 @@ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.18", "smallvec", "windows-link", ] +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + [[package]] name = "pin-project-lite" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -222,6 +879,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.5.18" @@ -231,18 +918,130 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rsa" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rustversion" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" +[[package]] +name = "ryu" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shlex" version = "1.3.0" @@ -259,11 +1058,30 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] [[package]] name = "socket2" @@ -275,6 +1093,236 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "bytes", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64", + "bitflags", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror", + "tracing", + "url", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.114" @@ -286,6 +1334,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.49.0" @@ -314,18 +1418,124 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + [[package]] name = "unicode-ident" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.108" @@ -371,6 +1581,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + [[package]] name = "windows-core" version = "0.62.2" @@ -430,13 +1650,22 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets", + "windows-targets 0.53.5", ] [[package]] @@ -448,6 +1677,21 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + [[package]] name = "windows-targets" version = "0.53.5" @@ -455,28 +1699,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ "windows-link", - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.53.1" @@ -489,26 +1751,165 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57cf3aa6855b23711ee9852dfc97dfaa51c45feaba5b645d0c777414d494a961" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a616990af1a287837c4fe6596ad77ef57948f787e46ce28e166facc0cc1cb75" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff05f8caa9038894637571ae6b9e29466c1f4f829d26c9b28f869a29cbe3445" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index fbf4602..3da8f35 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -5,4 +5,5 @@ edition = "2024" [dependencies] tokio = { version = "1.49.0", features = ["full"] } +sqlx = { version = "0.8.6", features = [ "runtime-tokio", "sqlite" ] } chrono = "0.4.43" diff --git a/koucha/migrations/20260115003047_initial_schema.sql b/koucha/migrations/20260115003047_initial_schema.sql new file mode 100644 index 0000000..b863eee --- /dev/null +++ b/koucha/migrations/20260115003047_initial_schema.sql @@ -0,0 +1,62 @@ +-- Add migration script here + +PRAGMA foreign_keys = ON; + +CREATE TABLE users ( + id INTEGER PRIMARY KEY, + name TEXT UNIQUE NOT NULL +); + +CREATE TABLE channels ( + id INTEGER PRIMARY KEY, + title TEXT NOT NULL, + link TEXT UNIQUE NOT NULL, + description TEXT, + last_fetched TEXT +); + +CREATE TABLE items ( + id INTEGER PRIMARY KEY, + channel_id INTEGER NOT NULL, + guid TEXT NOT NULL, + + fetched_at TEXT, + title TEXT, + description TEXT, + content TEXT, + + UNIQUE(channel_id, guid), + FOREIGN KEY (channel_id) REFERENCES channels(id) +); + +CREATE TABLE feeds ( + id INTEGER PRIMARY KEY, + user_id INTEGER NOT NULL, + title TEXT NOT NULL, + FOREIGN KEY (user_id) REFERENCES users(id) +); + +CREATE TABLE feed_channels ( + feed_id INTEGER NOT NULL, + channel_id INTEGER NOT NULL, + initial_score INTEGER, + gravity INTEGER, + boost INTEGER, + PRIMARY KEY (feed_id, channel_id), + FOREIGN KEY (feed_id) REFERENCES feeds(id), + FOREIGN KEY (channel_id) REFERENCES channels(id) +); + +CREATE TABLE feed_items ( + item_id INTEGER NOT NULL, + feed_id INTEGER NOT NULL, + score INTEGER NOT NULL, + last_updated TEXT NOT NULL, + boosted_at TEXT, + archived BOOLEAN DEFAULT FALSE, + PRIMARY KEY (item_id, feed_id), + FOREIGN KEY (feed_id) REFERENCES feeds(id), + FOREIGN KEY (item_id) REFERENCES items(id) +); +CREATE INDEX idx_feed_items_score +ON feed_items(feed_id, archived, score DESC); diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index ceed6cb..b0aef7d 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -3,3 +3,36 @@ use std::error::Error; type Result = std::result::Result>; pub mod score; +pub struct AdapterPool(sqlx::SqlitePool); +pub struct AdapterBuilder { + database_url: String, +} + +impl AdapterBuilder { + pub fn new() -> Self { + Self { + database_url: "sqlite:test.db".to_string(), + } + } + + pub fn database_url(mut self, url: &str) -> Self { + self.database_url = url.to_string(); + self + } + + pub async fn create(self) -> Result { + let db = sqlx::sqlite::SqlitePoolOptions::new() + .connect(&self.database_url).await?; + sqlx::migrate!().run(&db).await?; + + Ok(Adapter { db: AdapterPool(db) }) + } +} + +pub struct Adapter { + db: AdapterPool, +} + +impl Adapter { + pub fn get_pool(&self) -> &AdapterPool { &self.db } +} -- 2.52.0 From b30eefd51615034863f6507420e3d0cba48f554d Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 12:36:28 -0800 Subject: [PATCH 3/8] score&test, Tests for a42853a & test_utils mod Tests for all the core functionality implemented to score in a42853a. Optimistically adding a test_utils mod for shared test code --- koucha/src/lib.rs | 4 + koucha/src/score.rs | 196 +++++++++++++++++++++++++++++++++++++++ koucha/src/test_utils.rs | 11 +++ 3 files changed, 211 insertions(+) create mode 100644 koucha/src/test_utils.rs diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index b0aef7d..3bf607b 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -3,6 +3,10 @@ use std::error::Error; type Result = std::result::Result>; pub mod score; + +#[cfg(test)] +pub mod test_utils; + pub struct AdapterPool(sqlx::SqlitePool); pub struct AdapterBuilder { database_url: String, diff --git a/koucha/src/score.rs b/koucha/src/score.rs index 8b27b09..e289c6e 100644 --- a/koucha/src/score.rs +++ b/koucha/src/score.rs @@ -191,3 +191,199 @@ impl BoostedScore { } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::get_datetime; + + #[test] + fn gravity_default() { + let gravity = Gravity::new(None); + assert_eq!(i64::from(gravity), default::GRAVITY); + } + + #[test] + fn boost_default() { + let boost = Boost::new(None); + assert_eq!(i64::from(boost), default::BOOST); + } + + // "Score" Tests + + #[test] + fn new() { + let score = TimedScore::new(); + assert_eq!(score.value, Score(default::INITIAL_SCORE)); + } + + #[test] + fn new_with_values() { + let dt = get_datetime(); + let score = TimedScore::new_with_initial_and_time(Score(10), dt); + assert_eq!(score.value, Score(10)); + assert_eq!(score.last_updated, dt); + } + + #[test] + fn update_score_stays_decaying() { + let dt = get_datetime(); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds(SECONDS_IN_A_DAY); + + score.update_score_at_time(gravity, dt2).get_decaying().unwrap(); + } + + #[test] + fn update_score_stays_frozen() { + let dt = get_datetime(); + let score = TimedScore::Boosted( + BoostedScore { value: Score(10), boosted_at: dt } + ); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + + score.update_score_at_time(gravity, dt2).get_boosted().unwrap(); + } + + #[test] + fn update_score_thaws_and_decays() { + let dt = get_datetime(); + let score = TimedScore::Boosted( + BoostedScore { value: Score(10), boosted_at: dt } + ); + let gravity = Gravity::new(None); + + let dt2 = dt + TimeDelta::seconds( + default::BOOST_FREEZE_IN_SECONDS + SECONDS_IN_A_DAY + ); + + let updated = score.update_score_at_time(gravity, dt2) + .get_decaying().unwrap(); + assert!(updated.value < Score(10)) + } + + #[test] + fn get_decaying_success() { + let dt = get_datetime(); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); + + score.get_decaying().unwrap(); + } + + #[test] + #[should_panic = "Attempted to get_boosted() of a decaying score"] + fn get_boosted_failure() { + let dt = get_datetime(); + let score = TimedScore::Decaying( + TimedScore::new_with_initial_and_time(Score(10), dt) + ); + + score.get_boosted().unwrap(); + } + + #[test] + #[should_panic = "Attempted to get_decaying() of a boosted score"] + fn get_decaying_failure() { + let dt = get_datetime(); + let boost = Boost::new(None); + let score = TimedScore::Boosted( + TimedScore::new_with_initial_and_time(Score(10), dt) + .boost_at_time(boost, dt) + ); + + score.get_decaying().unwrap(); + } + + #[test] + fn get_boosted_success() { + let dt = get_datetime(); + let boost = Boost::new(None); + let score = TimedScore::Boosted( + TimedScore::new_with_initial_and_time(Score(10), dt) + .boost_at_time(boost, dt) + ); + + score.get_boosted().unwrap(); + } + + // "DecayingScore" Tests + + #[test] + fn apply_gravity_to_future() { + let dt = get_datetime(); + let score = DecayingScore { value: Score(10), last_updated: dt }; + let future = dt + TimeDelta::seconds(SECONDS_IN_A_DAY); + let gravity = Gravity::new(None); + + let updated = score.apply_gravity_to_time(gravity, future); + + assert!(updated.value < Score(10)); + assert_eq!(updated.last_updated, future); + } + + #[test] + fn apply_gravity_to_past() { + let dt = get_datetime(); + let score = DecayingScore { value: Score(10), last_updated: dt }; + let past = dt - TimeDelta::seconds(SECONDS_IN_A_DAY); + let gravity = Gravity::new(None); + + let updated = score.apply_gravity_to_time(gravity, past); + + assert!(updated.value > Score(10)); + assert_eq!(updated.last_updated, past); + } + + #[test] + fn boost() { + let dt = get_datetime(); + let score = DecayingScore { value: Score(10), last_updated: dt }; + let boost = Boost::new(None); + + let boosted = score.boost_at_time(boost, dt); + assert_eq!(boosted.value, Score(10) + Boost(default::BOOST)); + assert_eq!(boosted.boosted_at, dt); + } + + // "BoostedScore" tests + + #[test] + fn unboost() { + let dt = get_datetime(); + let score = DecayingScore { value: Score(10), last_updated: dt }; + let boost = Boost::new(None); + let boosted = score.boost_at_time(boost, dt); + + let unboosted = boosted.unboost(boost); + assert_eq!(unboosted.value, Score(10)); + assert_eq!(unboosted.last_updated, dt); + } + + #[test] + fn boosted_stays_frozen() { + let dt = get_datetime(); + let score = BoostedScore { value: Score(10), boosted_at: dt }; + + let last_second = dt + TimeDelta::seconds(default::BOOST_FREEZE_IN_SECONDS); + + score.try_unfreeze_at_time(last_second).get_boosted().unwrap(); + } + + #[test] + fn boosted_thaws() { + let dt = get_datetime(); + let score = BoostedScore { value: Score(10), boosted_at: dt }; + + let first_second = dt + TimeDelta::days(default::BOOST_FREEZE_IN_SECONDS+1); + + score.try_unfreeze_at_time(first_second).get_decaying().unwrap(); + } +} diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs new file mode 100644 index 0000000..6492538 --- /dev/null +++ b/koucha/src/test_utils.rs @@ -0,0 +1,11 @@ +#![cfg(test)] + +use chrono::{ + Utc, + TimeZone, + DateTime +}; + +pub fn get_datetime() -> DateTime { + Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() +} -- 2.52.0 From 99321e9a5d6a21fb06c122ba22d315915b81aa45 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 13:10:21 -0800 Subject: [PATCH 4/8] db, add core user functionality and tests; db mod Adds all the basic user functions, and tests for them. This is also intializes the DB Module, which will have more things in it --- koucha/src/db.rs | 11 +++ koucha/src/db/user.rs | 160 +++++++++++++++++++++++++++++++++++++++ koucha/src/lib.rs | 1 + koucha/src/test_utils.rs | 13 ++++ 4 files changed, 185 insertions(+) create mode 100644 koucha/src/db.rs create mode 100644 koucha/src/db/user.rs diff --git a/koucha/src/db.rs b/koucha/src/db.rs new file mode 100644 index 0000000..a19ee4a --- /dev/null +++ b/koucha/src/db.rs @@ -0,0 +1,11 @@ +mod user; +pub use user::User; + +macro_rules! define_key { + ($name:ident) => { + #[derive(PartialEq, Debug, Copy, Clone)] + pub struct $name(i64); + }; +} + +define_key!(UserKey); diff --git a/koucha/src/db/user.rs b/koucha/src/db/user.rs new file mode 100644 index 0000000..f42491b --- /dev/null +++ b/koucha/src/db/user.rs @@ -0,0 +1,160 @@ +use crate::{ + Result, + AdapterPool, + db::UserKey, +}; + +pub struct UnparsedUser { + pub id: i64, + pub name: String, +} +impl UnparsedUser { + pub fn parse(self) -> Result { + Ok(User { + key: UserKey(self.id), + name: self.name + }) + } +} + +pub struct User { + key: UserKey, + name: String, +} + +impl User { + pub fn key(&self) -> UserKey { self.key } + pub fn name(&self) -> &str { &self.name } + + pub async fn get(pool: &AdapterPool, key: UserKey) -> Result { + sqlx::query_as!( + UnparsedUser, + "SELECT id, name FROM users WHERE id = ?", + key.0 + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn get_all(pool: &AdapterPool) -> Result> { + sqlx::query_as!( + UnparsedUser, + "SELECT id, name FROM users" + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedUser::parse).collect() + } + + pub async fn create(pool: &AdapterPool, name: &str) -> Result { + sqlx::query_as!( + UnparsedUser, + "INSERT INTO users (name) + VALUES (?) + RETURNING id, name", + name + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn update_name( + pool: &AdapterPool, key: UserKey, new_name: &str + ) -> Result<()> { + sqlx::query!( + "UPDATE users SET name = ? WHERE id = ?", + new_name, key.0 + ).execute(&pool.0).await?; + + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + test_utils::{ + USERNAME, USERNAME2, + setup_adapter, + }, + }; + + #[test] + fn parse() { + const UID: i64 = 1; + let unparsed_user = UnparsedUser { + id: UID, + name: USERNAME.to_string(), + }; + + let user = unparsed_user.parse().unwrap(); + assert_eq!(user.key.0, UID); + assert_eq!(user.name, USERNAME); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let new_user = User::create(pool, USERNAME).await.unwrap(); + + let fetched_user = User::get(pool, new_user.key).await.unwrap(); + assert_eq!(fetched_user.name, USERNAME); + assert_eq!(fetched_user.key.0, 1); + } + + #[tokio::test] + async fn get_all() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + User::create(pool, USERNAME).await.unwrap(); + User::create(pool, USERNAME2).await.unwrap(); + + let users = User::get_all(pool).await.unwrap(); + assert_eq!(users.len(), 2); + assert!(users.iter().any(|u| u.name == USERNAME)); + assert!(users.iter().any(|u| u.name == USERNAME2)); + } + + #[tokio::test] + async fn create_user() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, USERNAME).await.unwrap(); + + assert_eq!(user.name, USERNAME); + assert_eq!(user.key.0, 1); + } + + #[tokio::test] + async fn create_duplicate_user() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + User::create(pool, USERNAME).await.unwrap(); + let duplicate_user = User::create(pool, USERNAME).await; + + assert!(duplicate_user.is_err()); + } + + #[tokio::test] + async fn update_name() { + const NEW_USERNAME: &str = "Alicia"; + assert!(NEW_USERNAME != USERNAME); + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, USERNAME).await.unwrap(); + User::update_name(pool, user.key, NEW_USERNAME).await.unwrap(); + + let updated = User::get(pool, user.key).await.unwrap(); + assert_eq!(updated.name, NEW_USERNAME); + } + + #[tokio::test] + async fn update_name_to_duplicate() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user1 = User::create(pool, USERNAME).await.unwrap(); + User::create(pool, USERNAME2).await.unwrap(); + let status = User::update_name(pool, user1.key, USERNAME2).await; + + assert!(status.is_err()); + } +} diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 3bf607b..5982237 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -2,6 +2,7 @@ use std::error::Error; type Result = std::result::Result>; +pub mod db; pub mod score; #[cfg(test)] diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs index 6492538..7cd4601 100644 --- a/koucha/src/test_utils.rs +++ b/koucha/src/test_utils.rs @@ -1,11 +1,24 @@ #![cfg(test)] +use crate::{ + Adapter, + AdapterBuilder, +}; use chrono::{ Utc, TimeZone, DateTime }; +pub const USERNAME: &str = "Alice"; +pub const USERNAME2: &str = "Bob"; + pub fn get_datetime() -> DateTime { Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() } + +pub async fn setup_adapter() -> Adapter { + AdapterBuilder::new() + .database_url("sqlite::memory:") + .create().await.unwrap() +} -- 2.52.0 From 2dc4c7bc99e0ad066a48e1d486cd66f5f95c5092 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Thu, 5 Feb 2026 13:59:34 -0800 Subject: [PATCH 5/8] db, add channel and feed; user.get_feeds Adds the primary functionality for channel and feed Also adds a function to user to get the feeds associated with a user. --- koucha/Cargo.lock | 973 ++++++++++++++++++++++++++++++++++++++- koucha/Cargo.toml | 1 + koucha/src/db.rs | 6 + koucha/src/db/channel.rs | 179 +++++++ koucha/src/db/feed.rs | 191 ++++++++ koucha/src/db/user.rs | 44 +- koucha/src/test_utils.rs | 23 + 7 files changed, 1400 insertions(+), 17 deletions(-) create mode 100644 koucha/src/db/channel.rs create mode 100644 koucha/src/db/feed.rs diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index ff859af..4849805 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -26,12 +26,40 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "aws-lc-rs" +version = "1.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7b6141e96a8c160799cc2d5adecd5cbbe5054cb8c7c4af53da0f83bb7ad256" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c34dda4df7017c8db52132f0f8a2e0f8161649d15723ed63fc00c82d0f2081a" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", +] + [[package]] name = "base64" version = "0.22.1" @@ -87,15 +115,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29" dependencies = [ "find-msvc-tools", + "jobserver", + "libc", "shlex", ] +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.43" @@ -109,6 +151,25 @@ dependencies = [ "windows-link", ] +[[package]] +name = "cmake" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d" +dependencies = [ + "cc", +] + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -124,6 +185,26 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -219,6 +300,12 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "either" version = "1.15.0" @@ -228,6 +315,15 @@ dependencies = [ "serde", ] +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "equivalent" version = "1.0.2" @@ -283,6 +379,12 @@ dependencies = [ "spin", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foldhash" version = "0.1.5" @@ -298,6 +400,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures-channel" version = "0.3.31" @@ -387,8 +495,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", ] [[package]] @@ -456,6 +599,108 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "system-configuration", + "tokio", + "tower-service", + "tracing", + "windows-registry", +] + [[package]] name = "iana-time-zone" version = "0.1.65" @@ -592,12 +837,60 @@ dependencies = [ "hashbrown 0.16.1", ] +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "itoa" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + [[package]] name = "js-sys" version = "0.3.85" @@ -613,6 +906,7 @@ name = "koucha" version = "0.1.0" dependencies = [ "chrono", + "reqwest", "sqlx", "tokio", ] @@ -681,6 +975,12 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + [[package]] name = "md-5" version = "0.10.6" @@ -697,6 +997,12 @@ version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "mio" version = "1.1.1" @@ -719,7 +1025,7 @@ dependencies = [ "num-integer", "num-iter", "num-traits", - "rand", + "rand 0.8.5", "smallvec", "zeroize", ] @@ -760,6 +1066,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + [[package]] name = "parking" version = "2.2.1" @@ -870,6 +1182,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.18", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand 0.9.2", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.18", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + [[package]] name = "quote" version = "1.0.44" @@ -879,6 +1247,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "rand" version = "0.8.5" @@ -886,8 +1260,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", ] [[package]] @@ -897,7 +1281,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", ] [[package]] @@ -906,7 +1300,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", ] [[package]] @@ -927,6 +1330,58 @@ dependencies = [ "bitflags", ] +[[package]] +name = "reqwest" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e9018c9d814e5f30cc16a0f03271aeab3571e609612d9fe78c1aa8d11c2f62" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rsa" version = "0.9.10" @@ -940,13 +1395,94 @@ dependencies = [ "num-traits", "pkcs1", "pkcs8", - "rand_core", + "rand_core 0.6.4", "signature", "spki", "subtle", "zeroize", ] +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustls" +version = "0.23.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +dependencies = [ + "aws-lc-rs", + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.22" @@ -959,12 +1495,53 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" +dependencies = [ + "bitflags", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.228" @@ -1065,7 +1642,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -1152,7 +1729,7 @@ dependencies = [ "serde_json", "sha2", "smallvec", - "thiserror", + "thiserror 2.0.18", "tokio", "tokio-stream", "tracing", @@ -1226,7 +1803,7 @@ dependencies = [ "memchr", "once_cell", "percent-encoding", - "rand", + "rand 0.8.5", "rsa", "serde", "sha1", @@ -1234,7 +1811,7 @@ dependencies = [ "smallvec", "sqlx-core", "stringprep", - "thiserror", + "thiserror 2.0.18", "tracing", "whoami", ] @@ -1264,14 +1841,14 @@ dependencies = [ "md-5", "memchr", "once_cell", - "rand", + "rand 0.8.5", "serde", "serde_json", "sha2", "smallvec", "sqlx-core", "stringprep", - "thiserror", + "thiserror 2.0.18", "tracing", "whoami", ] @@ -1295,7 +1872,7 @@ dependencies = [ "serde", "serde_urlencoded", "sqlx-core", - "thiserror", + "thiserror 2.0.18", "tracing", "url", ] @@ -1334,6 +1911,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + [[package]] name = "synstructure" version = "0.13.2" @@ -1345,13 +1931,54 @@ dependencies = [ "syn", ] +[[package]] +name = "system-configuration" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + [[package]] name = "thiserror" version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1418,6 +2045,16 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.18" @@ -1429,6 +2066,64 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + [[package]] name = "tracing" version = "0.1.44" @@ -1461,6 +2156,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.19.0" @@ -1494,6 +2195,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.8" @@ -1524,12 +2231,40 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "wasite" version = "0.1.0" @@ -1549,6 +2284,20 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.108" @@ -1581,6 +2330,35 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "web-sys" +version = "0.3.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "804f18a4ac2676ffb4e8b5b5fa9ae38af06df08162314f96a68d2a363e21a8ca" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "whoami" version = "1.6.1" @@ -1591,6 +2369,15 @@ dependencies = [ "wasite", ] +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "windows-core" version = "0.62.2" @@ -1632,6 +2419,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + [[package]] name = "windows-result" version = "0.4.1" @@ -1650,6 +2448,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -1659,6 +2466,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.60.2" @@ -1677,6 +2493,21 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -1692,6 +2523,22 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + [[package]] name = "windows-targets" version = "0.53.5" @@ -1702,103 +2549,199 @@ dependencies = [ "windows_aarch64_gnullvm 0.53.1", "windows_aarch64_msvc 0.53.1", "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm", + "windows_i686_gnullvm 0.53.1", "windows_i686_msvc 0.53.1", "windows_x86_64_gnu 0.53.1", "windows_x86_64_gnullvm 0.53.1", "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_aarch64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + [[package]] name = "windows_i686_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_i686_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "windows_x86_64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" + [[package]] name = "writeable" version = "0.6.2" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index 3da8f35..7a97cef 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] +reqwest = "0.13.1" tokio = { version = "1.49.0", features = ["full"] } sqlx = { version = "0.8.6", features = [ "runtime-tokio", "sqlite" ] } chrono = "0.4.43" diff --git a/koucha/src/db.rs b/koucha/src/db.rs index a19ee4a..df11ecc 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -1,5 +1,9 @@ mod user; pub use user::User; +mod feed; +pub use feed::Feed; +mod channel; +pub use channel::Channel; macro_rules! define_key { ($name:ident) => { @@ -9,3 +13,5 @@ macro_rules! define_key { } define_key!(UserKey); +define_key!(FeedKey); +define_key!(ChannelKey); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs new file mode 100644 index 0000000..f8642f5 --- /dev/null +++ b/koucha/src/db/channel.rs @@ -0,0 +1,179 @@ +use reqwest::Url; +use chrono::{DateTime, Utc}; +use crate::{ + Result, + AdapterPool, + db::ChannelKey, +}; + +pub struct UnparsedChannel { + pub id: i64, + pub title: String, + pub link: String, + pub description: Option, + pub last_fetched: Option, +} +impl UnparsedChannel { + pub fn parse(self) -> Result { + Ok(Channel { + key: ChannelKey(self.id), + title: self.title, + link: Url::parse(&self.link)?, + description: self.description, + last_fetched: self.last_fetched.as_deref() + .map(DateTime::parse_from_rfc2822) + .transpose()? + .map(|dt| dt.with_timezone(&Utc)), + }) + } +} + +pub struct Channel { + key: ChannelKey, + title: String, + link: Url, + description: Option, + last_fetched: Option>, +} + +impl Channel { + pub fn key(&self) -> ChannelKey { self.key } + pub fn title(&self) -> &str { &self.title } + pub fn link(&self) -> &Url { &self.link } + pub fn description(&self) -> Option<&str> { self.description.as_deref() } + pub fn last_fetched(&self) -> Option> { self.last_fetched } + + pub async fn get_all(pool: &AdapterPool) -> Result> { + sqlx::query_as!( + UnparsedChannel, + "SELECT id, title, link, description, last_fetched FROM channels" + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedChannel::parse).collect() + } + + pub async fn get(pool: &AdapterPool, key: ChannelKey) -> Result { + sqlx::query_as!( + UnparsedChannel, + "SELECT id, title, link, description, last_fetched + FROM channels + WHERE id = ?", + key.0 + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn get_or_create( + pool: &AdapterPool, link: Url + ) -> Result { + let link_str = link.as_str(); + + sqlx::query_as!( + UnparsedChannel, + "INSERT INTO channels (title, link) + VALUES(?, ?) + ON CONFLICT(link) DO UPDATE SET link = link + RETURNING id, title, link, description, last_fetched", + link_str, link_str // We use the url as a placeholder title + ).fetch_one(&pool.0).await?.parse() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + test_utils::{ + FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, + setup_adapter, + setup_channel, + }, + }; + use chrono::TimeZone; + + #[test] + fn parse_unparsed_item() { + const CHANNEL_ID: i64 = 1; + let date: DateTime = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap(); + + let raw_channel = UnparsedChannel { + id: CHANNEL_ID, + title: CHANNEL_TITLE.to_string(), + link: FEED1.to_string(), + description: Some(CHANNEL_DESC.to_string()), + last_fetched: Some(date.to_rfc2822()), + }; + let channel = raw_channel.parse().unwrap(); + + assert_eq!(channel.key.0, CHANNEL_ID); + assert_eq!(channel.title, CHANNEL_TITLE); + assert_eq!(channel.link.as_str(), FEED1); + assert_eq!(channel.description, Some(CHANNEL_DESC.to_string())); + assert_eq!(channel.last_fetched, Some(date)); + } + + #[tokio::test] + async fn get_all() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url1 = Url::parse(FEED1).unwrap(); + let url2 = Url::parse(FEED2).unwrap(); + Channel::get_or_create(pool, url1).await.unwrap(); + Channel::get_or_create(pool, url2).await.unwrap(); + + let channels = Channel::get_all(pool).await.unwrap(); + assert_eq!(channels.len(), 2); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel_a = setup_channel(pool).await; + + let channel_b = Channel::get(pool, channel_a.key()).await.unwrap(); + + assert_eq!(channel_a.key, channel_b.key); + assert_eq!(channel_a.title, channel_b.title); + assert_eq!(channel_a.link, channel_b.link); + assert_eq!(channel_a.last_fetched, channel_b.last_fetched); + assert_eq!(channel_a.description, channel_b.description); + } + + #[tokio::test] + async fn create() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed = Url::parse(FEED1).unwrap(); + + let channel = Channel::get_or_create(pool, url_feed).await.unwrap(); + + assert!(channel.key().0 > 0); + assert_eq!(channel.link().as_str(), FEED1); + assert!(channel.title().len() > 0); + } + + #[tokio::test] + async fn create_duplicate_returns_existing() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed = Url::parse(FEED1).unwrap(); + + let channel1 = Channel::get_or_create(pool, url_feed.clone()).await.unwrap(); + let channel2 = Channel::get_or_create(pool, url_feed).await.unwrap(); + + assert_eq!(channel1.key(), channel2.key()); + } + + #[tokio::test] + async fn get_all_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let url_feed1 = Url::parse(FEED1).unwrap(); + let url_feed2 = Url::parse(FEED2).unwrap(); + + Channel::get_or_create(pool, url_feed1).await.unwrap(); + Channel::get_or_create(pool, url_feed2).await.unwrap(); + + let channels = Channel::get_all(pool).await.unwrap(); + + assert_eq!(channels.len(), 2); + } +} diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs new file mode 100644 index 0000000..da645e6 --- /dev/null +++ b/koucha/src/db/feed.rs @@ -0,0 +1,191 @@ +use crate::{ + AdapterPool, + Result, + db::{ + Channel, + ChannelKey, + FeedKey, + UserKey, + channel::UnparsedChannel, + }, +}; + +pub struct UnparsedFeed { + pub id: i64, + pub title: String, +} +impl UnparsedFeed { + pub fn parse(self) -> Result { + Ok(Feed { + key: FeedKey(self.id), + title: self.title, + }) + } +} + +pub struct Feed { + key: FeedKey, + title: String, +} + +impl Feed { + pub fn key(&self) -> FeedKey { self.key } + pub fn title(&self) -> &str { &self.title } + + pub async fn get( + pool: &AdapterPool, key: FeedKey + ) -> Result { + sqlx::query_as!( + UnparsedFeed, + "SELECT id, title FROM feeds WHERE id = ?", + key.0 + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn create( + pool: &AdapterPool, user_key: UserKey, title: &str + ) -> Result { + sqlx::query_as!( + UnparsedFeed, + "INSERT INTO feeds (user_id, title) + VALUES (?, ?) + RETURNING id as `id!`, title", + user_key.0, title + ).fetch_one(&pool.0).await?.parse() + } + + pub async fn update_title( + pool: &AdapterPool, key: FeedKey, new_title: &str + ) -> Result<()> { + sqlx::query!( + "UPDATE feeds SET title = ? WHERE id = ?", + new_title, key.0 + ).execute(&pool.0).await?; + + Ok(()) + } + + pub async fn add_channel( + &self, pool: &AdapterPool, channel_key: ChannelKey + ) -> Result<()> { + sqlx::query!( + "INSERT INTO feed_channels (feed_id, channel_id) + VALUES (?, ?)", + self.key.0, channel_key.0 + ).execute(&pool.0).await?; + + Ok(()) + } + + pub async fn get_channels( + &self, pool: &AdapterPool + ) -> Result> { + sqlx::query_as!( + UnparsedChannel, + "SELECT c.id as `id!`, c.title, c.link, c.description, c.last_fetched + FROM channels c + JOIN feed_channels fc on c.id = fc.channel_id + WHERE fc.feed_id = ?", + self.key.0 + ).fetch_all(&pool.0).await?.into_iter() + .map(UnparsedChannel::parse).collect() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + db::User, + test_utils::{ + FEED_TITLE, USERNAME, FEED1, FEED2, + setup_adapter, + setup_feed, + setup_channel, + } + }; + use reqwest::Url; + + #[test] + fn parse() { + const FID: i64 = 1; + let uf = UnparsedFeed { + id: FID, + title: FEED_TITLE.to_string(), + }; + + let f = uf.parse().unwrap(); + + assert_eq!(f.key.0, FID); + assert_eq!(f.title, FEED_TITLE); + } + + #[tokio::test] + async fn get() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + + let gotten_feed = Feed::get(pool, feed.key).await.unwrap(); + + assert_eq!(feed.key, gotten_feed.key); + assert_eq!(feed.title, gotten_feed.title); + } + + #[tokio::test] + async fn create() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, USERNAME).await.unwrap(); + let feed = Feed::create(pool, user.key(), FEED_TITLE).await.unwrap(); + + assert!(feed.key().0 > 0); + assert_eq!(feed.title(), FEED_TITLE); + } + + #[tokio::test] + async fn update_title() { + const NEW_FEED_TITLE: &str = "My NEW feed!"; + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + + Feed::update_title(pool, feed.key(), NEW_FEED_TITLE).await.unwrap(); + + let updated = Feed::get(pool, feed.key()).await.unwrap(); + assert_eq!(updated.title(), NEW_FEED_TITLE); + } + + #[tokio::test] + async fn add_channel() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + let channel = setup_channel(pool).await; + + feed.add_channel(pool, channel.key()).await.unwrap(); + + let channels = feed.get_channels(pool).await.unwrap(); + let gotten_channel = &channels[0]; + + assert_eq!(gotten_channel.key().0, channel.key().0); + } + + #[tokio::test] + async fn get_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let feed = setup_feed(pool).await; + let url1 = Url::parse(FEED1).unwrap(); + let channel1 = Channel::get_or_create(pool, url1).await.unwrap(); + let url2 = Url::parse(FEED2).unwrap(); + let channel2 = Channel::get_or_create(pool, url2).await.unwrap(); + + feed.add_channel(pool, channel1.key()).await.unwrap(); + feed.add_channel(pool, channel2.key()).await.unwrap(); + + let channels = feed.get_channels(pool).await.unwrap(); + + assert_eq!(channels.len(), 2); + } +} diff --git a/koucha/src/db/user.rs b/koucha/src/db/user.rs index f42491b..038b82a 100644 --- a/koucha/src/db/user.rs +++ b/koucha/src/db/user.rs @@ -1,7 +1,11 @@ use crate::{ Result, AdapterPool, - db::UserKey, + db::{ + UserKey, + Feed, + feed::UnparsedFeed, + }, }; pub struct UnparsedUser { @@ -61,14 +65,26 @@ impl User { Ok(()) } + + pub async fn get_feeds(&self, pool: &AdapterPool) -> Result> { + let feeds: Result> = sqlx::query_as!( + UnparsedFeed, + "SELECT id, title FROM feeds WHERE user_id = ?", + self.key.0 + ).fetch_all(&pool.0).await?.into_iter() + .map(UnparsedFeed::parse).collect(); + + feeds + } } #[cfg(test)] mod tests { use super::*; use crate::{ + db::Feed, test_utils::{ - USERNAME, USERNAME2, + USERNAME, USERNAME2, FEED_TITLE, FEED_TITLE2, setup_adapter, }, }; @@ -157,4 +173,28 @@ mod tests { assert!(status.is_err()); } + + #[tokio::test] + async fn get_feeds() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, USERNAME).await.unwrap(); + Feed::create(pool, user.key, FEED_TITLE).await.unwrap(); + Feed::create(pool, user.key, FEED_TITLE2).await.unwrap(); + + let feeds = user.get_feeds(pool).await.unwrap(); + assert_eq!(feeds.len(), 2); + assert!(feeds.iter().any(|f| f.title() == FEED_TITLE)); + assert!(feeds.iter().any(|f| f.title() == FEED_TITLE2)); + } + + #[tokio::test] + async fn get_feeds_empty() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let user = User::create(pool, USERNAME).await.unwrap(); + let feeds = user.get_feeds(pool).await.unwrap(); + + assert_eq!(feeds.len(), 0); + } } diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs index 7cd4601..d02643c 100644 --- a/koucha/src/test_utils.rs +++ b/koucha/src/test_utils.rs @@ -3,15 +3,28 @@ use crate::{ Adapter, AdapterBuilder, + AdapterPool, + db::{ + Channel, + Feed, + User, + } }; +use reqwest::Url; use chrono::{ Utc, TimeZone, DateTime }; +pub const FEED1: &str = "https://example.com/feed"; +pub const FEED2: &str = "https://example2.com/feed"; pub const USERNAME: &str = "Alice"; pub const USERNAME2: &str = "Bob"; +pub const FEED_TITLE: &str = "My Feed!"; +pub const FEED_TITLE2: &str = "My Second Feed!"; +pub const CHANNEL_TITLE: &str = "My Channel!"; +pub const CHANNEL_DESC: &str = "My Channel's description"; pub fn get_datetime() -> DateTime { Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() @@ -22,3 +35,13 @@ pub async fn setup_adapter() -> Adapter { .database_url("sqlite::memory:") .create().await.unwrap() } + +pub async fn setup_channel(pool: &AdapterPool) -> Channel { + let url = Url::parse(FEED1).unwrap(); + Channel::get_or_create(pool, url).await.unwrap() +} + +pub async fn setup_feed(pool: &AdapterPool) -> Feed { + let user = User::create(pool, USERNAME).await.unwrap(); + Feed::create(pool, user.key(), FEED_TITLE).await.unwrap() +} -- 2.52.0 From 070c55a95bdc91c3ed7cdaab00968ba7d8e55d47 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 6 Feb 2026 13:03:31 -0800 Subject: [PATCH 6/8] db, add item and functions to get items Creates item. It's pretty barebowns until I implement fetching. I also added get functions for feed and channel to get items with. --- koucha/src/db.rs | 3 + koucha/src/db/channel.rs | 33 ++++++++++- koucha/src/db/feed.rs | 18 ++++++ koucha/src/db/item.rs | 122 +++++++++++++++++++++++++++++++++++++++ koucha/src/test_utils.rs | 5 ++ 5 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 koucha/src/db/item.rs diff --git a/koucha/src/db.rs b/koucha/src/db.rs index df11ecc..4964fd9 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -4,6 +4,8 @@ mod feed; pub use feed::Feed; mod channel; pub use channel::Channel; +mod item; +pub use item::Item; macro_rules! define_key { ($name:ident) => { @@ -15,3 +17,4 @@ macro_rules! define_key { define_key!(UserKey); define_key!(FeedKey); define_key!(ChannelKey); +define_key!(ItemKey); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index f8642f5..0f38f3e 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -3,7 +3,11 @@ use chrono::{DateTime, Utc}; use crate::{ Result, AdapterPool, - db::ChannelKey, + db::{ + ChannelKey, + Item, + item::UnparsedItem, + }, }; pub struct UnparsedChannel { @@ -74,6 +78,17 @@ impl Channel { link_str, link_str // We use the url as a placeholder title ).fetch_one(&pool.0).await?.parse() } + + pub async fn get_items(&self, pool: &AdapterPool) -> Result> { + sqlx::query_as!( + UnparsedItem, + "SELECT id as `id!`, channel_id, fetched_at, title, description, + content + FROM items + WHERE channel_id = ?", + self.key.0 + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect() + } } #[cfg(test)] @@ -81,7 +96,7 @@ mod tests { use super::*; use crate::{ test_utils::{ - FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, + FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, ITEM_GUID, ITEM_GUID2, setup_adapter, setup_channel, }, @@ -176,4 +191,18 @@ mod tests { assert_eq!(channels.len(), 2); } + + #[tokio::test] + async fn get_items() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + Item::get_or_create(pool, channel.key(), ITEM_GUID).await.unwrap(); + Item::get_or_create(pool, channel.key(), ITEM_GUID2).await.unwrap(); + + let items = channel.get_items(pool).await.unwrap(); + + assert_eq!(items.len(), 2); + } } diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs index da645e6..a162190 100644 --- a/koucha/src/db/feed.rs +++ b/koucha/src/db/feed.rs @@ -5,8 +5,10 @@ use crate::{ Channel, ChannelKey, FeedKey, + Item, UserKey, channel::UnparsedChannel, + item::UnparsedItem, }, }; @@ -77,6 +79,22 @@ impl Feed { Ok(()) } + pub async fn get_items( + &self, pool: &AdapterPool, limit: u8, offset: u32 + ) -> Result> { + sqlx::query_as!( + UnparsedItem, + "SELECT i.id as `id!`, i.channel_id, i.fetched_at, i.title, i.description, + i.content + FROM items i + JOIN feed_items fi on i.id = fi.item_id + WHERE feed_id = ? AND archived = FALSE + ORDER BY score DESC + LIMIT ? OFFSET ?", + self.key.0, limit, offset + ).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect() + } + pub async fn get_channels( &self, pool: &AdapterPool ) -> Result> { diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs new file mode 100644 index 0000000..31ee857 --- /dev/null +++ b/koucha/src/db/item.rs @@ -0,0 +1,122 @@ +use crate::{ + Result, + AdapterPool, + db::{ + ChannelKey, + ItemKey, + }, +}; +use chrono::{DateTime, Utc}; + +pub struct UnparsedItem { + pub id: i64, + pub channel_id: i64, + pub fetched_at: Option, + + pub title: Option, + pub description: Option, + pub content: Option, +} + +impl UnparsedItem { + pub fn parse(self) -> Result { + Ok(Item { + key: ItemKey(self.id), + channel_id: ChannelKey(self.channel_id), + fetched_at: match self.fetched_at { + Some(dt_str) => Some(DateTime::parse_from_rfc2822(&dt_str)? + .with_timezone(&Utc)), + None => None, + }, + + title: self.title, + description: self.description, + content: self.content, + }) + } +} + +pub struct Item { + key: ItemKey, + channel_id: ChannelKey, + + fetched_at: Option>, + title: Option, + description: Option, + content: Option, +} + +impl Item { + pub fn key(&self) -> ItemKey { self.key } + pub fn channel(&self) -> ChannelKey { self.channel_id } + pub fn title(&self) -> Option<&str> { self.title.as_deref() } + pub fn description(&self) -> Option<&str> { self.description.as_deref() } + pub fn content(&self) -> Option<&str> { self.content.as_deref() } + + pub async fn get_or_create( + pool: &AdapterPool, from_channel: ChannelKey, guid: &str + ) -> Result { + + let item = sqlx::query_as!( + UnparsedItem, + "INSERT INTO items (channel_id, guid) + VALUES (?, ?) + ON CONFLICT(channel_id, guid) DO UPDATE SET channel_id = channel_id + RETURNING id as `id!`, channel_id, fetched_at, title, description, + content", + from_channel.0, guid + ).fetch_one(&pool.0).await?.parse(); + + item + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::{ + ITEM_GUID, ITEM_TITLE, ITEM_DESC, ITEM_CONT, + setup_adapter, + setup_channel, + }; + use chrono::TimeZone; + + // UnparsedItem tests + #[test] + fn parse_unparsed_item() { + const ITEM_ID: i64 = 1; + const CHANNEL_ID: i64 = 1; + + let date: DateTime = Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap(); + let raw_item = UnparsedItem { + id: ITEM_ID, + channel_id: CHANNEL_ID, + fetched_at: Some(date.to_rfc2822()), + title: Some(ITEM_TITLE.to_string()), + description: Some(ITEM_DESC.to_string()), + content: Some(ITEM_CONT.to_string()), + }; + let item = raw_item.parse().unwrap(); + + assert_eq!(item.key.0, ITEM_ID); + assert_eq!(item.channel_id.0, CHANNEL_ID); + assert_eq!(item.fetched_at, Some(date)); + assert_eq!(item.title, Some(ITEM_TITLE.to_string())); + assert_eq!(item.description, Some(ITEM_DESC.to_string())); + assert_eq!(item.content, Some(ITEM_CONT.to_string())); + + } + + // Item Tests + #[tokio::test] + async fn get_or_create_duplicate() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + let item1 = Item::get_or_create(pool, channel.key(), ITEM_GUID).await.unwrap(); + let item2 = Item::get_or_create(pool, channel.key(), ITEM_GUID).await.unwrap(); + + assert_eq!(item1.key(), item2.key()); + } +} diff --git a/koucha/src/test_utils.rs b/koucha/src/test_utils.rs index d02643c..6a21ca9 100644 --- a/koucha/src/test_utils.rs +++ b/koucha/src/test_utils.rs @@ -25,6 +25,11 @@ pub const FEED_TITLE: &str = "My Feed!"; pub const FEED_TITLE2: &str = "My Second Feed!"; pub const CHANNEL_TITLE: &str = "My Channel!"; pub const CHANNEL_DESC: &str = "My Channel's description"; +pub const ITEM_GUID: &str = "item-guid"; +pub const ITEM_GUID2: &str = "item-guid2"; +pub const ITEM_TITLE: &str = "My Item!"; +pub const ITEM_DESC: &str = "My Item's description"; +pub const ITEM_CONT: &str = "The content of my Item"; pub fn get_datetime() -> DateTime { Utc.with_ymd_and_hms(2020,1,1,0,0,0).unwrap() -- 2.52.0 From fcb03ead1f1f179eabcc38237d815227523369c2 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 6 Feb 2026 13:18:26 -0800 Subject: [PATCH 7/8] fetch, create fetch mod and AdapterClient Creates a fetch mod for fetching remote rss content. This implementation is barebones and not great since it doesn't pass any compression or timestamp information. --- koucha/Cargo.lock | 129 +++++++++++++++++++++++++++++++++++++ koucha/Cargo.toml | 1 + koucha/src/fetch.rs | 151 ++++++++++++++++++++++++++++++++++++++++++++ koucha/src/lib.rs | 8 ++- 4 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 koucha/src/fetch.rs diff --git a/koucha/Cargo.lock b/koucha/Cargo.lock index 4849805..c9fd8ab 100644 --- a/koucha/Cargo.lock +++ b/koucha/Cargo.lock @@ -26,6 +26,19 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atom_syndication" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f68d23e2cb4fd958c705b91a6b4c80ceeaf27a9e11651272a8389d5ce1a4a3" +dependencies = [ + "chrono", + "derive_builder", + "diligent-date-parser", + "never", + "quick-xml", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -260,6 +273,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "der" version = "0.7.10" @@ -271,6 +319,37 @@ dependencies = [ "zeroize", ] +[[package]] +name = "derive_builder" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" +dependencies = [ + "derive_builder_core", + "syn", +] + [[package]] name = "digest" version = "0.10.7" @@ -283,6 +362,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "diligent-date-parser" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ede7d79366f419921e2e2f67889c12125726692a313bffb474bd5f37a581e9" +dependencies = [ + "chrono", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -806,6 +894,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "1.1.0" @@ -907,6 +1001,7 @@ version = "0.1.0" dependencies = [ "chrono", "reqwest", + "rss", "sqlx", "tokio", ] @@ -1014,6 +1109,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "never" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91" + [[package]] name = "num-bigint-dig" version = "0.8.6" @@ -1182,6 +1283,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-xml" +version = "0.37.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" +dependencies = [ + "encoding_rs", + "memchr", +] + [[package]] name = "quinn" version = "0.11.9" @@ -1402,6 +1513,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rss" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2107738f003660f0a91f56fd3e3bd3ab5d918b2ddaf1e1ec2136fb1c46f71bf" +dependencies = [ + "atom_syndication", + "derive_builder", + "never", + "quick-xml", +] + [[package]] name = "rustc-hash" version = "2.1.1" @@ -1894,6 +2017,12 @@ dependencies = [ "unicode-properties", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.6.1" diff --git a/koucha/Cargo.toml b/koucha/Cargo.toml index 7a97cef..1106901 100644 --- a/koucha/Cargo.toml +++ b/koucha/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] reqwest = "0.13.1" +rss = "2.0.12" tokio = { version = "1.49.0", features = ["full"] } sqlx = { version = "0.8.6", features = [ "runtime-tokio", "sqlite" ] } chrono = "0.4.43" diff --git a/koucha/src/fetch.rs b/koucha/src/fetch.rs new file mode 100644 index 0000000..53ba2b9 --- /dev/null +++ b/koucha/src/fetch.rs @@ -0,0 +1,151 @@ +use crate::{ + Result, + db::Channel, + AdapterClient, +}; +use reqwest::Url; +use chrono::{DateTime, Utc}; +use std::hash::{Hash, Hasher}; + +pub struct FetchedRSSItem { + guid: String, + title: String, + description: String, + content: String, +} +impl FetchedRSSItem { + pub fn guid(&self) -> &str { &self.guid } + pub fn title(&self) -> &str { &self.title } + pub fn description(&self) -> &str { &self.description } + pub fn content(&self) -> &str { &self.content } + + fn parse(item: rss::Item) -> Self { + FetchedRSSItem { + guid: Self::get_or_create_guid(&item), + title: item.title().unwrap_or("").to_string(), + description: item.description().unwrap_or("").to_string(), + content: item.content().unwrap_or("").to_string(), + } + } + + fn get_or_create_guid(item: &rss::Item) -> String { + if let Some(guid) = item.guid() { + return guid.value().to_string(); + } + + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + item.link().unwrap_or("").hash(&mut hasher); + item.title().unwrap_or("").hash(&mut hasher); + item.description().unwrap_or("").hash(&mut hasher); + + format!("gen-{:x}", hasher.finish()) + } +} +pub struct FetchedRSSChannel { + title: String, + link: Url, + description: String, + + items: Vec, + + fetched_at: DateTime, +} +impl FetchedRSSChannel { + pub fn title(&self) -> &str { &self.title } + pub fn link(&self) -> &Url { &self.link } + pub fn description(&self) -> &str { &self.description } + pub fn items(&self) -> &[FetchedRSSItem] { &self.items } + pub fn fetched_at(&self) -> &DateTime { &self.fetched_at } + + pub async fn fetch_channel( + client: &AdapterClient, channel: Channel + ) -> Result> { + let bytestream = client.0.get(channel.link().clone()) + .send().await? + .bytes().await?; + + let rss_channel = rss::Channel::read_from(&bytestream[..])?; + + let now = Utc::now(); + + Ok(Some(FetchedRSSChannel::parse(rss_channel, now)?)) + } + + fn parse(rss: rss::Channel, fetched_at: DateTime) -> Result { + Ok(FetchedRSSChannel { + title: rss.title, + link: Url::parse(&rss.link)?, + description: rss.description, + + items: rss.items.into_iter().map(FetchedRSSItem::parse).collect(), + + fetched_at: fetched_at, + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_utils::{ + ITEM_TITLE, ITEM_GUID, ITEM_GUID2, ITEM_DESC, ITEM_CONT, + CHANNEL_TITLE, CHANNEL_DESC, FEED1, + get_datetime + }; + + fn create_guid(value: String) -> rss::Guid { + rss::Guid { value, permalink: false } + } + + fn create_item(guid: rss::Guid) -> rss::Item { + rss::ItemBuilder::default() + .title(ITEM_TITLE.to_string()) + .guid(guid) + .description(ITEM_DESC.to_string()) + .content(ITEM_CONT.to_string()) + .build() + } + + fn create_channel(items: Vec) -> rss::Channel { + rss::ChannelBuilder::default() + .title(CHANNEL_TITLE.to_string()) + .description(CHANNEL_DESC.to_string()) + .link(FEED1.to_string()) + .items(items) + .build() + } + + #[test] + fn parse_item() { + let rss_guid = create_guid(ITEM_GUID.to_string()); + let rss_item = create_item(rss_guid); + let item = FetchedRSSItem::parse(rss_item); + + assert_eq!(item.guid, ITEM_GUID); + assert_eq!(item.title, ITEM_TITLE); + assert_eq!(item.description, ITEM_DESC); + assert_eq!(item.content, ITEM_CONT); + } + + #[test] + fn parse_feed() { + let rss_guid = create_guid(ITEM_GUID.to_string()); + let rss_guid2 = create_guid(ITEM_GUID2.to_string()); + let rss_item = create_item(rss_guid); + let rss_item2 = create_item(rss_guid2); + + let rss_channel = create_channel([rss_item, rss_item2].to_vec()); + + let date: DateTime = get_datetime(); + + let channel = FetchedRSSChannel::parse(rss_channel, date).unwrap(); + + assert_eq!(channel.title, CHANNEL_TITLE); + assert_eq!(channel.link.as_str(), FEED1); + assert_eq!(channel.description, CHANNEL_DESC); + assert_eq!(channel.fetched_at, date); + assert_eq!(channel.items.len(), 2); + assert!(channel.items.iter().any(|i| i.guid() == ITEM_GUID)); + assert!(channel.items.iter().any(|i| i.guid() == ITEM_GUID2)); + } +} diff --git a/koucha/src/lib.rs b/koucha/src/lib.rs index 5982237..a20a9dc 100644 --- a/koucha/src/lib.rs +++ b/koucha/src/lib.rs @@ -3,12 +3,15 @@ use std::error::Error; type Result = std::result::Result>; pub mod db; +pub mod fetch; pub mod score; #[cfg(test)] pub mod test_utils; pub struct AdapterPool(sqlx::SqlitePool); +pub struct AdapterClient(reqwest::Client); + pub struct AdapterBuilder { database_url: String, } @@ -29,15 +32,18 @@ impl AdapterBuilder { let db = sqlx::sqlite::SqlitePoolOptions::new() .connect(&self.database_url).await?; sqlx::migrate!().run(&db).await?; + let client = reqwest::Client::new(); - Ok(Adapter { db: AdapterPool(db) }) + Ok(Adapter { db: AdapterPool(db), client: AdapterClient(client) }) } } pub struct Adapter { db: AdapterPool, + client: AdapterClient, } impl Adapter { pub fn get_pool(&self) -> &AdapterPool { &self.db } + pub fn get_client(&self) -> &AdapterClient { &self.client } } -- 2.52.0 From bab52687c7619f3ab67c1ab61c726a6a89f20326 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Fri, 6 Feb 2026 14:49:13 -0800 Subject: [PATCH 8/8] db&score, feed_channel impl & score from db Adds a feed_channel implementation which reflects a feed's specific settings per channel. Also added an UnparsedTimedScore to score which allows parsing to score from db in a controlled fashion. --- koucha/src/db.rs | 10 ++ koucha/src/db/channel.rs | 37 ++++++- koucha/src/db/feed_channel.rs | 188 ++++++++++++++++++++++++++++++++++ koucha/src/score.rs | 58 +++++++++++ 4 files changed, 292 insertions(+), 1 deletion(-) create mode 100644 koucha/src/db/feed_channel.rs diff --git a/koucha/src/db.rs b/koucha/src/db.rs index 4964fd9..9be8130 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -2,6 +2,8 @@ mod user; pub use user::User; mod feed; pub use feed::Feed; +mod feed_channel; +pub use feed_channel::FeedChannel; mod channel; pub use channel::Channel; mod item; @@ -12,9 +14,17 @@ macro_rules! define_key { #[derive(PartialEq, Debug, Copy, Clone)] pub struct $name(i64); }; + + ($name:ident, $($field:ident : $type:ty),* $(,)?) => { + #[derive(PartialEq, Debug, Copy, Clone)] + pub struct $name { + $($field: $type),* + } + }; } define_key!(UserKey); define_key!(FeedKey); +define_key!(FeedChannelKey, feed_key: FeedKey, channel_key: ChannelKey); define_key!(ChannelKey); define_key!(ItemKey); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index 0f38f3e..eaa03be 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -6,6 +6,8 @@ use crate::{ db::{ ChannelKey, Item, + FeedChannel, + feed_channel::UnparsedFeedChannel, item::UnparsedItem, }, }; @@ -79,6 +81,19 @@ impl Channel { ).fetch_one(&pool.0).await?.parse() } + async fn get_feed_channels( + &self, pool: &AdapterPool + ) -> Result> { + sqlx::query_as!( + UnparsedFeedChannel, + "SELECT channel_id, feed_id, initial_score, gravity, boost + FROM feed_channels + WHERE channel_id = ?", + self.key.0 + ).fetch_all(&pool.0).await?.into_iter() + .map(UnparsedFeedChannel::parse).collect() + } + pub async fn get_items(&self, pool: &AdapterPool) -> Result> { sqlx::query_as!( UnparsedItem, @@ -95,8 +110,10 @@ impl Channel { mod tests { use super::*; use crate::{ + db::{Feed, User}, test_utils::{ - FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, ITEM_GUID, ITEM_GUID2, + FEED1, FEED2, CHANNEL_TITLE, CHANNEL_DESC, USERNAME, FEED_TITLE, + FEED_TITLE2, ITEM_GUID, ITEM_GUID2, setup_adapter, setup_channel, }, @@ -192,6 +209,24 @@ mod tests { assert_eq!(channels.len(), 2); } + #[tokio::test] + async fn get_feed_channels() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + let channel = setup_channel(pool).await; + + let user = User::create(pool, USERNAME).await.unwrap(); + let feed1 = Feed::create(pool, user.key(), FEED_TITLE).await.unwrap(); + let feed2 = Feed::create(pool, user.key(), FEED_TITLE2).await.unwrap(); + + feed1.add_channel(pool, channel.key).await.unwrap(); + feed2.add_channel(pool, channel.key).await.unwrap(); + + let fc_list = channel.get_feed_channels(pool).await.unwrap(); + + assert_eq!(fc_list.len(), 2); + } + #[tokio::test] async fn get_items() { let adapter = setup_adapter().await; diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs new file mode 100644 index 0000000..e2df61a --- /dev/null +++ b/koucha/src/db/feed_channel.rs @@ -0,0 +1,188 @@ +use crate::{ + Result, + AdapterPool, + db::{ + Channel, + ChannelKey, + Feed, + FeedKey, + FeedChannelKey, + Item, + }, + score::{ + Score, + Gravity, + Boost, + }, +}; +use chrono::{Utc, DateTime}; + +pub struct UnparsedFeedChannel { + pub channel_id: i64, + pub feed_id: i64, + pub initial_score: Option, + pub gravity: Option, + pub boost: Option, +} +impl UnparsedFeedChannel { + pub fn parse(self) -> Result { + Ok(FeedChannel { + key: FeedChannelKey { + feed_key: FeedKey(self.feed_id), + channel_key: ChannelKey(self.channel_id), + }, + initial_score: Score::new(self.initial_score), + gravity: Gravity::new(self.gravity), + boost: Boost::new(self.boost), + }) + } +} + +pub struct FeedChannel { + key: FeedChannelKey, + initial_score: Score, + gravity: Gravity, + boost: Boost, +} + +impl FeedChannel { + pub async fn get_channel(&self, pool: &AdapterPool) -> Result { + Channel::get(pool, self.key.channel_key).await + } + pub async fn get_feed(&self, pool: &AdapterPool) -> Result { + Feed::get(pool, self.key.feed_key).await + } + + pub async fn add_item( + &self, pool: &AdapterPool, item: &Item + ) -> Result<()> { + self.add_item_at(pool, item, Utc::now()).await + } + + async fn add_item_at( + &self, pool: &AdapterPool, item: &Item, add_at: DateTime + ) -> Result<()> { + let int_item_id = item.key().0; + let int_initial_score = i64::from(self.initial_score); + let string_last_updated = add_at.to_rfc2822(); + + sqlx::query!( + "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score, last_updated) + VALUES (?, ?, ?, ?)", + self.key.feed_key.0, int_item_id, int_initial_score, string_last_updated + ).execute(&pool.0).await?; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use reqwest::Url; + use crate::{ + db::{ + Channel, + FeedKey, + User + }, + test_utils::{ + FEED1, setup_adapter, get_datetime + }, + }; + + #[test] + fn parse() { + const CID: i64 = 1; + const FID: i64 = 2; + const IS: i64 = 3; + const G: i64 = 4; + const B: i64 = 5; + let ufc = UnparsedFeedChannel { + channel_id: CID, + feed_id: FID, + initial_score: Some(IS), + gravity: Some(G), + boost: Some(B), + }; + + let fc = ufc.parse().unwrap(); + + assert_eq!(fc.key.channel_key.0, CID); + assert_eq!(fc.key.feed_key.0, FID); + assert_eq!(i64::from(fc.initial_score), IS); + assert_eq!(i64::from(fc.gravity), G); + assert_eq!(i64::from(fc.boost), B); + } + + // FeedChannel Tests + #[tokio::test] + async fn get_channel() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let url = Url::parse(FEED1).unwrap(); + let channel = Channel::get_or_create(pool, url).await.unwrap(); + + let fc = FeedChannel { + key: FeedChannelKey { + feed_key: FeedKey(1), // Fake Feed + channel_key: channel.key(), + }, + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), + }; + + let channel_from_fc = fc.get_channel(pool).await.unwrap(); + assert_eq!(channel_from_fc.key(), channel.key()); + } + + #[tokio::test] + async fn get_feed() { + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, "Alice").await.unwrap(); + let feed = Feed::create(pool, user.key(), "My Feed").await.unwrap(); + + let fc = FeedChannel { + key: FeedChannelKey { + feed_key: feed.key(), + channel_key: ChannelKey(1), // Fake Channel + }, + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), + }; + + let feed_from_fc = fc.get_feed(pool).await.unwrap(); + assert_eq!(feed_from_fc.key(), feed.key()); + } + + #[tokio::test] + pub async fn add_item() { + let dt = get_datetime(); + let adapter = setup_adapter().await; + let pool = adapter.get_pool(); + + let user = User::create(pool, "Alice").await.unwrap(); + let feed = Feed::create(pool, user.key(), "My Feed").await.unwrap(); + let url = Url::parse(FEED1).unwrap(); + let channel = Channel::get_or_create(pool, url).await.unwrap(); + let fc = FeedChannel { + key: FeedChannelKey { + feed_key: feed.key(), + channel_key: channel.key(), + }, + initial_score: Score::new(None), + gravity: Gravity::new(None), + boost: Boost::new(None), + }; + + let item = Item::get_or_create(pool, channel.key(), "item-guid").await.unwrap(); + fc.add_item_at(pool, &item, dt).await.unwrap(); + + let items = feed.get_items(pool, 1, 0).await.unwrap(); + assert_eq!(items[0].key(), item.key()); + } +} diff --git a/koucha/src/score.rs b/koucha/src/score.rs index e289c6e..754ca17 100644 --- a/koucha/src/score.rs +++ b/koucha/src/score.rs @@ -61,6 +61,41 @@ impl Gravity { ) } } +pub struct UnparsedTimedScore { + pub value: i64, + pub last_updated: DateTime, + pub last_boosted: Option>, +} + +impl UnparsedTimedScore { + pub fn parse(self) -> TimedScore { + match self.last_boosted { + None => TimedScore::Decaying(DecayingScore { + value: Score(self.value), + last_updated: self.last_updated, + }), + Some(last_boosted) => TimedScore::Boosted(BoostedScore { + value: Score(self.value), + boosted_at: last_boosted, + }), + } + } + + pub fn unparse(ts: TimedScore) -> Self { + match ts { + TimedScore::Decaying(ds) => UnparsedTimedScore { + value: ds.value.into(), + last_updated: ds.last_updated, + last_boosted: None, + }, + TimedScore::Boosted(bs) => UnparsedTimedScore { + value: bs.value.into(), + last_updated: bs.boosted_at, + last_boosted: Some(bs.boosted_at), + }, + } + } +} #[derive(Clone)] pub enum TimedScore { @@ -211,6 +246,29 @@ mod tests { // "Score" Tests + #[test] + fn parse_decaying() { + let ups = UnparsedTimedScore { + value: 10, + last_updated: get_datetime(), + last_boosted: None, + }; + + ups.parse().get_decaying().unwrap(); + } + + #[test] + fn parse_boosted() { + let dt = get_datetime(); + let ups = UnparsedTimedScore { + value: 10, + last_updated: dt, + last_boosted: Some(dt), + }; + + ups.parse().get_boosted().unwrap(); + } + #[test] fn new() { let score = TimedScore::new(); -- 2.52.0