/** * Postgres-backed SpendStore + DecisionLogStore. * * Install: `npm install @agentguard-run/spend pg` * * UPSERT semantics for window spend. Append-only decision log table * with UNIQUE(signer_fingerprint, sequence) for crash-safe chain ordering. * * @example * import { Pool } from 'pg'; * import { * PostgresSpendStore, PostgresDecisionLogStore, ensureSchema, * } from '@agentguard-run/spend/dist/adapters/postgres-store'; * * const pool = new Pool({ connectionString: process.env.DATABASE_URL }); * await ensureSchema(pool); * const config = { * policy, * spendStore: new PostgresSpendStore(pool), * logStore: new PostgresDecisionLogStore(pool), * signingKeys: { privateKey, publicKey }, * }; */ import type { SignedDecisionLogEntry, SpendStore, DecisionLogStore, SpendWindow } from '../types'; type PoolLike = { query(text: string, params?: any[]): Promise<{ rows: any[]; rowCount: number | null; }>; }; /** Create the required tables/indexes if they don't exist. Idempotent. */ export declare function ensureSchema(pool: PoolLike): Promise; export declare class PostgresSpendStore implements SpendStore { private pool; constructor(pool: PoolLike); getWindowSpend(scopeKey: string, window: SpendWindow): Promise; incrementWindowSpend(scopeKey: string, window: SpendWindow, cents: number): Promise; reserveWindowSpend(scopeKey: string, window: SpendWindow, cents: number, limitCents: number): Promise<{ allowed: boolean; before: number; after: number; }>; settleWindowSpend(scopeKey: string, window: SpendWindow, deltaCents: number): Promise; } export declare class PostgresDecisionLogStore implements DecisionLogStore { private pool; constructor(pool: PoolLike); append(entry: SignedDecisionLogEntry): Promise; getLatest(signerFingerprint?: string): Promise; read(fromSequence: number, limit: number, signerFingerprint?: string): Promise; } export {}; //# sourceMappingURL=postgres-store.d.ts.map