mia-platform / mia-platform/custom-plugin-lib
DecoratedRequest typing support to Query, Headers and Params
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 25
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
## The feauture or bug you are proposing
Extend `DecoratedRequest` TypeScript support to Querystring, Headers and Params too.
## The description of the bug or the rationale of your proposal
Right now the `[DecoratedRequest interface](https://github.com/mia-platform/custom-plugin-lib/blob/9f20da345f208c391527c9c74e4bb7bcbc2955c2/index.d.ts#L60)` allows to specify the Generic only for the inner FastifyRequest body, meaning that if I can't specify the shape on any other request parameter (being Querystring, Headers or Params).
## A snippet of code for replicating the issue or showing the proposal usage if applicable
```
interface HelloQueryParameters {
who?: string
}
interface HelloRequest {
Querystring?: HelloQueryParameters
}
service.addRawCustomPlugin('GET', '/hello', async function (request:DecoratedRequest, reply:FastifyReply) {
return { message: `Hello ${request.getUserId() || (request.query as HelloQueryParameters).who}` }
}, schema)
```
In the snippet above, `request.query` is threated as `unknown`
## The expected result for your bug
```
service.addRawCustomPlugin('GET', '/hello', async function (request:DecoratedRequest, reply:FastifyReply) {
return { message: `Hello ${request.getUserId() || request.query.who}` }
}, schema)
```
### Your environment
node: v12.17.0
custom-plugin-lib: `@mia-platform/custom-plugin-lib@4.1.1`
os: MacOS
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DecoratedRequest interface in index.d.ts, especially the generic currently used for the FastifyRequest body. Check how query, headers, and params are typed, then verify that the HelloRequest example can access request.query.who without a cast while preserving existing body typing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100