(kind: string, cursor: string | undefined)
| 15 | // (corrupt cursors duplicate items the caller already saw). An absent |
| 16 | // cursor returns 0 (start of pagination). |
| 17 | export function decodeOffsetCursor(kind: string, cursor: string | undefined): number | null { |
| 18 | if (!cursor) return 0; |
| 19 | try { |
| 20 | const decoded = Buffer.from(cursor, 'base64url').toString('utf8'); |
| 21 | const m = new RegExp(`^${kind}:offset:(\\d+)$`).exec(decoded); |
| 22 | if (!m) return null; |
| 23 | const n = Number.parseInt(m[1], 10); |
| 24 | return Number.isFinite(n) && n >= 0 ? n : null; |
| 25 | } catch { |
| 26 | return null; |
| 27 | } |
| 28 | } |
no outgoing calls
no test coverage detected