75 lines
2.6 KiB
JavaScript
75 lines
2.6 KiB
JavaScript
"use strict";
|
|
/** Keyset pagination for high-volume admin reports (created_at + id). */
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.CURSOR_PAGINATED_REPORT_KEYS = void 0;
|
|
exports.reportSupportsCursor = reportSupportsCursor;
|
|
exports.encodeReportCursor = encodeReportCursor;
|
|
exports.decodeReportCursor = decodeReportCursor;
|
|
exports.buildCursorFromRow = buildCursorFromRow;
|
|
exports.orderByCreatedAtId = orderByCreatedAtId;
|
|
exports.buildCreatedAtIdKeyset = buildCreatedAtIdKeyset;
|
|
exports.CURSOR_PAGINATED_REPORT_KEYS = new Set([
|
|
'financial-deposits',
|
|
'financial-withdrawals',
|
|
'financial-bonuses',
|
|
'financial-encouragement-grants',
|
|
'financial-commission-history',
|
|
'financial-adjustments',
|
|
'games-predictions',
|
|
'games-predictions-real',
|
|
'games-wins',
|
|
'games-losses',
|
|
'games-auto',
|
|
'games-manual',
|
|
'games-multi-candle',
|
|
'games-test',
|
|
]);
|
|
function reportSupportsCursor(reportKey, sortBy) {
|
|
return exports.CURSOR_PAGINATED_REPORT_KEYS.has(reportKey) && (!sortBy || sortBy === 'created_at');
|
|
}
|
|
function encodeReportCursor(cursor) {
|
|
return Buffer.from(JSON.stringify(cursor), 'utf8').toString('base64url');
|
|
}
|
|
function decodeReportCursor(token) {
|
|
try {
|
|
const parsed = JSON.parse(Buffer.from(token, 'base64url').toString('utf8'));
|
|
if (!parsed || typeof parsed !== 'object')
|
|
return null;
|
|
if (parsed.sortBy !== 'created_at')
|
|
return null;
|
|
if (parsed.sortDir !== 'asc' && parsed.sortDir !== 'desc')
|
|
return null;
|
|
if (typeof parsed.createdAt !== 'string' || typeof parsed.id !== 'string')
|
|
return null;
|
|
return parsed;
|
|
}
|
|
catch {
|
|
return null;
|
|
}
|
|
}
|
|
function buildCursorFromRow(sortDir, row) {
|
|
const createdAt = row.created_at instanceof Date
|
|
? row.created_at.toISOString()
|
|
: String(row.created_at ?? '');
|
|
return encodeReportCursor({
|
|
sortBy: 'created_at',
|
|
sortDir,
|
|
createdAt,
|
|
id: String(row.id),
|
|
});
|
|
}
|
|
function orderByCreatedAtId(alias, sortDir) {
|
|
const sd = sortDir === 'asc' ? 'ASC' : 'DESC';
|
|
return `${alias}.created_at ${sd}, ${alias}.id ${sd}`;
|
|
}
|
|
function buildCreatedAtIdKeyset(alias, sortDir, cursor, values, paramStart) {
|
|
if (!cursor)
|
|
return { sql: '', nextParam: paramStart };
|
|
values.push(cursor.createdAt, cursor.id);
|
|
const op = sortDir === 'asc' ? '>' : '<';
|
|
return {
|
|
sql: ` AND (${alias}.created_at, ${alias}.id) ${op} ($${paramStart}::timestamptz, $${paramStart + 1}::uuid)`,
|
|
nextParam: paramStart + 2,
|
|
};
|
|
}
|
|
//# sourceMappingURL=reportListCursor.js.map
|