Skip to content

calternal_plugin_money::import

Privacy-preserving adapters from Actual and YNAB exports to Money files.

This module turns untrusted export bytes into the shared Money import model. The server streams Actual’s expanded database to a private calternal-fs file and queries it read-only; small adapter tests may use SQLite memory mode. Errors and progress expose no source values (#462, DESIGN §48). YNAB checks parent and child source identities before any conversion; equal rows merge and conflicting ownership or fields reject (#948). Transfer verification retains raw monthly postings before FIFO normalization; reciprocal legs cannot move between months (#949). #1130 keeps closed Accounts, exact separate notes, independent status marks and source goal text. Suspected Cards without a source type require a reviewed choice.

Source: crates/plugins/money/src/import.rs

pub struct ImportControl(Arc<ImportControlState>);

Cancellation and safe progress shared by one API import job.

Implements: Clone, Default

pub fn set_account_kinds(&self, choices: HashMap<String, String>) -> Result<()>

Apply explicit Cash/Card choices before parsing; off-budget status is source-authoritative and cannot be changed by this review (#1130).

pub fn new() -> Self

Start a bounded five-minute import job with an initial progress phase.

pub fn cancel(&self)

Mark the job cancelled. The next parser or renderer checkpoint stops it.

pub fn check(&self) -> Result<()>

Check cancellation and the fixed execution budget without changing progress.

pub fn report(
&self,
stage: &str,
completed: usize,
total: Option<usize>,
unit: &str,
) -> Result<()>

Publish one phase checkpoint and stop if the User cancelled or time ran out.

pub fn progress(&self) -> ImportProgress

Read the latest safe phase for the owner-scoped progress route.

Source: crates/plugins/money/src/import.rs:59

pub struct ImportProgress

Safe import progress. It contains counts and a phase only, never source names, amounts or row values (#462, DESIGN §48).

Implements: Clone, Debug, Serialize, ToSchema

Source: crates/plugins/money/src/import.rs:71

pub async fn actual_zip(_bytes: &[u8], _title: &str) -> Result<ImportSource>

Import a small Actual export ZIP using SQLite memory mode for adapter tests.

The live server uses actual_zip_with_root_and_control so expanded database bytes never become a whole-database application allocation. ZIP paths, entry counts and expanded sizes are checked before SQLite reads rows (#462, DESIGN §48).

Source: crates/plugins/money/src/import.rs:982

actual_zip_plan_staged_with_root_and_control

Section titled “actual_zip_plan_staged_with_root_and_control”
pub async fn actual_zip_plan_staged_with_root_and_control(
bytes: &[u8],
title: &str,
budget_id: &str,
control: &ImportControl,
root: &calternal_fs::Root,
sink: &mut dyn ImportFileSink,
) -> Result<ImportPlan>

Parse Actual into private staged files so the live route keeps only the preview summary and bounded SQLite row state in memory (#462, DESIGN §48).

Source: crates/plugins/money/src/import.rs:1045

pub async fn actual_zip_plan_with_control(
bytes: &[u8],
title: &str,
budget_id: &str,
control: &ImportControl,
) -> Result<ImportPlan>

Parse and stream an Actual archive through SQLite memory mode for adapter regression tests. Production uses the private scratch-file variant above so expanded SQLite bytes do not become an application allocation (#462, DESIGN §48).

Source: crates/plugins/money/src/import.rs:1075

pub async fn actual_zip_plan_with_root_and_control(
bytes: &[u8],
title: &str,
budget_id: &str,
control: &ImportControl,
root: &calternal_fs::Root,
) -> Result<ImportPlan>

Parse, verify and render an Actual import without retaining its normalized transaction list. The caller supplies the stable Budget ID before the stream starts so every month file shares one identity (#462, DESIGN §48).

Source: crates/plugins/money/src/import.rs:1028

pub async fn actual_zip_with_control(
_bytes: &[u8],
_title: &str,
control: &ImportControl,
) -> Result<ImportSource>

Import an Actual archive while exposing row progress and cooperative cancel checkpoints to the authenticated route (#462, DESIGN §48).

Source: crates/plugins/money/src/import.rs:988

pub async fn actual_zip_with_root_and_control(
_bytes: &[u8],
_title: &str,
control: &ImportControl,
root: &calternal_fs::Root,
) -> Result<ImportSource>

Import an Actual archive through a private calternal-fs scratch file.

The HTTP route uses this path so the expanded SQLite database is streamed to private scratch storage, then queried read-only. The file is unlinked after the connection closes, including cancellation and error paths (#462, DESIGN §48).

Source: crates/plugins/money/src/import.rs:1008

pub fn ynab_api_json(_bytes: &[u8], _title: &str) -> Result<ImportSource>

Import YNAB’s budget-detail API JSON into the shared normalized model.

Milliunits are converted with checked integer arithmetic; no floating point value participates in an amount (#462, DESIGN §48). The API’s data.plan wrapper and the public YNAB5 fixture’s root budget object use the same source fields after selecting the budget object.

Source: crates/plugins/money/src/import.rs:4026

pub fn ynab_api_json_with_control(
_bytes: &[u8],
_title: &str,
control: &ImportControl,
) -> Result<ImportSource>

Parse YNAB’s API JSON with safe progress and cooperative cancellation checkpoints (#462, DESIGN §48).

Source: crates/plugins/money/src/import.rs:4032

pub fn ynab_csv(
plan_bytes: &[u8],
register_bytes: &[u8],
currency: &str,
title: &str,
) -> Result<ImportSource>

Read YNAB’s Plan and Register tables into the shared import model.

Both UTF-8 CSV and tab-separated exports are accepted. Decimal commas are accepted only in tab-separated files, where comma grouping is unambiguous. Register rows are authoritative for activity; Plan rows supply assignments.

Source: crates/plugins/money/src/import.rs:179

pub fn ynab_csv_with_control(
plan_bytes: &[u8],
register_bytes: &[u8],
currency: &str,
title: &str,
control: &ImportControl,
) -> Result<ImportSource>

Parse the two YNAB CSV tables with bounded progress and cancel checkpoints (#462, DESIGN §48).

Source: crates/plugins/money/src/import.rs:196