@agentbadge/database 0.6.14 → 0.6.15
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.
|
@@ -73,5 +73,14 @@ export declare class CommercePaymentRepository implements CommercePaymentStore {
|
|
|
73
73
|
getById(id: string): Promise<CommercePaymentRow | null>;
|
|
74
74
|
getByAgreement(agreementId: string): Promise<CommercePaymentRow | null>;
|
|
75
75
|
applyStatus(id: string, expectedFrom: string, to: string, patch?: PaymentStatusPatch): Promise<CommercePaymentRow | null>;
|
|
76
|
+
list(opts?: {
|
|
77
|
+
mode?: string;
|
|
78
|
+
status?: string;
|
|
79
|
+
statuses?: readonly string[];
|
|
80
|
+
recordedSinceMs?: number;
|
|
81
|
+
recordedUntilMs?: number;
|
|
82
|
+
limit?: number;
|
|
83
|
+
offset?: number;
|
|
84
|
+
}): Promise<CommercePaymentRow[]>;
|
|
76
85
|
}
|
|
77
86
|
export declare function createPrismaCommerceStores(db: PrismaDb): CommerceStores;
|
|
@@ -500,6 +500,30 @@ export class CommercePaymentRepository {
|
|
|
500
500
|
});
|
|
501
501
|
return row ? toPaymentRow(row) : null;
|
|
502
502
|
}
|
|
503
|
+
async list(opts = {}) {
|
|
504
|
+
const statusSet = opts.statuses !== undefined
|
|
505
|
+
? new Set(opts.statuses)
|
|
506
|
+
: opts.status !== undefined
|
|
507
|
+
? new Set([opts.status])
|
|
508
|
+
: undefined;
|
|
509
|
+
const eq = {};
|
|
510
|
+
if (opts.mode !== undefined)
|
|
511
|
+
eq["mode"] = opts.mode;
|
|
512
|
+
const candidates = await this.orm.where(eq).all();
|
|
513
|
+
const stamp = (r) => r.recordedAtMs ?? Date.parse(r.createdAt);
|
|
514
|
+
const out = candidates
|
|
515
|
+
.map(toPaymentRow)
|
|
516
|
+
.filter((r) => (statusSet === undefined || statusSet.has(r.status)) &&
|
|
517
|
+
(opts.recordedSinceMs === undefined ||
|
|
518
|
+
(r.recordedAtMs != null &&
|
|
519
|
+
r.recordedAtMs >= opts.recordedSinceMs)) &&
|
|
520
|
+
(opts.recordedUntilMs === undefined ||
|
|
521
|
+
(r.recordedAtMs != null &&
|
|
522
|
+
r.recordedAtMs <= opts.recordedUntilMs)));
|
|
523
|
+
out.sort((a, b) => stamp(b) - stamp(a));
|
|
524
|
+
const offset = opts.offset ?? 0;
|
|
525
|
+
return out.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
|
|
526
|
+
}
|
|
503
527
|
}
|
|
504
528
|
export function createPrismaCommerceStores(db) {
|
|
505
529
|
const bundle = (client) => ({
|
|
@@ -179,6 +179,15 @@ export interface CommercePaymentStore {
|
|
|
179
179
|
getById(id: string): Promise<CommercePaymentRow | null>;
|
|
180
180
|
getByAgreement(agreementId: string): Promise<CommercePaymentRow | null>;
|
|
181
181
|
applyStatus(id: string, expectedFrom: string, to: string, patch?: PaymentStatusPatch): Promise<CommercePaymentRow | null>;
|
|
182
|
+
list(opts?: {
|
|
183
|
+
mode?: string;
|
|
184
|
+
status?: string;
|
|
185
|
+
statuses?: readonly string[];
|
|
186
|
+
recordedSinceMs?: number;
|
|
187
|
+
recordedUntilMs?: number;
|
|
188
|
+
limit?: number;
|
|
189
|
+
offset?: number;
|
|
190
|
+
}): Promise<CommercePaymentRow[]>;
|
|
182
191
|
}
|
|
183
192
|
export interface CommerceStores {
|
|
184
193
|
tasks: CommerceTaskStore;
|
|
@@ -249,5 +258,14 @@ export declare class InMemoryCommercePaymentStore implements CommercePaymentStor
|
|
|
249
258
|
getById(id: string): Promise<CommercePaymentRow | null>;
|
|
250
259
|
getByAgreement(agreementId: string): Promise<CommercePaymentRow | null>;
|
|
251
260
|
applyStatus(id: string, expectedFrom: string, to: string, patch?: PaymentStatusPatch): Promise<CommercePaymentRow | null>;
|
|
261
|
+
list(opts?: {
|
|
262
|
+
mode?: string;
|
|
263
|
+
status?: string;
|
|
264
|
+
statuses?: readonly string[];
|
|
265
|
+
recordedSinceMs?: number;
|
|
266
|
+
recordedUntilMs?: number;
|
|
267
|
+
limit?: number;
|
|
268
|
+
offset?: number;
|
|
269
|
+
}): Promise<CommercePaymentRow[]>;
|
|
252
270
|
}
|
|
253
271
|
export declare function createInMemoryCommerceStores(): CommerceStores;
|
|
@@ -301,6 +301,25 @@ export class InMemoryCommercePaymentStore {
|
|
|
301
301
|
this.rows.set(id, next);
|
|
302
302
|
return next;
|
|
303
303
|
}
|
|
304
|
+
async list(opts = {}) {
|
|
305
|
+
const statusSet = opts.statuses !== undefined
|
|
306
|
+
? new Set(opts.statuses)
|
|
307
|
+
: opts.status !== undefined
|
|
308
|
+
? new Set([opts.status])
|
|
309
|
+
: undefined;
|
|
310
|
+
const stamp = (r) => r.recordedAtMs ?? Date.parse(r.createdAt);
|
|
311
|
+
const out = [...this.rows.values()].filter((r) => (opts.mode === undefined || r.mode === opts.mode) &&
|
|
312
|
+
(statusSet === undefined || statusSet.has(r.status)) &&
|
|
313
|
+
(opts.recordedSinceMs === undefined ||
|
|
314
|
+
(r.recordedAtMs != null &&
|
|
315
|
+
r.recordedAtMs >= opts.recordedSinceMs)) &&
|
|
316
|
+
(opts.recordedUntilMs === undefined ||
|
|
317
|
+
(r.recordedAtMs != null &&
|
|
318
|
+
r.recordedAtMs <= opts.recordedUntilMs)));
|
|
319
|
+
out.sort((a, b) => stamp(b) - stamp(a));
|
|
320
|
+
const offset = opts.offset ?? 0;
|
|
321
|
+
return out.slice(offset, opts.limit === undefined ? undefined : offset + opts.limit);
|
|
322
|
+
}
|
|
304
323
|
}
|
|
305
324
|
function cloneRows(value) {
|
|
306
325
|
if (value === null || typeof value !== "object")
|
package/package.json
CHANGED