Files
k-mood/crates/domain/src/macros.rs
Gabriel Kaszewski bf148902ab spa hardening, offline logging, rate limit fixes
server:
- backup exporter, auth extractors, error shapes, CONTEXT (prior work)
- spa assets served outside the rate limit via route_layer
- requests_per_second went to per_second(), which takes an interval not a
  rate: 50 meant one request per 50s once burst was spent. now converted
  properly. 15/s, burst 60

spa fixes:
- account delete cleared snake_case token keys that were never written
- refresh interceptor could retry forever
- date ranges used local day boundaries stamped +00:00
- "all" period trend plotted one page; calendar days fabricated mood 3
- chart grid invisible: hsl(var(--border)) against rgba tokens
- blob url leak, orphaned media on failed save, devtools in prod bundle
- pt-safe/safe-area-pb classes never existed

spa features:
- offline outbox: entries queue to IndexedDB, replay with backoff, only
  server refusals count against an entry
- drafts persist, quick-log sheet, diary infinite scroll + filters
- route error boundary, stale-chunk recovery, no service worker in dev

a11y + perf:
- mood picker is a radiogroup, activity picker keyboard-operable,
  text alternatives for colour/emoji, locale week start
- dark glass over the bright photo: worst case 1.4:1 -> 4.9-9.6:1
- initial payload 1095->769kB raw, 306->230kB gzip; 38 unused components
  and 5 deps dropped; fonts 218->133kB

53 tests added (43 spa, 10 server)
2026-08-28 15:00:30 +02:00

79 lines
2.1 KiB
Rust

macro_rules! uuid_id {
($name:ident) => {
#[derive(
Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
serde::Serialize, serde::Deserialize,
)]
pub struct $name(uuid::Uuid);
impl $name {
pub fn generate() -> Self {
Self(uuid::Uuid::new_v4())
}
pub fn from_uuid(uuid: uuid::Uuid) -> Self {
Self(uuid)
}
pub fn value(&self) -> uuid::Uuid {
self.0
}
}
impl Default for $name {
fn default() -> Self {
Self::generate()
}
}
impl From<uuid::Uuid> for $name {
fn from(uuid: uuid::Uuid) -> Self {
Self(uuid)
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
};
}
pub(crate) use uuid_id;
macro_rules! bounded_metric {
($name:ident, $inner:ty, $min:expr, $max:expr, $label:literal) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct $name($inner);
impl $name {
pub const MINIMUM: $inner = $min;
pub const MAXIMUM: $inner = $max;
pub fn new(value: $inner) -> Result<Self, crate::errors::DomainError> {
if !(Self::MINIMUM..=Self::MAXIMUM).contains(&value) {
return Err(crate::errors::DomainError::InvalidInput(format!(
concat!($label, " must be between {} and {}, got {}"),
Self::MINIMUM,
Self::MAXIMUM,
value
)));
}
Ok(Self(value))
}
pub fn from_persistence(value: $inner) -> Self {
Self(value)
}
pub fn value(&self) -> $inner {
self.0
}
}
};
}
pub(crate) use bounded_metric;