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

feat: support promise api #31

Closed
wants to merge 5 commits into from
Closed

feat: support promise api #31

wants to merge 5 commits into from

Conversation

lokshunhung
Copy link
Contributor

Reolves #24: This PR adds promise support for FastifyRequest#destroySession and the get, set, destroy methods on FastifyInstance#sessionStore.

The session store methods are wrapped with a new function to inspect whether a callback argument is passed, and will return a promise if the callback is missing. This approach does not mutate/monkey-patch methods on the store instance to avoid breaking anything. Tests for this are included here.

Checklist

@mcollina
Copy link
Member

I'm sorry but this is not what the issue is about. We would like to support stores written with async functions, not creating a proxy.

@lokshunhung
Copy link
Contributor Author

@mcollina Thanks for taking a look, unfortunately i have misunderstood the issue. Is there any existing promise-based store packages that the library would like to support? I could use it as reference and work on it. Cheers

@mcollina
Copy link
Member

mcollina commented Nov 1, 2021

@SimenB wdyt? Do you know anything?

@SimenB
Copy link
Member

SimenB commented Nov 1, 2021

What I originally requested was a way to use promises instead of callbacks in the API exposed by @fastify/session. Since this module is made for compat with Express' stores, I don't think any of those (pluggable stores) being promise based is anywhere close to happening.

So what I wanted is essentially what this PR has implemented - wrap any callback APIs with promises.

(as mentioned in the issue, request.destroySession is also a callback, but all other methods today are from the stores which are plugged in)

@lokshunhung
Copy link
Contributor Author

@mcollina I can continue to work on it if you think this could be something to be added to the library. Currently the CI fails due to coverage which should not be too hard to fix.

@mcollina
Copy link
Member

mcollina commented Nov 1, 2021

Great news! Could you fix the remaining tests @lokshunhung ?

@lokshunhung
Copy link
Contributor Author

Sure, I can take a look next morning. It's 12am now so good night guys.

@coveralls
Copy link

coveralls commented Nov 2, 2021

Pull Request Test Coverage Report for Build 1428409433

  • 39 of 39 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1420719549: 0.0%
Covered Lines: 223
Relevant Lines: 223

💛 - Coveralls

@lokshunhung
Copy link
Contributor Author

@mcollina I fixed the tests and updated the docs. It's ready now.

README.md Outdated Show resolved Hide resolved
@zekth zekth requested a review from SimenB November 2, 2021 09:31
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

late suggestion for alternative approach, but current code works for my use cases 🙂

lib/destroy-session.js Show resolved Hide resolved
@lokshunhung
Copy link
Contributor Author

If the comment from @SimenB is resolved, I think this can be merged

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works fine for me as is (it adds what I originally requested in a nice and clean way), but I do think the API consistency should be solved first (to avoid potential churn)

Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. Good work

@mcollina
Copy link
Member

mcollina commented Nov 3, 2021

I do think the API consistency should be solved first (to avoid potential churn)

Could you clarify what you mean by "first"?

@SimenB
Copy link
Member

SimenB commented Nov 3, 2021

I do think the API consistency should be solved first (to avoid potential churn)

Could you clarify what you mean by "first"?

Before landing this PR, as I think a unified API will remove the reason to promisify sessionStore in the first place (thus change this PR quite fundamentally)

@mcollina
Copy link
Member

mcollina commented Nov 3, 2021

@SimenB so you prefer if #34 was solved first and then this to be reworked on top. Great.

@SimenB
Copy link
Member

SimenB commented Nov 3, 2021

Yup!

This pull request was closed.
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.

6 participants