feat: defineRequestMidleware, defineResponseMiddleware and rename object synctax hooks#507
feat: defineRequestMidleware, defineResponseMiddleware and rename object synctax hooks#507
defineRequestMidleware, defineResponseMiddleware and rename object synctax hooks#507Conversation
… object synctax hooks
Codecov Report
@@ 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
|
danielroe
left a comment
There was a problem hiding this comment.
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.
|
These middleware are same as current before/after. Do you mind to push any required placeholder generic? |
|
I think prefixing with underscore would be enough to mark them as internal types for now. |
🔗 Linked issue
Context: Find most of DX issues while working on a example for #501
❓ Type of change
📚 Description
This PR introduces two new define utils
defineRequestMidlewareanddefineResponseMiddleware(withRequestMiddlewareandResponseMiddleware) 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
compressionMiddlewareas util)Also in order to keep consistency with global hook options and readability, the hooks are renamed from
before/aftertoonRequest/beforeResponse.Also we support non Array format for most consistency with top level
📝 Checklist