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
impl Ledger
Sourcepub fn from_files(files: JsValue, entry_point: &str) -> Result<Self, JsError>
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 infiles).
Sourcepub fn get_errors(&self) -> Result<JsValue, JsError>
pub fn get_errors(&self) -> Result<JsValue, JsError>
Get all errors.
Sourcepub fn get_directives(&self) -> Result<JsValue, JsError>
pub fn get_directives(&self) -> Result<JsValue, JsError>
Get the parsed directives.
Sourcepub fn get_options(&self) -> Result<JsValue, JsError>
pub fn get_options(&self) -> Result<JsValue, JsError>
Get the ledger options.
Sourcepub fn directive_count(&self) -> usize
pub fn directive_count(&self) -> usize
Get the number of directives.
Sourcepub fn query(&self, query_str: &str) -> Result<JsValue, JsError>
pub fn query(&self, query_str: &str) -> Result<JsValue, JsError>
Run a BQL query on this ledger.
Sourcepub fn balances(&self) -> Result<JsValue, JsError>
pub fn balances(&self) -> Result<JsValue, JsError>
Get account balances (shorthand for query(“BALANCES”)).
Sourcepub fn expand_pads(&self) -> Result<JsValue, JsError>
pub fn expand_pads(&self) -> Result<JsValue, JsError>
Expand pad directives.
Sourcepub fn run_plugin(&self, plugin_name: &str) -> Result<JsValue, JsError>
pub fn run_plugin(&self, plugin_name: &str) -> Result<JsValue, JsError>
Run a native plugin on this ledger.
Sourcepub fn get_completions(
&self,
source: &str,
line: u32,
character: u32,
) -> Result<JsValue, JsError>
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.
Sourcepub fn serialize(&self) -> Result<Vec<u8>, JsError>
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.
Sourcepub fn from_cache(bytes: &[u8]) -> Result<Self, JsError>
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 FromWasmAbi for Ledger
impl FromWasmAbi for Ledger
Source§impl IntoWasmAbi for Ledger
impl IntoWasmAbi for Ledger
Source§impl LongRefFromWasmAbi for Ledger
impl LongRefFromWasmAbi for Ledger
Source§impl OptionFromWasmAbi for Ledger
impl OptionFromWasmAbi for Ledger
Source§impl OptionIntoWasmAbi for Ledger
impl OptionIntoWasmAbi for Ledger
Source§impl RefFromWasmAbi for Ledger
impl RefFromWasmAbi for Ledger
Source§type Abi = WasmPtr<WasmRefCell<Ledger>>
type Abi = WasmPtr<WasmRefCell<Ledger>>
Self are recovered from.Source§impl RefMutFromWasmAbi for Ledger
impl RefMutFromWasmAbi for Ledger
impl SupportsConstructor for Ledger
impl SupportsInstanceProperty for Ledger
impl SupportsStaticProperty for Ledger
Source§impl TryFromJsValue for Ledger
impl TryFromJsValue for Ledger
Source§impl VectorFromWasmAbi for Ledger
impl VectorFromWasmAbi for Ledger
Source§impl VectorIntoWasmAbi for Ledger
impl VectorIntoWasmAbi for Ledger
Auto Trait Implementations§
impl Freeze for Ledger
impl RefUnwindSafe for Ledger
impl Send for Ledger
impl Sync for Ledger
impl Unpin for Ledger
impl UnsafeUnpin for Ledger
impl UnwindSafe for Ledger
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.