@@ -0,0 +1,43 @@
|
||||
import { token } from "@conusai-kit/core"
|
||||
import type {
|
||||
AccountView,
|
||||
BalanceView,
|
||||
EntryView,
|
||||
RecordTerms,
|
||||
TransactionView,
|
||||
VerificationView,
|
||||
} from "../contract/index.js"
|
||||
export interface Page<T> {
|
||||
rows: T[]
|
||||
after?: string
|
||||
}
|
||||
export interface LedgerReads {
|
||||
accounts(after?: string): Promise<Page<AccountView>>
|
||||
account(id: string): Promise<AccountView>
|
||||
balances(accountId?: string, after?: string): Promise<Page<BalanceView>>
|
||||
entries(accountId: string, after?: string): Promise<Page<EntryView>>
|
||||
transactions(after?: string): Promise<Page<TransactionView>>
|
||||
transaction(id: string): Promise<TransactionView>
|
||||
verify(): Promise<VerificationView>
|
||||
}
|
||||
export interface LedgerService extends LedgerReads {
|
||||
createAccount(input: Omit<AccountView, "accountId" | "revision" | "status">, key: string): Promise<AccountView>
|
||||
updateAccount(
|
||||
id: string,
|
||||
input: Pick<AccountView, "name" | "status" | "allowNegative">,
|
||||
revision: string,
|
||||
key: string,
|
||||
): Promise<AccountView>
|
||||
record(terms: RecordTerms, key: string): Promise<TransactionView>
|
||||
transition(action: "post" | "void" | "reverse", id: string, revision: string, key: string): Promise<TransactionView>
|
||||
}
|
||||
export const readsOf = (service: LedgerReads): LedgerReads => ({
|
||||
accounts: (after) => service.accounts(after),
|
||||
account: (id) => service.account(id),
|
||||
balances: (id, after) => service.balances(id, after),
|
||||
entries: (id, after) => service.entries(id, after),
|
||||
transactions: (after) => service.transactions(after),
|
||||
transaction: (id) => service.transaction(id),
|
||||
verify: () => service.verify(),
|
||||
})
|
||||
export const LEDGER_SERVICE = token<LedgerService>("ledger.service", { views: { read: readsOf, write: readsOf } })
|
||||
Reference in New Issue
Block a user