diff --git a/packages/sqlite-shared/src/cursor.ts b/packages/sqlite-shared/src/cursor.ts index d94f161..9eb7632 100644 --- a/packages/sqlite-shared/src/cursor.ts +++ b/packages/sqlite-shared/src/cursor.ts @@ -26,14 +26,10 @@ export const decodeCursor = (cursor: string): DecodedCursor => { throw new StackQueryError(`Invalid cursor: malformed "${cursor}"`); } const parts = decoded.split('|'); - // Three parts: field|value|id. Two parts: value|id, implying createdAt. - const [field, value, id] = - parts.length === 3 - ? (parts as [string, string, string]) - : (['createdAt', ...parts] as [string, string, string]); - if (field === undefined || value === undefined || id === undefined) { + if (parts.length !== 3) { throw new StackQueryError(`Invalid cursor: malformed "${cursor}"`); } + const [field, value, id] = parts as [string, string, string]; if (!SORT_FIELDS.includes(field as SortField)) { throw new StackQueryError(`Invalid cursor: unknown sort field "${field}"`); } diff --git a/packages/sqlite-shared/tests/cursor.test.ts b/packages/sqlite-shared/tests/cursor.test.ts index b9d9aa7..26030a9 100644 --- a/packages/sqlite-shared/tests/cursor.test.ts +++ b/packages/sqlite-shared/tests/cursor.test.ts @@ -19,9 +19,9 @@ describe('encodeCursor / decodeCursor', () => { expect(decodeCursor(cursor)).toEqual({ field: 'createdAt', value: 12345, id: 'rec01' }); }); - test('accepts the legacy 2-part (value|id) format as createdAt', () => { + test('throws StackQueryError for a 2-part (value|id) cursor', () => { const legacy = btoa('12345|rec01'); - expect(decodeCursor(legacy)).toEqual({ field: 'createdAt', value: 12345, id: 'rec01' }); + expect(() => decodeCursor(legacy)).toThrow(StackQueryError); }); test('throws StackQueryError for non-base64 garbage', () => {