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

"limit=-1 must be "enabled" with maxLimit=-1" as per #393 not working #958

Open
jakobwgnr opened this issue Aug 19, 2024 · 5 comments
Open

Comments

@jakobwgnr
Copy link
Contributor

jakobwgnr commented Aug 19, 2024

Hey!

I think the changes made in #393 are not fully correct.

SHOULD:
My expectation would be that "maxLimit=-1" would enable the caller to use no pagination if he wants to with "limit=-1".
My expecation would be that the standardfunctionality with e.g. "limit=2" would still work regardless of maxLimit definition

IS:
If I set maxLimit=-1 and limit=2 it will currently give me all entries (hence no pagination) which is not the expected behaviour from my POV.

Using: 9.0.1

I think the issue is somewhere here:

: Math.min(query.limit ?? defaultLimit, maxLimit)

It will result in const limit = -1

BR Jakob

@Helveg
Copy link
Collaborator

Helveg commented Aug 19, 2024

Thanks for the report, could you open a PR that adds a failing test case for this? From there, fixing it will be easier :)

@jakobwgnr
Copy link
Contributor Author

@Helveg Please see #959

@jakobwgnr
Copy link
Contributor Author

jakobwgnr commented Aug 20, 2024

@Helveg my proposed change would be following - paginate.ts Line 197 ff:

const limit =
        query.limit === PaginationLimit.COUNTER_ONLY
            ? PaginationLimit.COUNTER_ONLY
            : isPaginated === true // would change that here as otherwise will only validate if "isPaginated" is existing. Not 100& sure tho... In the following we may assume that either maxLimit or query.limit may be NO_PAGINATION, but never both
            ? maxLimit === PaginationLimit.NO_PAGINATION
                ? query.limit ?? defaultLimit // in case of maxLimit = NO_PAGINATION either given limit or defaultLimit will be used
                : query.limit === PaginationLimit.NO_PAGINATION
                ? Math.min(defaultLimit, maxLimit) // query.limit not to be considered if NO_PAGINATION
                : Math.min(query.limit ?? defaultLimit, maxLimit) // happy path
            : defaultLimit

Nevertheless it changes the behaviour of the test "should limit to defaultLimit, if limit is differt FROM NO_PAGINATION ecc...."

But for me it would be the more correct logic to apply the limit if it was given in the query, regardless of the config of "maxLimit"

@ppetzold
Copy link
Owner

yep. definitely also how I had it envisioned :) let's roll with it. breaking changes ftw :) could you add to PR?

@jakobwgnr
Copy link
Contributor Author

@ppetzold @Helveg Change was added to the PR as proposed.

Summary of change:

  • Adapted logic to define limit in paginate.ts
  • removed a now invalid test case
  • added a new test case to cover the new logic

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

No branches or pull requests

3 participants