0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-27 16:06:24 +01:00
Commit Graph

64 Commits

Author SHA1 Message Date
uttk
c378dd99a4
fix(validator): Fixed a bug in hono/validator where URL Encoded Data could not be validated if the Content-Type included charset. (#3297) 2024-08-19 14:44:57 +09:00
Nick Randall
0c1e89964e
fix(validator): Allow form data will mutliple values appended (#3273) 2024-08-17 18:55:40 +09:00
Ernest Badu
81a1f07d4b
fix(validator): support multipart headers without a space separating boundary (#3286) 2024-08-17 18:49:01 +09:00
Yusuke Wada
d58b98aa72
fix(types): param in ValidationTargets supports optional param (#3229) 2024-08-06 20:15:21 +09:00
Yusuke Wada
cdd48f4fd4
fix(validator): support application/json with a charset (#3199) 2024-07-28 16:39:40 +09:00
Gaspard Wierzbinski
0417830fe9
fix(validator): Add double quotation marks to multipart checker regex (#3195) 2024-07-28 16:22:52 +09:00
Yusuke Wada
4171896681
fix(validator): allow content-type mismatches (#3165) 2024-07-20 23:05:11 +09:00
Ame_x
f1c7d312a8
fix(validator-types): type Alignment with Web Standards (#3120)
* fix(validator-types): type Alignment with Web Standards

* fix
2024-07-11 16:34:36 +09:00
Yusuke Wada
ec58511247
fix(types): allow string[] | File[] for RPC form value (#3117) 2024-07-10 10:23:07 +09:00
Yusuke Wada
2d452f2bd2
fix(validator): don't return a FormData if formData is cached (#3067)
* fix(validator): don't return a FormData if formData is cached

* fixed typo

* test the value
2024-07-01 16:29:34 +09:00
Balint Orosz
bc39c3b897
fix(validator): support json api header (#2855) 2024-05-29 23:17:14 +09:00
Yusuke Wada
6d9f1f09a9
docs: add module doc (#2796) 2024-05-26 14:16:25 +09:00
Yusuke Wada
cc4b2b3c7f
chore(lint): update eslint rules (#2790)
* chore(lint): update eslint rules

* fix formats
2024-05-26 05:17:45 +09:00
Taku Amano
406abbb12c
feat(utils): specify detailed return type for parseBody (#2771)
* feat(utils): specify detailed return type for parseBody

* chore: denoify

* fix(test): fix import type statement

Co-authored-by: fzn0x <fncolon@pm.me>

* fix(utils): Accept `parseBody<T extends BodyData>()`

* refactor: Use `BodyData<{ all: true }>` explicitly

* chore: denoify

* feat(request): add detailed type for c.req.parseBody()

* chore: denoify

* test: add tests for specifying return type for parseBody

* refactor: remove unnecessary type annotation in parseBody method

* refactor(utils): improve type for IDE

* chore: denoify

* refactor(utils): Change to a better name

---------

Co-authored-by: fzn0x <fncolon@pm.me>
2024-05-24 11:38:00 +09:00
Yusuke Wada
f7225eefe6
test(validator): compatibility with Node.js v20.13.1 (#2682) 2024-05-16 08:08:12 +09:00
Moritz Rebbert
aebaa28462
feat(validator): check for json subtypes in validator (#2634)
* check for json subtypes in validator

* formatting and deno_dist added

* review fix, string#match -> regexp#test

* format & lint
2024-05-09 16:23:57 +09:00
Yusuke Wada
799a8d8ae5
fix(validator): form supports multiple values with foo[] (#2639)
* fix(validator): `form` supports multiple values `foo[]`

* denoify
2024-05-08 14:22:17 +09:00
Trung Dang
2b2dacc2e1
feat(types): improve response types flow (#2581)
* fix: `ClientResponse` now properly extends fetch's `Response`

Better experience / fix types error when working with functions that expects a fetch's `Response`

* feat(context): switch from `InterfaceToType` to `Simplify` for better performance

Also automatically infer ReturnType for cleaner code

* feat(context): infer `TypedResponse` for `TextRespond`

* feat: improve response types flow with `ResponseFormat`

Co-authored-by: Yusuke Wada <yusuke@kamawada.com>

* tests: adjust & add new tests for `TextRespond` & `ResponseFormat`

* tests: improve test of using interface

* chore: denoify

---------

Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
2024-05-03 01:28:15 +09:00
kosei28
8129a3a06e
feat(rpc): Add status code to response type (#2499)
* feat: add status code to response type

* fix MergeSchemaPath

* remove TypedResponseInit

* fix issues

* update tests

* add types tests

* add client tests

* denoify

* fix client test

* fix validator test

---------

Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
2024-04-30 20:03:32 +09:00
nagasawaryoya
a33b9b7121
fix(validator): Default use to OutputTypeExcludeResponseType when InputType is unknown (#2500)
* fix(validator): Default use to `OutputTypeExcludeResponseType` when `InputType` is unknown

* denoify
2024-04-13 06:43:59 +09:00
Yusuke Wada
9e54e77bbc Merge branch 'main' into next 2024-03-30 17:57:40 +09:00
Yusuke Wada
1d30cecc4f
fix(validator): await cached contents (#2430)
* fix(validator): `await` cached contents

* denoify
2024-03-28 07:13:08 +09:00
Yusuke Wada
40f7f599ef
feat(request): cache body for reusing (#2416)
* feat(request): cache body for re-using

* denoify
2024-03-27 05:02:30 +09:00
Yusuke Wada
8e4293b219
fix(validator): use cached body for json and form validation (#2392)
* fix(validator): use cached body for `json` and `form` validation

* denoify

* teak
2024-03-20 21:33:29 +09:00
Yusuke Wada
e2f1d145bd
fix(validator): use the cached content (#2234)
* fix(validator): use the cached content

* denoify
2024-02-17 22:47:23 +09:00
Yusuke Wada
ebbd444661
feat!(validator): supports transformation (#2130)
* feat!(validator): supports transformation

* refactored

* denoify
2024-02-02 13:21:08 +09:00
Yusuke Wada
e3051039c6
feat!: validator throws error rathar than return c.json() (#2021)
* feat!: validator throws error rathar than `return c.json()`

* denoify
2024-01-18 23:52:16 +09:00
Yusuke Wada
fb96a76ee5
feat!: remove deprecated features (#1934)
* feat!: remove deprecated features

* denoify

* remove not used `import`

* denoify
2024-01-10 09:33:44 +09:00
Yusuke Wada
dbdbd227a2
fix(validator): exclude Response type for returned values from c.req.valid() (#1914)
* fix(validator): exclude Response type for returned values from `c.req.valid()`

* denoify
2024-01-08 06:58:43 +09:00
Taku Amano
d16aedfffd
feat: Ensure that calls to c.json() have a type equivalent to c.jsonT() (#1728)
* feat: Ensure that calls to `c.json()` have a type equivalent to `c.jsonT()`

* refactor: Objects with "response" properties are never returned by the handler

* refactor: "status" is not needed in TypedResponse

* refactor: Revive `c.jsonT()` and add @deprecated label

* refactor: Tweaks commenting on "eslint-disable" broken by `format:fix`

* test: Use `c.json()` instead of `c.jsonT()` to make sure there are no problems

* refactor: allow ambiguous type for `c.json()`

* chore: denoify

* fix: Remove unused TypedResponse from import statement
2023-12-03 09:03:14 +09:00
watany
bea87a0429
feat(adaptor): Enhance AWS Lambda Event Handling and Interface (#1710) 2023-11-27 15:31:10 +09:00
Yusuke Wada
62d4d44d34
test(validator): fix the error message for node v18.18 (#1596)
* test(validator): fix the error message for node v18.18

* ci: fix node version

* fixed version

* test: fix the test pattern
2023-10-18 22:38:37 +09:00
Bruno Marques
cca7577cf4
fix: return status 500 when using validator 'form' (#1554)
* fix: return status 500 when using validator 'form'

When using `validator('form', ...)` hono is returning a 500 status
when receiving a POST request with a JSON in request body, instead
of a bad request 400, .

This is happenning due to a unhandled error in an
underlying library (@miniflare).
https://github.com/cloudflare/miniflare/pull/711

The code changes in this PR are responsible to prepare the code to
handle possible TypeError that can be thrown in the future, by the lib
doing the FormData parsing, as per, https://fetch.spec.whatwg.org/#dom-body-formdata.

This PR should wait for bugfix on @miniflare.

* fix: json validator allowing Content-Type value other than json/application

Forgery attacks will try to avoid preflight requests when POSTing JSON
payloads manipulating the HTTP header Content-Type. For example, it will
send a JSON payload with `Content-Type=text/plain`, but the request stills
containing a JSON in its body. Those requests must be rejected.

Thus, when using the validator with the target set to `json`, we must
check the Content-Type header.

* fix: change check for json Content-Type header

Change JSON validation to only allow Content-Type header starting with
'application/json'.

Change from regexp test to starsWith builtin function, to make code more
expressive.

---------

Co-authored-by: Bruno Nascimento <bruno.nascimento@csghq.com>
2023-10-12 00:21:01 +09:00
Yusuke Wada
c7fc8a033a
fix(utils/buffer): fix bufferToFormData() (#1500)
* fix(utils/buffer): fix `bufferToFormData()`

* denoify
2023-09-23 23:46:09 +09:00
Derrick Farris
5b07146cf8
test(vitest): replace jest with vitest (#1404)
* test(vitest): replace `jest` with `vitest` for core tests

* test(fastly): `jest` -> `vitest`, correct env for fastly

* test(jest): remove `jest-environment-miniflare` as dep

* test(lagon): configure `lagon` tests to run on `vitest`

* test(lambda): `jest` -> `vitest`

* test(lambda-edge): `jest` -> `vitest`

* test(node): `jest` -> `vitest`

* test(wrangler): `jest` -> `vitest`

* chore(deps): remove `jest` and `ts-jest` from deps

* test(vitest): add `yarn coverage` for checking coverage

* test(fastly): fix check for `globalThis.crypto`

* test(handler): fix stray `.only`

* test(lagon): change env file back to original path

* test(fastly): go back to `jest` until `vitest` has support for fastly env

* test(fastly): remove hack for the `crypto` global from the test
2023-09-08 17:42:28 +09:00
Yusuke Wada
5cbd89c3ae
fix(validator): cache arrayBuffer to use after validation (#1393)
* wip

* fix(validator): cache `arrayBuffer` to use after validation

* denoify

* refactor

* denoify

* make it `bufferToFormData()` in utils/buffer.ts
2023-09-03 14:43:01 +09:00
Yusuke Wada
e07019125d
feat: introduce "Helpers" (#1353)
* mv jsx

* introduce helper

* denoify & add src/helper.ts for Deno

* remove `c` not used

* remove `c` in lagon test

* remove `src/adapter.ts` not used
2023-08-21 15:22:37 +09:00
Yusuke Wada
8adc8c14c4
feat(validator): supports header and cookie (#1352)
* feat(validator): supports `header` and `cookie`

* denoify
2023-08-19 18:23:04 +09:00
Yusuke Wada
9e391cf8f9
feat(validator): deprecate queries (use query instead) (#1350)
* fixed test

* denoify
2023-08-19 17:50:50 +09:00
Yusuke Wada
f254fdc846
feat(req): cache body content (#1333)
* feat(req): cache body content

* denoify

* use destruction

* denoify
2023-08-18 16:25:48 +09:00
Yusuke Wada
f7bce19751
fix(validator): support async validator func (#1303)
* fix(validator): support async validator func

* denoify
2023-08-07 21:26:53 +09:00
Yusuke Wada
8ebd8b7b76
fix(jsonT): remove overloads from JSONTRespond (#1208)
* fix(`jsonT`): remove overloads from `JSONTRespond`

* denoify

* update tests
2023-06-29 20:09:00 +09:00
Yusuke Wada
cadb6eab41
feat(validator): query supports array params (#984)
* feat(validator): `query` supports array params

* denoify
2023-03-16 21:49:28 +09:00
Taku Amano
287498bdec
feat(validator): Allow validator to apply validation to path param. (#982)
* Allow validator to apply validation to path param.

* chore: denoify

* feat(validator): Enable passing the path to ValidationFunction as a template parameter.

* chore: denoify

Co-authored-by: yusukebe <yusuke@kamawada.com>
2023-03-15 22:20:50 +09:00
Yusuke Wada
e2a174b8ac
fix(types): infer types correctly (#983)
* v3.1.0-rc.2

* fix(types): infer path param types correctly

* denoify

* fix: infer the value type in the validation funtion

* denoify
2023-03-14 23:43:33 +09:00
Yusuke Wada
9c4197a772
feat(validator): support type transformation (#969)
* feat(validator): support type transformation

* denoify

* create `ValidationFunction` and add a test

* denoify

* rename

* denoify
2023-03-11 22:17:08 +09:00
Yusuke Wada
4636b81090
fix(type): remove unnecessary distribution (#951) 2023-03-05 23:39:04 +09:00
Yusuke Wada
b788fe619f
fix(validator): clone Request object if json or form (#926) 2023-02-25 02:36:11 +09:00
Yusuke Wada
68cbbbcde7
refactor: rename ValidationTypes to ValidationTargets (#890)
* refactor: rename `ValidationTypes` to `ValidationTargets`

* denoify
2023-02-14 06:21:30 +09:00
Yusuke Wada
17af727d49
feat(validator): moved validator outside of middleware (#879) 2023-02-11 01:18:27 +09:00