import { token } from "@conusai-kit/core" import type { AccountView, BalanceView, EntryView, RecordTerms, TransactionView, VerificationView, } from "../contract/index.js" export interface Page { rows: T[] after?: string } export interface LedgerReads { accounts(after?: string): Promise> account(id: string): Promise balances(accountId?: string, after?: string): Promise> entries(accountId: string, after?: string): Promise> transactions(after?: string): Promise> transaction(id: string): Promise verify(): Promise } export interface LedgerService extends LedgerReads { createAccount(input: Omit, key: string): Promise updateAccount( id: string, input: Pick, revision: string, key: string, ): Promise record(terms: RecordTerms, key: string): Promise transition(action: "post" | "void" | "reverse", id: string, revision: string, key: string): Promise } 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("ledger.service", { views: { read: readsOf, write: readsOf } })