koa-better-modules / joi-router

Easy, rich and fully validated koa routing.
MIT License
3 stars 4 forks source link

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

Open slewsys opened 2 years ago

slewsys commented 2 years ago

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 commented 3 months ago

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 commented 3 months ago

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.