-
-
Notifications
You must be signed in to change notification settings - Fork 376
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(core): refactor to use koa style middlewares #651
Conversation
There are lint errors. Use |
@nponeccop Linter and/or tests are not meant to pass, ATM. Read the PR description, please :) |
That is some pretty-looking code and has some good ideas worth exploring. My first impression is that it's too big of a change for middy to do in one step. We just got rid of callbacks in v2, adding PS I can add the prettier rc file in if that helps your IDE |
100%. This is only exploratory, at the moment.
Would definitely need a new major release and proper docs. Not something I'm even playing around with the idea of offering "two cores"? Like different "
Saw that you did that. Much appreciated. Since we are on the topic, I'm curious: why did you decide to go with EDIT: Seems like |
I think 2 versions of
We started using |
Not really interested in re-writing the core in TS, to be honest. It's small enough as it is and the typings that we have from
You can definitively use
Maybe we could add some doc section on how to setup the IDE if you wish to contribute, if that's the case? I'm only talking from my experience here, but a typical JS setup includes some variation of |
There is only one linting tool now. I'm for keeping the current approach ( |
Sort of. They both use
I agree. Or maybe even all releases? Don't see any need for TS, at all, TBH.
One approach that I have used in the past with good results is to auto-generate |
This defeats the purpose of
They don't. Eslint and typescript work exactly the same way from Eslint IDE support is a separate thing from command line, and Standard is sometimes supported too. Standard setup is marginally easier than the lint way of course, and doesn't pollute your package.json devDependencies.
TS has an insane level of support from JetBrains. So unless you are a fan of JetBrains/IntelliJ IDEs there is no point.
Nah, that would generate mediocre typings, especially for such framework as |
I feel like we are digressing from the main point of focus of this PR, so I'll only briefly address your comments above, @nponeccop.
Not really the case, IMHO. Of course, it all boils down to a matter of preference. I see
They do. And no. It's super easy to confirm: I cloned the repository, opened my IDE and got no linting feedback or auto-formatting whatsoever. No
From your comments, I reckon you have never used the tools I mentioned. You should give it a try before dismissing it or forming an opinion. The typings are as good as your jsdocs. If your docs are good, your typings will follow. Not sure what "TS-Fu" you are specifically referring to (generics and intersections are both pretty basic and fully supported in jsdocs), but you can always manually tweak typings once generated, if really needed. |
Hey guys, thanks for your work on this project. I've only been using middy briefly, but I wanted to share a few thoughts. Please just let me know if I'm off base here.
It's been awhile since I've used Koa, but I think this is in keeping with its design. It seems weird to me that you would specify the the order of the handler within the middleware stack using something like
In the example posted at the top of this thread, a
I understand that On the other hand, if for some reason
I think it's been mentioned a couple times already that this is a large refactor of how middy works. And reading your posts above, it seems that many are maintaining alternate versions of the middleware anyway. So, I'm putting in my vote for starting a new project. Oddly enough, that would reflect the history of the Express -> Koa transition. By the way, let me know if this discussion is now happening elsewhere. Also, I'm happy to help where I can :D |
Looks like |
What does this implement/fix? Explain your changes.
A PoC to let
middy
support Koa-style middlewares.It also includes some (much needed, IMHO) DX improvements, namely:
eslint
support through a new@middy/eslint-config
shareable package (breaks currentts-standard
rules).prettier
support.Does this close any currently open issues?
Related to #622 and #626
Any other comments?
This is meant to kick off a discussion into what people expect of
middy
as a framework moving forward, rather than a complete or full implementation of@middy/core
. As such, it doesn't really include any new documentation or tests. Not meant to be merged.Here's how you would use it. Borrow this Gist for
event.json
.The new API looks pretty similar, but it does bring some changes along.
next
dispatches the next function down the chain.next()
.await next()
..use()
accepts a function expectingrequest
(i.e.: the request context) andnext
arguments..lambda()
serves two purposes: wraps the handler logic inside amiddy
middleware and sets the execution order for the event handler within the chain, effectively discerning between "before" and "after" middlewares..error()
registers an optional "global" error handler for any unhandled exceptions - this is meant as a safety net for logging unexpected errors and does not replace a proper error handler middleware. Similar tokoa
app.on('error', err => ... )
..handler()
builds and returns the final AWS Lambda handler function. Should be called last. Similar tokoa
callback()
.This is obviously a proposal at this stage, so I'm looking forward to hearing other people's opinion on this.
.handler()
builder call could be omitted, at the expense of composing middlewares again on each new event (would not affect cold starts).For example, consider this alternative API that addresses points above.
In this case, it's made clearer that the AWS handler function is a required argument for constructing a
middy
instance - but we lose the immediate visual grepping and ordering of the middlewares in the chain. The phases of execution are now determined by calling either.before
or.after
.Todo list