-
Notifications
You must be signed in to change notification settings - Fork 130
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
feature/rework to typescript remove deprecated strict option #213
feature/rework to typescript remove deprecated strict option #213
Conversation
TheDadi
commented
Oct 19, 2022
- reworked the module to typescript
- removed the deprecated strict option
- added zod for options validation
At first glance, this looks great! I will review this weekend. |
app.use( | ||
koaBody({ | ||
parsedMethods: [ | ||
HttpMethodEnum.PATCH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to note the use of this in the README
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just the typescript approach, you can still pass in 'GET', 'POST', 'PUT' as normal strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we can note them if you want. You decide 🥇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/utils/throwable-to-error.ts
Outdated
return e; | ||
} | ||
|
||
const error = new Error(typeof e === 'object' ? `${JSON.stringify(e)}` : `${String(e)}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we simplify this to:
const error = new Error(typeof e === 'object' ? JSON.stringify(e) : '' + e);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 👍
README.md
Outdated
@@ -141,22 +147,28 @@ Request Body: {"declaration":{"attributes":{"version":"1.0"}},"elements":[{"type | |||
- `includeUnparsed` **{Boolean}** Toggles co-body returnRawBody option; if set to true, for form encoded and JSON requests the raw, unparsed request body will be attached to `ctx.request.body` using a `Symbol` ([see details](#a-note-about-unparsed-request-bodies)), default `false` | |||
- `formidable` **{Object}** Options to pass to the formidable multipart parser | |||
- `onError` **{Function}** Custom error handle, if throw an error, you can customize the response - onError(error, context), default will throw | |||
- `strict` **{Boolean}** ***DEPRECATED*** If enabled, don't parse GET, HEAD, DELETE requests, default `true` | |||
- `strict` **{Boolean}** **_DEPRECATED_** If enabled, don't parse GET, HEAD, DELETE requests, default `true` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can delete documentation of this option since it's being removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 👍
@@ -1,29 +1,36 @@ | |||
## Problem/Feature Request Summary | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what tool did you use to format md files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i introduced prettier that also works for md files
"@types/co-body": "^6.1.0", | ||
"@types/formidable": "^2.0.5", | ||
"@types/koa": "^2.13.5", | ||
"co-body": "^6.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for updating these :)
@@ -2,10 +2,21 @@ | |||
"name": "koa-body", | |||
"version": "5.0.0", | |||
"description": "A Koa body parser middleware. Supports multipart, urlencoded and JSON request bodies.", | |||
"main": "index.js", | |||
"types": "./index.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to specify types
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the types keyword would be there so non-typescript projects' IDEs could know where to find type info
I'll test this out locally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheDadi yeah let's re-add the types property please
https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
onFileBegin?: (name: string, file: File) => void; | ||
}; | ||
|
||
export const KoaBodyMiddlewareOptionsSchema = z.object({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love this
"scripts": { | ||
"test": "mocha test/unit/", | ||
"build": "npm run check-format && npm run test && npm run clean && npm run build:typescript", | ||
"build:typescript": "tsc --build tsconfig.build.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add "prepack": "npm run build",
to ensure we only publish with built and tested code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
adding note about HttpMethodEnum
I think after the last 2 or so requested changes, this is good to merge! |
… feature/typescript-rewrite
@MarkHerhold should be ready now. 🍾 |