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: defineRequestMidleware, defineResponseMiddleware and rename object synctax hooks #507

Merged
merged 4 commits into from
Aug 14, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Aug 14, 2023

πŸ”— Linked issue

Context: Find most of DX issues while working on a example for #501

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR introduces two new define utils defineRequestMidleware and defineResponseMiddleware (with RequestMiddleware and ResponseMiddleware) types.

These utils are then used for event handlers with object syntax but can also used independently to define such hooks outside of the event handler in a composable way (imagine compressionMiddleware as util)

Also in order to keep consistency with global hook options and readability, the hooks are renamed from before/after to onRequest/beforeResponse.

Also we support non Array format for most consistency with top level

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0 pi0 requested a review from danielroe August 14, 2023 18:04
@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #507 (6bf6992) into main (8079fa9) will decrease coverage by 0.32%.
The diff coverage is 51.85%.

❗ Current head 6bf6992 differs from pull request most recent head f577876. Consider uploading reports for the commit f577876 to get more accurate results

@@            Coverage Diff             @@
##             main     #507      +/-   ##
==========================================
- Coverage   82.43%   82.11%   -0.32%     
==========================================
  Files          31       31              
  Lines        3604     3646      +42     
  Branches      536      536              
==========================================
+ Hits         2971     2994      +23     
- Misses        633      652      +19     
Files Changed Coverage Ξ”
src/event/utils.ts 58.38% <31.57%> (-4.30%) ⬇️
src/types.ts 100.00% <100.00%> (ΓΈ)

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

This looks good to me, from an API perspective.

Note that we will probably need to change the signature of these types before merging any kind of validation support. You could already go ahead and add the appropriate generics (even if unused) in the hook types so we don't break anything when implementing later.

@pi0
Copy link
Member Author

pi0 commented Aug 14, 2023

These middleware are same as current before/after. Do you mind to push any required placeholder generic?

@danielroe
Copy link
Member

I think prefixing with underscore would be enough to mark them as internal types for now.

@pi0 pi0 merged commit a3303e6 into main Aug 14, 2023
4 checks passed
@pi0 pi0 deleted the feat/before-after-def branch August 14, 2023 20:22
@pi0 pi0 mentioned this pull request Aug 14, 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.

None yet

2 participants