0.1.4Updated 6 months ago
declare namespace Ledger {

  type Events = {
    /**
     * Event for adding an entry to the ledger.
     * 
     * @param entry_values All values passed to the creation of the new entry
     */
    'ledger created': [Ledger.Ledger<any>]
  
    /**
     * Event for adding an entry to the ledger.
     * 
     * @param entry_values All values passed to the creation of the new entry
     */
    'entry_created': [entry: Omit<Ledger.Entry, 'id' | 'timestamp'>]
  
    /**
     * Event for adding an entry to the ledger.
     * 
     * @param reason Why this entry could not be created
     */
    'entry_creation_failed': [reason: string, entry: Omit<Ledger.Entry, 'id' | 'timestamp'>]
  
    /**
     * Runs before a consumption is added to the ledger. Cancelable.
     * 
     * @param params The information that will be used to create the consumption entry
     * @param fail Call this with `true` to cancel the consumption event.
     */
    'before-consumption': [params: Ledger.Consumption.Entry, fail: Events.FailMethod, after_consumption: (cb: () => void | Promise<void>) => void]
  
    /**
     * Runs after a consumption has been added to the ledger.
     * 
     * @param consumption_data The ID of the new entry, and data about the altered entries
     * @param params The information that was used to create the consumption entry
     */
    'consumption': [consumption_data: Ledger.Consumption.Function.Response, params: Ledger.Consumption.Entry]
  }

  namespace Events {
    type FailMethod = (reason?: string) => void
  }
}