@agentbadge/database 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ import type { PrismaDb } from "./event-repository.js";
2
+ import type { ArchiveCursorCommit, ArchiveCursorRecord, ArchiveCursorStore } from "./archive-cursor-store.js";
3
+ export declare class ArchiveCursorRepository implements ArchiveCursorStore {
4
+ private readonly db;
5
+ constructor(db: PrismaDb);
6
+ getCursor(stream: string): Promise<ArchiveCursorRecord | null>;
7
+ commitCursor(stream: string, commit: ArchiveCursorCommit): Promise<void>;
8
+ }
@@ -0,0 +1,38 @@
1
+ export class ArchiveCursorRepository {
2
+ db;
3
+ constructor(db) {
4
+ this.db = db;
5
+ }
6
+ async getCursor(stream) {
7
+ const r = await this.db.orm.public.ArchiveCursor.where({ stream }).first();
8
+ if (!r)
9
+ return null;
10
+ return {
11
+ stream: r.stream,
12
+ throughAt: BigInt(r.throughAt),
13
+ lastMessageId: r.lastMessageId === null || r.lastMessageId === undefined
14
+ ? null
15
+ : BigInt(r.lastMessageId),
16
+ note: r.note ?? null,
17
+ updatedAt: r.updatedAt,
18
+ };
19
+ }
20
+ async commitCursor(stream, commit) {
21
+ const patch = {
22
+ throughAt: commit.throughAt,
23
+ lastMessageId: (commit.messageId ?? null),
24
+ note: (commit.note ?? null),
25
+ };
26
+ const existing = await this.db.orm.public.ArchiveCursor.where({
27
+ stream,
28
+ }).first();
29
+ if (existing) {
30
+ await this.db.orm.public.ArchiveCursor.where({ stream }).update(patch);
31
+ return;
32
+ }
33
+ await this.db.orm.public.ArchiveCursor.create({
34
+ stream,
35
+ ...patch,
36
+ });
37
+ }
38
+ }
@@ -0,0 +1,21 @@
1
+ export interface ArchiveCursorRecord {
2
+ stream: string;
3
+ throughAt: bigint;
4
+ lastMessageId: bigint | null;
5
+ note: string | null;
6
+ updatedAt: string;
7
+ }
8
+ export interface ArchiveCursorCommit {
9
+ throughAt: bigint;
10
+ messageId?: bigint | null;
11
+ note?: string | null;
12
+ }
13
+ export interface ArchiveCursorStore {
14
+ getCursor(stream: string): Promise<ArchiveCursorRecord | null>;
15
+ commitCursor(stream: string, commit: ArchiveCursorCommit): Promise<void>;
16
+ }
17
+ export declare class InMemoryArchiveCursorStore implements ArchiveCursorStore {
18
+ private rows;
19
+ getCursor(stream: string): Promise<ArchiveCursorRecord | null>;
20
+ commitCursor(stream: string, commit: ArchiveCursorCommit): Promise<void>;
21
+ }
@@ -0,0 +1,16 @@
1
+ export class InMemoryArchiveCursorStore {
2
+ rows = new Map();
3
+ async getCursor(stream) {
4
+ const r = this.rows.get(stream);
5
+ return r ? { ...r } : null;
6
+ }
7
+ async commitCursor(stream, commit) {
8
+ this.rows.set(stream, {
9
+ stream,
10
+ throughAt: commit.throughAt,
11
+ lastMessageId: commit.messageId ?? null,
12
+ note: commit.note ?? null,
13
+ updatedAt: new Date().toISOString(),
14
+ });
15
+ }
16
+ }
@@ -0,0 +1,22 @@
1
+ import type { EconomicEvent } from "@agentbadge/econ-events";
2
+ import type { PrismaDb } from "./event-repository.js";
3
+ import { type AppendResult, type EconEventStored, type EconLedgerStore, type ListOpts } from "./econ-ledger-store.js";
4
+ import { type TrustEdgeStore } from "./trust-edge-store.js";
5
+ type Orm = PrismaDb["orm"];
6
+ export declare class EconLedgerRepository implements EconLedgerStore<Orm> {
7
+ private readonly db;
8
+ private readonly edges?;
9
+ constructor(db: PrismaDb, edges?: TrustEdgeStore<Orm> | undefined);
10
+ append(events: EconomicEvent[]): Promise<AppendResult[]>;
11
+ appendInTx(events: EconomicEvent[], extra: (tx: Orm) => Promise<void>): Promise<AppendResult[]>;
12
+ getById(id: string): Promise<EconEventStored | null>;
13
+ getByKey(idempotencyKey: string): Promise<EconEventStored | null>;
14
+ listByAgent(agent: string, opts?: ListOpts): Promise<EconEventStored[]>;
15
+ listByPair(a: string, b: string, opts?: ListOpts): Promise<EconEventStored[]>;
16
+ listBySourceId(source: string, sourceId: string, opts?: ListOpts): Promise<EconEventStored[]>;
17
+ scan(fromLedgerSeq: bigint, opts?: {
18
+ limit?: number;
19
+ }): Promise<EconEventStored[]>;
20
+ private page;
21
+ }
22
+ export {};
@@ -0,0 +1,138 @@
1
+ import { guardEventsForAppend, rowToStored, } from "./econ-ledger-store.js";
2
+ import { deltasOfAppended } from "./trust-edge-store.js";
3
+ function toCreate(e) {
4
+ return {
5
+ id: e.id,
6
+ spec: e.spec,
7
+ source: e.source,
8
+ sourceId: e.sourceId,
9
+ seq: e.seq,
10
+ kind: e.kind,
11
+ actor: e.actor,
12
+ counterparty: e.counterparty ?? null,
13
+ amountUsdc: (e.amountUsdc ?? null),
14
+ at: e.at,
15
+ idempotencyKey: e.idempotencyKey,
16
+ payload: e.payload,
17
+ };
18
+ }
19
+ function isUniqueViolation(err) {
20
+ const m = err instanceof Error ? err.message : String(err);
21
+ return /unique|duplicate/i.test(m);
22
+ }
23
+ export class EconLedgerRepository {
24
+ db;
25
+ edges;
26
+ constructor(db, edges) {
27
+ this.db = db;
28
+ this.edges = edges;
29
+ }
30
+ async append(events) {
31
+ try {
32
+ return await this.appendInTx(events, async () => { });
33
+ }
34
+ catch (err) {
35
+ if (!isUniqueViolation(err))
36
+ throw err;
37
+ return this.appendInTx(events, async () => { });
38
+ }
39
+ }
40
+ async appendInTx(events, extra) {
41
+ guardEventsForAppend(events);
42
+ return this.db.transaction(async (tx) => {
43
+ const out = [];
44
+ for (const e of events) {
45
+ const existing = await tx.orm.public.EconomicEvent.where({
46
+ idempotencyKey: e.idempotencyKey,
47
+ }).first();
48
+ if (existing) {
49
+ out.push({
50
+ event: rowToStored(existing).event,
51
+ ledgerSeq: BigInt(existing.ledgerSeq),
52
+ duplicate: true,
53
+ });
54
+ continue;
55
+ }
56
+ const row = await tx.orm.public.EconomicEvent.create(toCreate(e));
57
+ out.push({ event: e, ledgerSeq: BigInt(row.ledgerSeq), duplicate: false });
58
+ }
59
+ if (this.edges) {
60
+ const deltas = deltasOfAppended(out);
61
+ if (deltas.length > 0)
62
+ await this.edges.applyDeltasTx(tx.orm, deltas);
63
+ }
64
+ await extra(tx.orm);
65
+ return out;
66
+ });
67
+ }
68
+ async getById(id) {
69
+ const row = await this.db.orm.public.EconomicEvent.where({ id }).first();
70
+ return row ? rowToStored(row) : null;
71
+ }
72
+ async getByKey(idempotencyKey) {
73
+ const row = await this.db.orm.public.EconomicEvent.where({
74
+ idempotencyKey,
75
+ }).first();
76
+ return row ? rowToStored(row) : null;
77
+ }
78
+ async listByAgent(agent, opts) {
79
+ const [asActor, asCparty] = await Promise.all([
80
+ this.db.orm.public.EconomicEvent.where({ actor: agent }).all(),
81
+ this.db.orm.public.EconomicEvent.where({ counterparty: agent }).all(),
82
+ ]);
83
+ return this.page(dedupeMerge(asActor, asCparty), opts);
84
+ }
85
+ async listByPair(a, b, opts) {
86
+ const [ab, ba] = await Promise.all([
87
+ this.db.orm.public.EconomicEvent.where({ actor: a, counterparty: b }).all(),
88
+ this.db.orm.public.EconomicEvent.where({ actor: b, counterparty: a }).all(),
89
+ ]);
90
+ return this.page(dedupeMerge(ab, ba), opts);
91
+ }
92
+ async listBySourceId(source, sourceId, opts) {
93
+ const rows = await this.db.orm.public.EconomicEvent.where({
94
+ source,
95
+ sourceId,
96
+ }).all();
97
+ let out = rows
98
+ .map(rowToStored)
99
+ .filter((s) => opts?.beforeLedgerSeq === undefined ||
100
+ s.ledgerSeq < opts.beforeLedgerSeq)
101
+ .sort((x, y) => x.ledgerSeq < y.ledgerSeq ? -1 : x.ledgerSeq > y.ledgerSeq ? 1 : 0);
102
+ if (opts?.limit !== undefined)
103
+ out = out.slice(0, opts.limit);
104
+ return out;
105
+ }
106
+ async scan(fromLedgerSeq, opts) {
107
+ const rows = await this.db.orm.public.EconomicEvent
108
+ .orderBy((e) => e.ledgerSeq.asc())
109
+ .all();
110
+ let out = rows
111
+ .filter((r) => BigInt(r.ledgerSeq) >= fromLedgerSeq)
112
+ .map(rowToStored);
113
+ if (opts?.limit !== undefined)
114
+ out = out.slice(0, opts.limit);
115
+ return out;
116
+ }
117
+ page(rows, opts) {
118
+ let out = rows
119
+ .map(rowToStored)
120
+ .filter((s) => opts?.beforeLedgerSeq === undefined ||
121
+ s.ledgerSeq < opts.beforeLedgerSeq)
122
+ .sort((x, y) => x.ledgerSeq > y.ledgerSeq ? -1 : x.ledgerSeq < y.ledgerSeq ? 1 : 0);
123
+ if (opts?.limit !== undefined)
124
+ out = out.slice(0, opts.limit);
125
+ return out;
126
+ }
127
+ }
128
+ function dedupeMerge(a, b) {
129
+ const seen = new Set();
130
+ const out = [];
131
+ for (const r of [...a, ...b]) {
132
+ if (seen.has(r.idempotencyKey))
133
+ continue;
134
+ seen.add(r.idempotencyKey);
135
+ out.push(r);
136
+ }
137
+ return out;
138
+ }
@@ -0,0 +1,53 @@
1
+ import { type EconomicEvent } from "@agentbadge/econ-events";
2
+ import type { Models } from "../prisma/contract.d.js";
3
+ import { type TrustEdgeDelta } from "./trust-edge-store.js";
4
+ export type EconEventDbRow = Models.public_EconomicEvent;
5
+ export interface EconEventStored {
6
+ ledgerSeq: bigint;
7
+ event: EconomicEvent;
8
+ createdAtMs: bigint;
9
+ }
10
+ export interface AppendResult {
11
+ event: EconomicEvent;
12
+ ledgerSeq: bigint;
13
+ duplicate: boolean;
14
+ }
15
+ export interface ListOpts {
16
+ beforeLedgerSeq?: bigint;
17
+ limit?: number;
18
+ }
19
+ export interface EconLedgerStore<TTx = unknown> {
20
+ append(events: EconomicEvent[]): Promise<AppendResult[]>;
21
+ appendInTx(events: EconomicEvent[], extra: (tx: TTx) => Promise<void>): Promise<AppendResult[]>;
22
+ getById(id: string): Promise<EconEventStored | null>;
23
+ getByKey(idempotencyKey: string): Promise<EconEventStored | null>;
24
+ listByAgent(agent: string, opts?: ListOpts): Promise<EconEventStored[]>;
25
+ listByPair(a: string, b: string, opts?: ListOpts): Promise<EconEventStored[]>;
26
+ listBySourceId(source: string, sourceId: string, opts?: ListOpts): Promise<EconEventStored[]>;
27
+ scan(fromLedgerSeq: bigint, opts?: {
28
+ limit?: number;
29
+ }): Promise<EconEventStored[]>;
30
+ }
31
+ export declare const ECON_LEDGER_MAX_PAYLOAD_BYTES = 65536;
32
+ export declare const ECON_LEDGER_MAX_BATCH = 500;
33
+ export declare function guardEventsForAppend(events: EconomicEvent[]): void;
34
+ export declare function rowToStored(row: EconEventDbRow): EconEventStored;
35
+ export declare class InMemoryEconLedgerStore implements EconLedgerStore<InMemoryEconLedgerStore> {
36
+ private readonly edges?;
37
+ private readonly byKey;
38
+ private seq;
39
+ constructor(edges?: {
40
+ applyDeltas(deltas: TrustEdgeDelta[]): Promise<void>;
41
+ } | undefined);
42
+ append(events: EconomicEvent[]): Promise<AppendResult[]>;
43
+ appendInTx(events: EconomicEvent[], extra: (tx: InMemoryEconLedgerStore) => Promise<void>): Promise<AppendResult[]>;
44
+ getById(id: string): Promise<EconEventStored | null>;
45
+ getByKey(idempotencyKey: string): Promise<EconEventStored | null>;
46
+ listByAgent(agent: string, opts?: ListOpts): Promise<EconEventStored[]>;
47
+ listByPair(a: string, b: string, opts?: ListOpts): Promise<EconEventStored[]>;
48
+ listBySourceId(source: string, sourceId: string, opts?: ListOpts): Promise<EconEventStored[]>;
49
+ scan(fromLedgerSeq: bigint, opts?: {
50
+ limit?: number;
51
+ }): Promise<EconEventStored[]>;
52
+ private page;
53
+ }
@@ -0,0 +1,130 @@
1
+ import { ECON_EVENT_KIND_SET, verifyEconomicEvent, EconEventError, } from "@agentbadge/econ-events";
2
+ import { deltasOfAppended } from "./trust-edge-store.js";
3
+ export const ECON_LEDGER_MAX_PAYLOAD_BYTES = 65_536;
4
+ export const ECON_LEDGER_MAX_BATCH = 500;
5
+ export function guardEventsForAppend(events) {
6
+ if (events.length === 0) {
7
+ throw new EconEventError("invalid_event", "append requires a non-empty batch");
8
+ }
9
+ if (events.length > ECON_LEDGER_MAX_BATCH) {
10
+ throw new EconEventError("invalid_event", `batch size ${events.length} exceeds cap ${ECON_LEDGER_MAX_BATCH}`);
11
+ }
12
+ for (const e of events) {
13
+ const res = verifyEconomicEvent(e);
14
+ if (!res.ok)
15
+ throw res.error;
16
+ if (!ECON_EVENT_KIND_SET.has(e.kind)) {
17
+ throw new EconEventError("invalid_event", `unknown kind "${e.kind}"`);
18
+ }
19
+ if (JSON.stringify(e.payload).length > ECON_LEDGER_MAX_PAYLOAD_BYTES) {
20
+ throw new EconEventError("invalid_event", `payload exceeds ${ECON_LEDGER_MAX_PAYLOAD_BYTES} bytes`);
21
+ }
22
+ }
23
+ }
24
+ export function rowToStored(row) {
25
+ const event = {
26
+ spec: row.spec,
27
+ id: row.id,
28
+ source: row.source,
29
+ sourceId: row.sourceId,
30
+ seq: row.seq,
31
+ kind: row.kind,
32
+ actor: row.actor,
33
+ ...(row.counterparty !== null ? { counterparty: row.counterparty } : {}),
34
+ ...(row.amountUsdc !== null
35
+ ? { amountUsdc: String(row.amountUsdc) }
36
+ : {}),
37
+ at: row.at,
38
+ payload: row.payload,
39
+ idempotencyKey: row.idempotencyKey,
40
+ };
41
+ return {
42
+ ledgerSeq: BigInt(row.ledgerSeq),
43
+ event,
44
+ createdAtMs: BigInt(new Date(row.createdAt).getTime()),
45
+ };
46
+ }
47
+ export class InMemoryEconLedgerStore {
48
+ edges;
49
+ byKey = new Map();
50
+ seq = 0n;
51
+ constructor(edges) {
52
+ this.edges = edges;
53
+ }
54
+ async append(events) {
55
+ guardEventsForAppend(events);
56
+ const out = [];
57
+ for (const e of events) {
58
+ const existing = this.byKey.get(e.idempotencyKey);
59
+ if (existing) {
60
+ out.push({ event: existing.event, ledgerSeq: existing.ledgerSeq, duplicate: true });
61
+ continue;
62
+ }
63
+ const stored = {
64
+ ledgerSeq: ++this.seq,
65
+ event: e,
66
+ createdAtMs: BigInt(Date.now()),
67
+ };
68
+ this.byKey.set(e.idempotencyKey, stored);
69
+ out.push({ event: e, ledgerSeq: stored.ledgerSeq, duplicate: false });
70
+ }
71
+ if (this.edges) {
72
+ const deltas = deltasOfAppended(out);
73
+ if (deltas.length > 0)
74
+ await this.edges.applyDeltas(deltas);
75
+ }
76
+ return out;
77
+ }
78
+ async appendInTx(events, extra) {
79
+ const rs = await this.append(events);
80
+ await extra(this);
81
+ return rs;
82
+ }
83
+ async getById(id) {
84
+ for (const s of this.byKey.values()) {
85
+ if (s.event.id === id)
86
+ return s;
87
+ }
88
+ return null;
89
+ }
90
+ async getByKey(idempotencyKey) {
91
+ return this.byKey.get(idempotencyKey) ?? null;
92
+ }
93
+ async listByAgent(agent, opts) {
94
+ return this.page([...this.byKey.values()].filter((s) => s.event.actor === agent || s.event.counterparty === agent), opts);
95
+ }
96
+ async listByPair(a, b, opts) {
97
+ return this.page([...this.byKey.values()].filter((s) => {
98
+ const { actor, counterparty } = s.event;
99
+ return ((actor === a && counterparty === b) ||
100
+ (actor === b && counterparty === a));
101
+ }), opts);
102
+ }
103
+ async listBySourceId(source, sourceId, opts) {
104
+ let rows = [...this.byKey.values()]
105
+ .filter((s) => s.event.source === source && s.event.sourceId === sourceId)
106
+ .sort((x, y) => x.ledgerSeq < y.ledgerSeq ? -1 : x.ledgerSeq > y.ledgerSeq ? 1 : 0);
107
+ if (opts?.beforeLedgerSeq !== undefined) {
108
+ rows = rows.filter((s) => s.ledgerSeq < opts.beforeLedgerSeq);
109
+ }
110
+ if (opts?.limit !== undefined)
111
+ rows = rows.slice(0, opts.limit);
112
+ return rows;
113
+ }
114
+ async scan(fromLedgerSeq, opts) {
115
+ let rows = [...this.byKey.values()]
116
+ .filter((s) => s.ledgerSeq >= fromLedgerSeq)
117
+ .sort((x, y) => (x.ledgerSeq < y.ledgerSeq ? -1 : x.ledgerSeq > y.ledgerSeq ? 1 : 0));
118
+ if (opts?.limit !== undefined)
119
+ rows = rows.slice(0, opts.limit);
120
+ return rows;
121
+ }
122
+ page(rows, opts) {
123
+ let out = rows
124
+ .filter((s) => opts?.beforeLedgerSeq === undefined || s.ledgerSeq < opts.beforeLedgerSeq)
125
+ .sort((x, y) => (x.ledgerSeq > y.ledgerSeq ? -1 : x.ledgerSeq < y.ledgerSeq ? 1 : 0));
126
+ if (opts?.limit !== undefined)
127
+ out = out.slice(0, opts.limit);
128
+ return out;
129
+ }
130
+ }
@@ -10,6 +10,10 @@ export declare class ForensicsEdgeRepository implements ForensicsEdgeStore {
10
10
  fromBlock?: bigint;
11
11
  }): Promise<ForensicsEdgeRow[]>;
12
12
  listByPayer(chain: string, payer: string): Promise<ForensicsEdgeRow[]>;
13
+ listWindow(fromIso: string, toIso: string, opts?: {
14
+ chain?: string;
15
+ limit?: number;
16
+ }): Promise<ForensicsEdgeRow[]>;
13
17
  countByChain(chain: string): Promise<number>;
14
18
  private toRow;
15
19
  }
@@ -47,6 +47,14 @@ export class ForensicsEdgeRepository {
47
47
  }).all();
48
48
  return rows.map((r) => this.toRow(r));
49
49
  }
50
+ async listWindow(fromIso, toIso, opts) {
51
+ const rows = await this.db.orm.public.ForensicsEdge.where(opts?.chain !== undefined ? { chain: opts.chain } : {}).all();
52
+ return rows
53
+ .map((r) => this.toRow(r))
54
+ .filter((r) => r.createdAt >= fromIso && r.createdAt < toIso)
55
+ .sort((a, b) => a.createdAt.localeCompare(b.createdAt))
56
+ .slice(0, opts?.limit ?? Number.MAX_SAFE_INTEGER);
57
+ }
50
58
  async countByChain(chain) {
51
59
  const rows = await this.db.orm.public.ForensicsEdge.where({ chain }).all();
52
60
  return rows.length;
@@ -20,6 +20,10 @@ export interface ForensicsEdgeStore {
20
20
  fromBlock?: bigint;
21
21
  }): Promise<ForensicsEdgeRow[]>;
22
22
  listByPayer(chain: string, payer: string): Promise<ForensicsEdgeRow[]>;
23
+ listWindow(fromIso: string, toIso: string, opts?: {
24
+ chain?: string;
25
+ limit?: number;
26
+ }): Promise<ForensicsEdgeRow[]>;
23
27
  countByChain(chain: string): Promise<number>;
24
28
  }
25
29
  export interface ForensicsFundingInsert {
@@ -55,6 +59,10 @@ export declare class InMemoryForensicsEdgeStore implements ForensicsEdgeStore {
55
59
  fromBlock?: bigint;
56
60
  }): Promise<ForensicsEdgeRow[]>;
57
61
  listByPayer(chain: string, payer: string): Promise<ForensicsEdgeRow[]>;
62
+ listWindow(fromIso: string, toIso: string, opts?: {
63
+ chain?: string;
64
+ limit?: number;
65
+ }): Promise<ForensicsEdgeRow[]>;
58
66
  countByChain(chain: string): Promise<number>;
59
67
  }
60
68
  export declare class InMemoryForensicsFundingStore implements ForensicsFundingStore {
@@ -36,6 +36,13 @@ export class InMemoryForensicsEdgeStore {
36
36
  const p = payer.toLowerCase();
37
37
  return [...this.rows.values()].filter((r) => r.chain === chain && r.payer === p);
38
38
  }
39
+ async listWindow(fromIso, toIso, opts) {
40
+ let out = [...this.rows.values()].filter((r) => r.createdAt >= fromIso &&
41
+ r.createdAt < toIso &&
42
+ (opts?.chain === undefined || r.chain === opts.chain));
43
+ out.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
44
+ return opts?.limit !== undefined ? out.slice(0, opts.limit) : out;
45
+ }
39
46
  async countByChain(chain) {
40
47
  return [...this.rows.values()].filter((r) => r.chain === chain).length;
41
48
  }
@@ -0,0 +1,66 @@
1
+ import type { PrismaDb } from "./event-repository.js";
2
+ import type { AttemptStatusPatch, PaymentAttemptInsert, PaymentAttemptRow, PaymentAttemptStore, PaymentEventInsert, PaymentEventRow, PaymentEventStore, PaymentInsert, PaymentPriceInsert, PaymentPriceRow, PaymentPriceStore, PaymentProductInsert, PaymentProductRow, PaymentProductStore, PaymentReceiptInsert, PaymentReceiptRow, PaymentReceiptStore, PaymentRow, PaymentStore, PaymentStores } from "./payment-store.js";
3
+ export declare class PaymentRepository implements PaymentStore {
4
+ private readonly db;
5
+ constructor(db: PrismaDb);
6
+ private get orm();
7
+ create(p: PaymentInsert): Promise<PaymentRow | null>;
8
+ getById(id: string): Promise<PaymentRow | null>;
9
+ getByReference(reference: string): Promise<PaymentRow | null>;
10
+ getByIdempotencyKey(key: string): Promise<PaymentRow | null>;
11
+ listByCustomer(customerId: string): Promise<PaymentRow[]>;
12
+ applyStatus(id: string, expectedFrom: string, to: string, updatedAtMs: number): Promise<PaymentRow | null>;
13
+ listExpired(nowMs: number): Promise<PaymentRow[]>;
14
+ }
15
+ export declare class PaymentAttemptRepository implements PaymentAttemptStore {
16
+ private readonly db;
17
+ constructor(db: PrismaDb);
18
+ private get orm();
19
+ create(a: PaymentAttemptInsert): Promise<PaymentAttemptRow | null>;
20
+ getById(id: string): Promise<PaymentAttemptRow | null>;
21
+ listByPayment(paymentId: string): Promise<PaymentAttemptRow[]>;
22
+ getByProviderRef(provider: string, providerReference: string): Promise<PaymentAttemptRow | null>;
23
+ private getByProviderTx;
24
+ getByTxHash(transactionHash: string): Promise<PaymentAttemptRow | null>;
25
+ applyStatus(id: string, expectedFrom: string, to: string, _updatedAtMs: number, patch?: AttemptStatusPatch): Promise<PaymentAttemptRow | null>;
26
+ listExpired(nowMs: number): Promise<PaymentAttemptRow[]>;
27
+ }
28
+ export declare class PaymentReceiptRepository implements PaymentReceiptStore {
29
+ private readonly db;
30
+ constructor(db: PrismaDb);
31
+ private get orm();
32
+ append(r: PaymentReceiptInsert): Promise<PaymentReceiptRow | null>;
33
+ getById(id: string): Promise<PaymentReceiptRow | null>;
34
+ listByPayment(paymentId: string): Promise<PaymentReceiptRow[]>;
35
+ getByExternalRef(provider: string, externalReference: string): Promise<PaymentReceiptRow | null>;
36
+ }
37
+ export declare class PaymentEventRepository implements PaymentEventStore {
38
+ private readonly db;
39
+ constructor(db: PrismaDb);
40
+ private get orm();
41
+ append(e: PaymentEventInsert): Promise<PaymentEventRow | null>;
42
+ listByPayment(paymentId: string): Promise<PaymentEventRow[]>;
43
+ listByAttempt(attemptId: string): Promise<PaymentEventRow[]>;
44
+ }
45
+ export declare class PaymentProductRepository implements PaymentProductStore {
46
+ private readonly db;
47
+ constructor(db: PrismaDb);
48
+ private get orm();
49
+ upsert(p: PaymentProductInsert): Promise<PaymentProductRow>;
50
+ getById(id: string): Promise<PaymentProductRow | null>;
51
+ getByCode(code: string): Promise<PaymentProductRow | null>;
52
+ list(opts?: {
53
+ activeOnly?: boolean;
54
+ }): Promise<PaymentProductRow[]>;
55
+ }
56
+ export declare class PaymentPriceRepository implements PaymentPriceStore {
57
+ private readonly db;
58
+ constructor(db: PrismaDb);
59
+ private get orm();
60
+ create(p: PaymentPriceInsert): Promise<PaymentPriceRow | null>;
61
+ getById(id: string): Promise<PaymentPriceRow | null>;
62
+ listByProduct(productId: string, opts?: {
63
+ activeOnly?: boolean;
64
+ }): Promise<PaymentPriceRow[]>;
65
+ }
66
+ export declare function createPrismaPaymentStores(db: PrismaDb): PaymentStores;