-
-
Notifications
You must be signed in to change notification settings - Fork 681
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
Promise support for form.parse() #685
Comments
Wait for v2 to be finalized. We will try to make no breaking change for v2 but for v3 this could be good. |
Awesome, thanks for the quick reply! |
If you want to help review this PR #686 |
Of course. Added some comments there. :) |
Yep, it was considered. |
@lmammino you can make a PR against the v3.x branch |
Are |
No the issue is still open |
Should form.parse()
|
for v2 and above. Then we should consider the Streaming things and APIs, but lets that be v4 haha. |
Still no Promise support? |
Soon ™ |
Just a thought... instead of supporting both callbacks and promises in the same function you could mimic the way
|
@jwerre yep, i'm leaning more towards that, or just a separate exports. @GrosSacASac haha 🤣 on v3 or for v4? I think I said we will drop v2 (as main) around march or april? Uh, let me see where that thing was haha. |
Is there any update on this? |
How wrapping function in promise would take a year?
but please do coverage test on a code above |
It's not hard. It's just that there are several other things and at least 2 parallel versions used. Plus, it's that hard to just use |
here is a "one line" solution for creating the promise const parseForm = async (req) => new Promise((resolve, reject) => usage: const [fields, files] = await parseForm(req) |
@ds2345 right. The beauty of callback APIs, you can easily turn them into promises.. haha. |
Hi @ds2345 , I believe your code works, but it seems my code never enters into callback BTW, the version of async #parseForm(request) {
return new Promise((resolve, reject) => {
// const form = formidable({ multiples: true, api: { bodyParser: false } });
console.log('START form.parse()');
new formidable.IncomingForm().parse(request, (error, fields, files) => {
console.log(
'form.parse() error:',
error,
', fields:',
fields,
', files:',
files
);
error ? reject(error) : resolve([fields, files]);
});
});
}
async handle(request) {
console.time('TaskAttachmentSaveHandler.handle() parseForm');
const [fields, files] = await this.#parseForm(request);
console.timeEnd('TaskAttachmentSaveHandler.handle() parseForm');
} |
It's very disappointing to see that a library in 2023 isn't capable of using promises. I would happily submit a PR, as this fix would be trivial to make ... but from the comments here it sounds like the maintainers are against promises? |
Soon ™ |
It is not delayed because it is hard, but because I was busy and I try to fix all the test, see the ongoing PR for commit details |
So based on votes I decided to make it both callback and promise as a transition and then later make it promise only (breaking change) |
Awesome job! Thanks. |
It will be on npm once pr is merged |
Published as formidable@3.4.0 |
Oh nice, v3 is now However... would be good to get some documentation / types! I've documented this a bit: Migration guide?Unfortunately, in upgrading from I was looking for a "Migrating from v2 to v3" guide, I only found this Version History file which seems more like (partly outdated) historical information: But maybe this is not documentation that the Formidable team will provide? 😬 Release notes?There are also release notes for
Broken types?Maybe the DefinitelyTyped types at cc @martin-badin @gboer @peterblazejewicz as "code owners" of Soo... looks like it's time for a bit of trial and error to see how to get this working... 😬 |
The problems in our project was associated with this change from the v3 changelog:
Our code expected a single file as an object instead of an array with a single item inside. It appears |
I did a PR for |
this could be, I'm not sure if tests on DT for v2 covers code patterns that are changed in v3 (including changed imports, |
…karlhorky * Change version number * Add overload for promise version of form.parse PR: node-formidable/formidable#940 Issue: node-formidable/formidable#685 * Add test * Fix version * Remove patch version
…ise overload by @karlhorky * Change version number * Add overload for promise version of form.parse PR: node-formidable/formidable#940 Issue: node-formidable/formidable#685 * Add test * Fix version * Remove patch version
I am thinking that it could be nice to make
form.parse()
promisified: if no callback is provided, it will return a promise.This could allow us to rewrite the following code:
Into something like this:
Is this something that has been considered already?
I had a quick look at the code and it seems that
parse
currently returnsthis
(i suppose to allow method chaining). This seems to be a potential blocker for this feature (as it will require a breaking change), but as an alternative, it could be possible to create a new method calledparsePromise
or something similar, which can act as a wrapper for the original parse method...The main advantages I see in supporting this syntax are the following:
Thoughts?
If this idea resonates with the maintainers and the community, I'd be happy to find some time to submit a PR...
The text was updated successfully, but these errors were encountered: