Finfry::Store
Persists the Database to a single JSON file under the user's XDG data
directory (override with FINFRY_DATA). Writes are atomic (temp file +
rename) so a crash mid-write can't corrupt the ledger. Legacy single-entry
files are migrated to double-entry on load, keeping a .bak backup.
Constants
The visible per-directory book file. finfry discovers it by walking up from the current directory (like git's .git), so a project/folder can hold its own ledger.
Constructors
Class methods
Resolve the active ledger: an explicit FINFRY_DATA override, else the nearest book file walking up from the current directory, else the global per-user ledger.
Instance methods
Net balance of every account (optionally restricted to a subtree, and/or
to transactions on or before up_to). Returns account => signed cents.
Run a block as a single reversible changeset. Mutations inside record how to undo themselves. Nested calls join the enclosing changeset, so an AI plan's many operations collapse into one undo unit. The changeset is only persisted if it actually changed something and the block didn't raise.
Balance of the staged tier (cleared-but-not-committed).
Transaction ids marked cleared against account's statement.
Declare an account in the chart. Returns false if already declared.
Remove a transaction by id. Returns the deleted record, or nil if absent.
Materialize every occurrence due up to today into the queue, advancing
each rule's cursor so nothing is generated twice. Returns how many were
added.
Declared ∪ used — the accounts finfry treats as known. Feeds the AI's
chart context, the accounts listing, and completions.
The most recent finalized reconciliation for an account, if any.
Finalize a reconciliation: move every staged-cleared transaction into the committed tier and record the statement it was balanced against. The caller verifies the balance matches first. Returns the number locked in.
Balance of the committed tier (locked by past reconciliations).
Every finalized reconciliation for an account, oldest first.
Build, validate, persist, and return a transaction. Raises Error if the
postings don't balance.
Re-apply the change most recently removed by undo_last. Returns it, or
nil if there's nothing to redo.
Rewrite every posting on from to to (also updating the chart and any
budget keyed on it). Doubles as a merge when to already exists. Returns
the number of postings rewritten.
Correct an older change the proper accounting way: append a reversing
entry. The original is never removed — transactions it added are negated by
mirror-image postings, budget changes restored. Returns the reversing
changeset, nil if id is unknown, or raises if it's already reversed.
Mark (or unmark) transactions as cleared against account. Reconciliation
is bookkeeping metadata, not a ledger change, so it isn't journaled for
undo. Returns the number of ids whose state actually changed.
Net movement into an account subtree within a "YYYY-MM" month. For an Expenses account this is the amount spent.
Remove an account from the chart. Returns false if it wasn't declared. (If postings still reference it, it stays "known" via use.)
Undo the most recent change by removing it outright — as if it never happened. Safe precisely because it's the last change: nothing follows it. Returns the removed changeset, or nil if there's nothing to undo.
Remove a metadata key. Returns false if it wasn't set.