/** * PostgreSQL-backed cross-replica per-key CUMULATIVE cost quota — the PG twin of {@link TiDBCostQuota} * (src/plugins/tidb-cost-quota.ts). Behaviourally identical (same {@link QuotaTracker} surface, same * SOFT/eventual-consistency write-behind semantics: atomic `micro = micro + delta` per aligned window * bucket), PostgreSQL dialect instead of MySQL/TiDB. The two are kept in lock-step by ONE shared real-DB * integration suite (test/pg-cost-quota-integration.test.ts) running the SAME scenarios on BOTH engines. * * [ref] A12 C1b: this file used to carry a PRIVATE inline copy of the write-behind counter, hardwired * to the `cost_quota` columns — the third copy of the same 150 lines. It is gone; both dialects now share * ONE dialect-parameterized implementation (write-behind-counter.ts), and the dialect deltas this header * used to enumerate ($n placeholders / ON CONFLICT increment / rowCount / BIGINT-as-string) are documented * and branched THERE. Only the table binding lives here. */ import type { Pool, PoolClient } from "pg"; import type { QuotaDecision, QuotaLimits, QuotaTracker } from "../observability/cost-quota.js"; import { type CounterDegradeHook } from "./write-behind-counter.js"; import { type IndexSpec } from "./ensure-index.js"; export declare class PgCostQuota implements QuotaTracker { private readonly counter; /** [ref]:与 TiDB 孪生逐字同语义(限额=比较参数;关断哨兵零 SQL;窗长换代=换桶)。 */ private limitMicroUsd; private refreshRequested; private refreshIntervalMs; constructor(pool: Pool, limitMicroUsd: number, windowMs: number, now?: () => number, onDegraded?: CounterDegradeHook, queryTimeoutMs?: number); setLimits(next: QuotaLimits): void; private syncRefresh; check(scopeKey: string): QuotaDecision; add(scopeKey: string, micro: number): void; flush(): Promise; refresh(): Promise; reap(): Promise; startRefresh(intervalMs?: number): this; stop(): void; } /** PG DDL for the `cost_quota` table (translated from tidb-pool.ts SCHEMA_STATEMENTS: BIGINT same, * DATETIME(3)→TIMESTAMPTZ(3), inline `KEY idx_window`→separate CREATE INDEX). DISJOINT from other stores' * tables, so a self-contained ensureSchema is safe (the central pg-pool aggregation is done separately). */ export declare const PG_COST_QUOTA_SCHEMA: string[]; /** S-287:本 store 的索引**声明**(两方言共用一份)。PG 侧由下面的 `ensureSchema` 应用,MySQL 侧由 `tidb-pool.ts` 的中央 `ensureSchema` 应用(那里内联 `KEY` 已在 `CREATE TABLE` 里 ⇒ 新建库探到即零 DDL,存量库缺谁补谁)。加索引以外的 schema 变更仍归运维,见 `plugins/ensure-index.ts` 头注。 */ export declare const COST_QUOTA_INDEXES: readonly IndexSpec[]; /** Idempotent schema apply for the cost_quota table (the PG twin of tidb-pool.ts ensureSchema). */ export declare function ensureSchema(pool: Pool | PoolClient): Promise; //# sourceMappingURL=pg-cost-quota.d.ts.map