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)
This commit is contained in:
2026-08-28 14:59:21 +02:00
parent 23d052278a
commit bf148902ab
395 changed files with 13972 additions and 10635 deletions

View File

@@ -0,0 +1,86 @@
use crate::errors::DomainError;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Pagination {
limit: i64,
offset: i64,
}
impl Pagination {
pub fn new(limit: i64, offset: i64, most_per_page: i64) -> Result<Self, DomainError> {
if limit < 1 {
return Err(DomainError::InvalidInput(
"a page of nothing is not a page: ask for at least one".into(),
));
}
if limit > most_per_page {
return Err(DomainError::InvalidInput(format!(
"this server serves at most {most_per_page} entries per page, and {limit} were asked for"
)));
}
if offset < 0 {
return Err(DomainError::InvalidInput(
"a page cannot start before the beginning".into(),
));
}
Ok(Self { limit, offset })
}
pub fn limit(&self) -> i64 {
self.limit
}
pub fn offset(&self) -> i64 {
self.offset
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Page<T> {
items: Vec<T>,
total: u64,
at: Pagination,
}
impl<T> Page<T> {
pub fn new(items: Vec<T>, total: u64, at: Pagination) -> Self {
Self { items, total, at }
}
pub fn items(&self) -> &[T] {
&self.items
}
pub fn into_items(self) -> Vec<T> {
self.items
}
pub fn total(&self) -> u64 {
self.total
}
pub fn limit(&self) -> i64 {
self.at.limit()
}
pub fn offset(&self) -> i64 {
self.at.offset()
}
pub fn more_after_this(&self) -> bool {
let seen = self.at.offset().saturating_add(self.items.len() as i64);
(seen as u64) < self.total
}
pub fn map<U>(self, transform: impl FnMut(T) -> U) -> Page<U> {
Page {
items: self.items.into_iter().map(transform).collect(),
total: self.total,
at: self.at,
}
}
}