Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Cursor Id validation #11

Closed
wants to merge 6 commits into from
Closed

FIX: Cursor Id validation #11

wants to merge 6 commits into from

Conversation

guicuton
Copy link

This fix is related to issue: #9

When your table does not have a sequential primary key (like my case that is UUID), the decryptedCursor inside of a parseInt() always results into a number excepting the first page.

Sample with parseInt():

const cursors = ['c2FsdHlzYWx0YjhlZTZhMjMtNjcxYi00MTAxLThkMzgtYzFkZmNkZWM5ZDRk', 'c2FsdHlzYWx0NmJkMDk0YTQtYmY2Zi00YTg1LThlNDItOWNlYTYyNjlhYTI0', 'c2FsdHlzYWx0NzBlN2Q1NTgtZjY5MS00OTEyLTk3ZGItOTI5NDkyYzQwMzhi', 'c2FsdHlzYWx0MjU1ZTcwODYtNmQ0Yy00OWYyLWFjYTctYTYxYjljMTNkZGVj'];

cursors.forEach((cursor) => {
    const decryptedCursor = Buffer.from(cursor, 'base64').toString('ascii').slice(9);
    console.log(parseInt(decryptedCursor))
});
// output: NaN | 6 | 70 | 255
// All these should console as NaN

This behaviour leads to a falsy FALSE condition giving the idOrigin variable the NaN value resulting the error:

Argument id: Got invalid value NaN on prisma.model. Provided Float, expected String.

Instead of using the parseInt(decryptedCursor) we need use the Number(decryptedCursor) on ternary condition

Sample with Number():

const cursors = ['c2FsdHlzYWx0YjhlZTZhMjMtNjcxYi00MTAxLThkMzgtYzFkZmNkZWM5ZDRk', 'c2FsdHlzYWx0NmJkMDk0YTQtYmY2Zi00YTg1LThlNDItOWNlYTYyNjlhYTI0', 'c2FsdHlzYWx0NzBlN2Q1NTgtZjY5MS00OTEyLTk3ZGItOTI5NDkyYzQwMzhi', 'c2FsdHlzYWx0MjU1ZTcwODYtNmQ0Yy00OWYyLWFjYTctYTYxYjljMTNkZGVj', 
'c2FsdHlzYWx0Mg==', //Here is a encrypted cursor from a table with sequential id
'c2FsdHlzYWx0MjM3', //Here is a encrypted cursor from a table with sequential id
'c2FsdHlzYWx0MjMy' //Here is a encrypted cursor from a table with sequential id
];  

cursors.forEach((cursor) => {
    const decryptedCursor = Buffer.from(cursor, 'base64').toString('ascii').slice(9);
    console.log(Number(decryptedCursor))
});
// output: NaN | NaN | NaN | NaN | 2 | 237 | 232

…at, expected String.

Fix cursor id validation
Add SELECT props inside of a prisma query
Added new param instruction
@guicuton guicuton mentioned this pull request Oct 23, 2023
@guicuton
Copy link
Author

This PR also add the select. Related to issue: #8

@guicuton guicuton closed this by deleting the head repository Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant