Skip to content

Library crates own no storage: SessionStore + Cache traits, typed API - #2

Draft
macalinao wants to merge 6 commits into
masterfrom
library-storage
Draft

macalinao wants to merge 6 commits into
masterfrom
library-storage

Conversation

@macalinao

Copy link
Copy Markdown
Collaborator

Library crates (grabcli-core, grabfood, grabmart) now own no storage: no paths, config-file reads, env, printing or rusqlite. They can be embedded in a daemon that keeps the session and cache in its own database.

What's here

  • Core traits. SessionStore and Cache are async (async_trait), Send + Sync and usable as Arc<dyn …>. Context::new(config, store, cache) is async and saves every session change (silent refresh, hydra mint, mart login, address) through the store. CacheHandle holds the TTL/mode logic. MemorySessionStore, MemoryCache and NoCache are for tests and embedders.
  • grabcli-sqlite. New crate with SqliteCache (the old cache DB, catalog and images) plus stats/clear/prune. It is the only crate that links rusqlite.
  • Login driver. Login uses step functions over a &mut Option<PendingLogin> slot with an injectable SendBudget. LoginDriver (start / submit_code / poll / cancel) ends in Done(Session) and writes no files.
  • grabfood typed API. Covers browse listings, menu, cart_add/cart_remove on a Cart value, quote, vouchers/best_voucher, prepare/submit/place_order, orders, track and history. The order path checks the quote id against a fresh quote and requires allow_ordering, both before any request, and never retries. The bpaf parser for ListOpts is behind the cli feature.
  • grabmart. Mart::new(ctx) with an injectable Pacer. The mart command flows stay in the CLI.
  • CLI. The grab bin owns config.toml, FileSessionStore (session.json, 0600), the login send-log and pending-login files, the hydra key, GRAB_NO_CACHE, cart and last-quote files, the tracking map and printing. CLI behaviour is unchanged.

Tests

  • New tests cover the store and cache traits (memory backends) and saving through the store (location change, hydra mint, failed refresh saves nothing).
  • Also new: the order refusals (quote mismatch, ordering disabled) with no network, and the file store and budget.
  • cargo test --workspace, cargo clippy --workspace --all-targets -D warnings, nix fmt and nix flake check all pass. No test hits Grab.

…, storage-free login steps

grabcli-core no longer reads files, paths or the environment and no longer
depends on rusqlite. Context loads/saves the session through an
Arc<dyn SessionStore> and caches through an Arc<dyn Cache> (wrapped in
CacheHandle for TTLs/modes). MemorySessionStore, MemoryCache and NoCache
for tests and embedders. Login steps take the pending login as a value and
the send budget as an injectable SendBudget; LoginDriver wraps them as a
state machine for daemons.

WIP: the service crates and the CLI are ported in the next commits.
…printing

grabfood exposes context(), menu(), cart_add/cart_remove, quote(), vouchers()/best_voucher(), prepare_order/submit_order/place_order (quote-id match and allow_ordering checked before any request, never retried), orders(), track(), history(); browse functions return Listing. ListOpts' bpaf parser is behind the cli feature. grabmart's Mart::new takes a Context and an injectable Pacer.
…raries

session.json via FileSessionStore (0600), login send log and pending login files, config.toml and hydra-key.pem loading, GRAB_NO_CACHE, and the SQLite cache all live in the bin crate now. The food/mart command enums, printing, cart and last-quote files, the tile map and cross-process mart pacing moved here from the library crates. CLI behaviour is unchanged.
…tance)

Git-dependency vendoring that copies only the crate directory (crate2nix) can't resolve workspace.package or workspace dependencies.
@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant