Skip to content
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

Propose breaking change: replace await-busboy with async-busboy #5

Open
slewsys opened this issue Jul 11, 2022 · 2 comments
Open

Propose breaking change: replace await-busboy with async-busboy #5

slewsys opened this issue Jul 11, 2022 · 2 comments

Comments

@slewsys
Copy link

slewsys commented Jul 11, 2022

Hi,
Thank you for your contributions! I'd like to hazard suggesting a breaking change: replace await-busboy with async-busboy.
What I like about async-busboy is that the interface is cleaner as can be seen in the updated joi-router test fragment below. The property parts has been replaced by multipart to reflect the change:

    describe('request.multipart', () => {
        describe('when expected type is', () => {
            'stream multipart'.split(' ').forEach((type) => {
                describe(`"${type}"`, () => {
                    it('is a co-busboy object', (done) => {
                        const r = router()
                        r.route({
                            method: 'put',
                            path: '/',
                            handler: async (ctx) => {
                                let filename
                                let { files, fields } = await ctx.request.multipart
                                files.forEach(file => filename = file.filename)
                                ctx.body = {
                                    color: fields.color,
                                    file: filename
                                }
                            },
                            validate: {
                                type: type
                            }
                        })
                        const app = new Koa()
                        const document = `${__dirname}/fixtures/koa.png`
                        app.use(r.middleware())
                        test(app)
                            .put('/')
                            .attach('file1', document)
                            .field('color', 'green')
                            .expect(`{"color":"green","file":"${basename(document)}"}`, done)
                    })
                })
            })
            describe('not specified', () => {
                it('is undefined', (done) => {
                    const r = router()
                    r.route({
                        method: 'put',
                        path: '/',
                        handler: (ctx) => {
                            ctx.status = undefined === ctx.request.multipart ?
                                200 :
                                500
                        },
                        validate: {}
                    })
                    const app = new Koa()
                    app.use(r.middleware())
                    const b = new Buffer(1024)
                    b.fill('a')
                    test(app)
                        .put('/')
                        .attach('file1', b)
                        .expect(200, done)
                })
            })
        })
    })
@3imed-jaberi
Copy link
Member

Currently this module wrap the @fastify/busboy with the same interface as await-busboy, so in practical this module use @fastify/busboy directly and we can provide a different API or expected results format ... Could you please identify exactly what you want exactly, and please check this impl file!!

Also, it will be better if you can submit a PR!

@slewsys
Copy link
Author

slewsys commented Apr 7, 2024

Hi,
The koajs joi-router project was not being maintained a couple of years ago, so I reworked it, starting with mscdex busboy. The results can be found as
revoinc-async-busboy and revoinc-koa-joi-router.

After completing that work, I came across this project and made the comment above. To be honest, I'd have to go back to the original koajs joi-router project test suite to know the difference. But you're welcome to use the revoinc code if you find merit in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants