feat: move to `compress` and `decompress` route specific options, improved typescript types and tests, reorganize tests
darkgl0w opened this issue Β· comments
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the feature has not already been requested
π Feature Proposal
Hello,
following the PR #196, I would like to work on a few things for this package that will help improve development experience:
- Add
compress
anddecompress
route shorthand configuration properties - Improve typescript types and actually test those types
- Update the documentation
- Reorganize and/or rewrite tests (renaming files following
xxx.test.js
convention, making groups with sub-tests, ...)
Note: some of those changes are breaking changes and will require a major bump.
If you think my proposal is acceptable the first 3 points are covered by this PR #199.
Regards.
Motivation
- It will follow the way over official packages define specific route options, it will be shorter ( π€£ ) and more intuitive.
- It will have complete typings and those types will actually be tested.
Example
Current way to configure specific route options:
'use strict'
const zlib = require('zlib')
const fastify = require('fastify')()
fastify.register(require('fastify-compress', { global: false })
fastify.get('/one', {
config: {
compress: { createGzip: () => zlib.createGzip() },
decompress: { createGunzip: () => zlib.createGunzip() }
}
}, (request, reply) => {
// ...
})
fastify.route({
method: 'GET',
path: '/two',
config: {
compress: { createGzip: () => zlib.createGzip() },
decompress: { createGunzip: () => zlib.createGunzip() }
},
handler: (request, reply) => {
// ...
}
})
New way to configure specific route options:
'use strict'
const zlib = require('zlib')
const fastify = require('fastify')()
fastify.register(require('fastify-compress', { global: false })
fastify.get('/one', {
compress: { createGzip: () => zlib.createGzip() },
decompress: { createGunzip: () => zlib.createGunzip() }
}, (request, reply) => {
// ...
})
fastify.route({
method: 'GET',
path: '/two',
compress: { createGzip: () => zlib.createGzip() },
decompress: { createGunzip: () => zlib.createGunzip() },
handler: (request, reply) => {
// ...
}
})