MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / decodeOffsetCursor

Function decodeOffsetCursor

server/src/training-agent/pagination.ts:17–28  ·  view source on GitHub ↗
(kind: string, cursor: string | undefined)

Source from the content-addressed store, hash-verified

15// (corrupt cursors duplicate items the caller already saw). An absent
16// cursor returns 0 (start of pagination).
17export 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}

Callers 7

handleGetMediaBuysFunction · 0.85
decodeCreativeCursorFunction · 0.85
handleGetSignalsFunction · 0.85
handleListPropertyListsFunction · 0.85
handleListAccountsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected