/** * @pwngh/economy-lab * * Copyright (c) Preston Neal * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import type { Posting } from '../ports.js'; import type { Link } from './sql-shared.js'; /** * Selects which placeholder style the routines emit. Postgres uses `$1,$2,...` and MySQL uses * `?,?,...`. * * @see {@link https://economy-lab-docs.pages.dev/economy/ports/storage/ Storage} for the stored-routine boundary. */ export type SqlDialect = 'postgres' | 'mysql'; /** * Runs SQL with positional params and returns the rows. Each engine wraps its driver to this * shape (Postgres `pool.query`, MySQL `rows()`), so the routines below are written once for both * backends. */ export type SqlQuery = (sql: string, params: ReadonlyArray) => Promise<{ rows: ReadonlyArray>; }>; export declare function callProcedure(query: SqlQuery, dialect: SqlDialect, name: string, args: ReadonlyArray): Promise; export declare function callFunction(query: SqlQuery, dialect: SqlDialect, name: string, args: ReadonlyArray): Promise; /** * Persistence-only arguments for the `post_entry` procedure. The business decisions stay in TS: the * direction per account (`balanceDelta`), the net delta summed across a posting's legs that touch * one account, the first-time user-account kind, and the currency. The procedure only writes rows. * bigints are carried as strings so the JSON keeps full precision past 2^53. */ export interface PostEntryArgs { legs: Array<{ account: string; currency: string; amount: string; }>; links: Array<{ account: string; prev_hash: string; hash: string; }>; balances: Array<{ account: string; currency: string; delta: string; }>; newAccounts: Array<{ id: string; kind: string; currency: string; }>; } /** * Turns a posting and its pre-computed chain links into the {@link PostEntryArgs} the `post_entry` * procedure persists — the one place the per-account math lives. */ export declare function postEntryArgs(posting: Posting, links: ReadonlyArray): PostEntryArgs;