-
-
Notifications
You must be signed in to change notification settings - Fork 683
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
Rewrite to Typescript #854
base: master
Are you sure you want to change the base?
Conversation
I have a few questions for now:
|
Converting to Typescript is already a huge task. You refactoring the code at the same time reduces the likelihood of this PR being merged fast. Because it creates opportunity for disagreement. |
|
I don't know where but if it is always true then maybe it is a leftover from before a refactor where it wasn't the case |
Maybe in a future PR we will make .parse return a Promise so try to not change too much in this PR |
My point is, that since the plugin does not return (only modifies |
You are right, rewrite to TS is huge in itself, but in order to make usage of TS sensible, some parts might need to be rewritten. |
Well, the point was not to make it a promise. The current implementation of the Take the code below:
Since the
This could be fixed using a simple if statement in This would also make the export class IncomingForm<
// Setting this is unsafe, but is normal practice to allow developers to define expected output
Fields extends Record<string, string | string[]> | string[],
Files extends Record<string, FormidableFile | FormidableFile[]>
> extends EventEmitter {
readonly options: FormidableOptions<Fields, Files>;
error?: Error;
headers?: IncomingHttpHeaders;
type?: string;
ended = false;
bytesExpected = 0;
bytesReceived = 0;
readonly openedFiles: FormidableFile[] = [];
private req?: IncomingMessage;
private parser: undefined;
private flushing = 0;
private fieldsSize = 0;
private totalFileSize = 0;
private plugins: Transform[] = [];
} into export class IncomingForm<
// Setting this is unsafe, but is normal practice to allow developers to define expected output
Fields extends Record<string, string | string[]> | string[],
Files extends Record<string, FormidableFile | FormidableFile[]>
> extends EventEmitter {
readonly options: FormidableOptions<Fields, Files>;
private readonly headers = this.getHeaders(this.req);
private readonly type = this.getType(this.headers);
// ended = false; // Redundant, once it is done, the parse method returns and all cease activity, can be kept thought...
// error?: Error; // Same as above
private readonly bytesExpected = this.getExpectedBytes(this.headers);
bytesReceived = 0;
readonly openedFiles: FormidableFile[] = [];
private flushing = 0;
private fieldsSize = 0;
private totalFileSize = 0;
private plugins: Transform[] = [];
constructor(
private readonly req: IncomingMessage,
) {}
} |
This is work in progress
not to be merged yet!
Formidable (IncommingForm)
My main concern here is that a log of variables is not defined before the
parse
method is called. From my understanding, the idea is that oneFormidable
instance can be parsing one request at a time, but can be reused after it has completed reading the form. (Why is it that it can be reused, what is the point?)I would propose, that the
parse
would return a subclass, that would only live until the parsing is complete, then it would be a frozen object/class instance. The parse method then could:"on"
and"true"
to true and the rest to false).Plugins
I still have more to read through.
Parsers
I still have more to read through.
Misc
Formidable.parse
? It could return aPromise<ParsedForm>
, whereParsedForm
is: