Skip to content
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

Merged
merged 13 commits into from
Oct 26, 2022
Merged

feature/rework to typescript remove deprecated strict option #213

merged 13 commits into from
Oct 26, 2022

Conversation

TheDadi
Copy link
Contributor

@TheDadi TheDadi commented Oct 19, 2022

  • reworked the module to typescript
  • removed the deprecated strict option
  • added zod for options validation

@MarkHerhold
Copy link
Contributor

At first glance, this looks great! I will review this weekend.

app.use(
koaBody({
parsedMethods: [
HttpMethodEnum.PATCH,
Copy link
Contributor

@MarkHerhold MarkHerhold Oct 22, 2022

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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 🥇

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return e;
}

const error = new Error(typeof e === 'object' ? `${JSON.stringify(e)}` : `${String(e)}`);
Copy link
Contributor

@MarkHerhold MarkHerhold Oct 22, 2022

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

Copy link
Contributor Author

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`
Copy link
Contributor

@MarkHerhold MarkHerhold Oct 22, 2022

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

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

@TheDadi TheDadi Oct 24, 2022

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",
Copy link
Contributor

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",
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are a typescript project now, we export typings along side with our files and therefore typescript can resolve them without mentioning them in the package.json
Bildschirmfoto 2022-10-24 um 16 02 50

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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({
Copy link
Contributor

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",
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@MarkHerhold
Copy link
Contributor

I think after the last 2 or so requested changes, this is good to merge!

@TheDadi
Copy link
Contributor Author

TheDadi commented Oct 25, 2022

@MarkHerhold should be ready now. 🍾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants