0.1.4•Updated 6 months ago
declare namespace Ledger {
interface Ledger<EntityName extends string> {
readonly REST: import("@ledger/mod.ts").LedgerRest<EntityName>
/**
* Add a new entry to the ledger.
* Updates the user balance and updates the ledger meta.
*
* *Runs on a processor*
*/
AddEntry(params: Ledger.Entry.Unentered & Ledger.Expiration.Override): Promise<Ledger.Entry.Response>
/**
* Consume from positive past entries linked to a specific user.
* Updates the user balance and updates the ledger meta.
*
* *Runs on a processor*
*/
ConsumeEntries(params: Ledger.Entry.Unentered): Promise<Ledger.Consumption.ConsumptionResponse>
/**
* Get recent entries to the ledger history
*/
History(count: number, page: number): Promise<Ledger.Entry[]>
/**
* Fetch ledger data for a particular user
*
* @param key The unique value referring to a user. Usually their `msisdn`
*/
UserData(key: string, count: number, page: number): Promise<Ledger.User.Response>
/**
* Get the ledger history for a user
*
* @param key The unique value referring to a user. Usually their `msisdn`
* @param limit How many entries should be retrieved?
*
* Default: 10
*/
HistoryFor(key: string, count: number, page: number): void
/**
* Get information regarding an entry, including consumption entries
*
* @param key The unique value referring to a user. Usually their `msisdn`
* @param limit How many entries should be retrieved?
*
* Default: 10
*/
EntryData(id: number): void
/**
* Get the total balance for a user
*
* @param key The unique value referring to a user. Usually their `msisdn`
*/
BalanceFor(key: string): Promise<number | undefined>
/**
* Get the total balance for multiple user
*
* @param keys The unique values used to refer to a user. Usually their `msisdn`
*/
Balances(...keys: string[]): Promise<Pick<User, 'key' | 'balance'>[]>
/**
* Get the amount of ledger entries for a user
*
* @param key The unique value referring to a user. Usually their `msisdn`
*/
CountFor(key: string): Promise<number | undefined>
/**
* Get the total number of users that have been tracked in this ledger.
*
* A user is only tracked once an entry has been added for them.
*/
UserCount(): Promise<number>
/**
* The name of the database table where this ledger stores entries
*/
entries_table: string
/**
* The name of the database table where this ledger stores user data
*/
user_table: string
/**
* The name of the database table where this ledger records consumptions
*/
consumption_table: string
}
}