Skip to content

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

Open
@slewsys

Description

@slewsys

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)
                })
            })
        })
    })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions