Skip to content

Formidable monorepo and v4 perp #997

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Formidable monorepo and v4 perp #997

wants to merge 3 commits into from

Conversation

tunnckoCore
Copy link
Member

@tunnckoCore tunnckoCore commented Apr 27, 2025

Moving to a monorepo and TypeScript.

There will be couple of benefits with that like we can have v1, v2, v3 and others as separate directories and not separate branches. We can make CI builds based on that too.

I played with a lot of variants, so there will be:

  • package for each major, like packages/v1 (or similar), v2, v3,
  • a v3-trimmed variant,
  • benchmarks package,
  • v4 built on the old/current parser,
  • v4 with fresh parser,
  • v4 built on @mjackson/multipart-parser
  • helpers and s3 adapter
  • frontend utils

What i just started realizing is that the HTTP Multipart is pretty bad, and there might be an alternative way to handle all that a lot better, like..

What if on the backend user defines formidable(req, options) but on his frontend he also get the formidableClient(e.target, options), the client side part will basically get the FileList and send in parallel each File to a server endpoint that is handled by the formidable(req) and just does the validation and checking on the server.

That way we can accept multiple requests at the same time and validate and stream to a third-party like S3 or the disk. Usually what happens is, no matter how many files and fields there are, on the server end we (any body parser) get just one stream that we gotta process "synchronously", there's no other way - but that's the nature of streams.

eg. in frontend

function handler() {
  const files = event.target.files as FileList;
  const results = await Promise.all(files.map((file: File) => {
    return fetch('/api/upload', {
      method: 'POST',
      body: file
    })
  }))
}

and then, on the endpoint backend, you just get the requests, validate it and send it wherever you want (disk or S3).

Signed-off-by: tunnckoCore <5038030+tunnckoCore@users.noreply.github.com>
Signed-off-by: tunnckoCore <5038030+tunnckoCore@users.noreply.github.com>
Signed-off-by: tunnckoCore <5038030+tunnckoCore@users.noreply.github.com>
@tunnckoCore tunnckoCore added the do not merge When something is not yet finished. Could be used with Status:blocked label Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge When something is not yet finished. Could be used with Status:blocked
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant