Skip to main content

Ledger

Struct Ledger 

Source
pub struct Ledger { /* private fields */ }
Expand description

A fully processed multi-file ledger for queries and validation.

Use this class for ledgers that span multiple files with include directives. Caches the processed result for efficient repeated queries.

For single-file ledgers with editor features, use ParsedLedger instead.

§Example (JavaScript)

const ledger = Ledger.fromFiles({
    "main.beancount": 'include "accounts.beancount"\n...',
    "accounts.beancount": "2024-01-01 open Assets:Bank USD\n..."
}, "main.beancount");

if (ledger.isValid()) {
    const balances = ledger.query("BALANCES");
    const completions = ledger.getCompletions(currentSource, line, char);
}

Implementations§

Source§

impl Ledger

Source

pub fn from_files(files: JsValue, entry_point: &str) -> Result<Self, JsError>

Create a Ledger from multiple files with include resolution.

Loads and runs the same processing pipeline as the CLI: sort → synth-plugins → Early validation → book → regular-plugins → Late validation → finalize.

§Arguments
  • files - A JavaScript object mapping file paths to their contents.
  • entry_point - The main file to start loading from (must exist in files).
Source

pub fn is_valid(&self) -> bool

Check if the ledger is valid (no errors).

Source

pub fn get_errors(&self) -> Result<JsValue, JsError>

Get all errors.

Source

pub fn get_directives(&self) -> Result<JsValue, JsError>

Get the parsed directives.

Source

pub fn get_options(&self) -> Result<JsValue, JsError>

Get the ledger options.

Source

pub fn directive_count(&self) -> usize

Get the number of directives.

Source

pub fn query(&self, query_str: &str) -> Result<JsValue, JsError>

Run a BQL query on this ledger.

Source

pub fn balances(&self) -> Result<JsValue, JsError>

Get account balances (shorthand for query(“BALANCES”)).

Source

pub fn expand_pads(&self) -> Result<JsValue, JsError>

Expand pad directives.

Source

pub fn run_plugin(&self, plugin_name: &str) -> Result<JsValue, JsError>

Run a native plugin on this ledger.

Source

pub fn get_completions( &self, source: &str, line: u32, character: u32, ) -> Result<JsValue, JsError>

Get completions for a source string using cross-file data.

Pass the source text of the file currently being edited. Completions use accounts, currencies, and payees from all loaded files.

Source

pub fn serialize(&self) -> Result<Vec<u8>, JsError>

Serialize this ledger to a compact binary blob (rkyv).

Store the bytes in OPFS or IndexedDB alongside a source fingerprint (see crate::hash_sources) and restore later with Ledger::from_cache.

Source

pub fn from_cache(bytes: &[u8]) -> Result<Self, JsError>

Restore a Ledger from bytes produced by Ledger::serialize.

§Errors

Returns an error if the bytes are invalid or were produced by a different library version.

Trait Implementations§

Source§

impl From<Ledger> for JsValue

Source§

fn from(value: Ledger) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for Ledger

Source§

type Abi = WasmPtr<WasmRefCell<Ledger>>

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: Self::Abi) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for Ledger

Source§

type Abi = WasmPtr<WasmRefCell<Ledger>>

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> Self::Abi

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for Ledger

Source§

type Abi = WasmPtr<WasmRefCell<Ledger>>

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<Ledger>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for Ledger

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for Ledger

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for Ledger

Source§

type Abi = WasmPtr<WasmRefCell<Ledger>>

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<Ledger>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for Ledger

Source§

type Abi = WasmPtr<WasmRefCell<Ledger>>

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<Ledger>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl SupportsConstructor for Ledger

Source§

impl SupportsInstanceProperty for Ledger

Source§

impl SupportsStaticProperty for Ledger

Source§

impl TryFromJsValue for Ledger

Source§

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.
Source§

impl VectorFromWasmAbi for Ledger

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Ledger]>

Source§

impl VectorIntoWasmAbi for Ledger

Source§

type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi

Source§

fn vector_into_abi(vector: Box<[Ledger]>) -> Self::Abi

Source§

impl WasmDescribe for Ledger

Source§

impl WasmDescribeVector for Ledger

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more