Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: unjs/h3
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.7.1
Choose a base ref
...
head repository: unjs/h3
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.7.2
Choose a head ref
  • 4 commits
  • 5 files changed
  • 2 contributors

Commits on Apr 8, 2022

  1. Copy the full SHA
    884460b View commit details
  2. Copy the full SHA
    6fcdc22 View commit details
  3. refactor: update internal type

    pi0 committed Apr 8, 2022
    Copy the full SHA
    ccad751 View commit details
  4. chore(release): 0.7.2

    pi0 committed Apr 8, 2022
    Copy the full SHA
    8b2e1bc View commit details
Showing with 23 additions and 9 deletions.
  1. +12 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +8 −6 src/event.ts
  4. +1 −1 src/types.ts
  5. +1 −1 src/utils/body.ts
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.7.2](https://github.com/unjs/h3/compare/v0.7.1...v0.7.2) (2022-04-08)


### Features

* add generic response type support for eventHandler ([6fcdc22](https://github.com/unjs/h3/commit/6fcdc22dd20df731cd31b99ebac0cdb473541297))


### Bug Fixes

* add missing `PATCH` method to types ([#88](https://github.com/unjs/h3/issues/88)) ([884460b](https://github.com/unjs/h3/commit/884460bffd210de9042cd9ebe3b84d1c07b40a06))

### [0.7.1](https://github.com/unjs/h3/compare/v0.7.0...v0.7.1) (2022-04-07)


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "h3",
"version": "0.7.1",
"version": "0.7.2",
"description": "Tiny JavaScript Server",
"repository": "unjs/h3",
"license": "MIT",
14 changes: 8 additions & 6 deletions src/event.ts
Original file line number Diff line number Diff line change
@@ -12,16 +12,18 @@ export interface H3Event {

export type CompatibilityEvent = H3Event | IncomingMessage

export type _JSONValue<T=string|number|boolean> = T | T[] | Record<string, T>
type _JSONValue<T=string|number|boolean> = T | T[] | Record<string, T>
export type JSONValue = _JSONValue<_JSONValue>
export type H3Response = void | JSONValue | Buffer

export interface EventHandler {
type _H3Response = void | JSONValue | Buffer
export type H3Response = _H3Response | Promise<_H3Response>

export interface EventHandler<T extends H3Response = H3Response> {
'__is_handler__'?: true
(event: CompatibilityEvent): H3Response| Promise<H3Response>
(event: CompatibilityEvent): T
}

export function defineEventHandler (handler: EventHandler) {
export function defineEventHandler <T extends H3Response = H3Response> (handler: EventHandler<T>): EventHandler<T> {
handler.__is_handler__ = true
return handler
}
@@ -82,7 +84,7 @@ export function toEventHandler (handler: CompatibilityEventHandler): EventHandle
throw new TypeError('Invalid handler. It should be a function:', handler)
}
return eventHandler((event) => {
return callHandler(handler, event.req as IncomingMessage, event.res) as Promise<H3Response>
return callHandler(handler, event.req as IncomingMessage, event.res) as H3Response
})
}

2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -27,4 +27,4 @@ export type LazyHandler = () => Handler | Promise<Handler>
export type Encoding = false | 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex'

// https://www.rfc-editor.org/rfc/rfc7231#section-4.1
export type HTTPMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE'
export type HTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE'
2 changes: 1 addition & 1 deletion src/utils/body.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import { assertMethod } from './request'
const RawBodySymbol = Symbol('h3RawBody')
const ParsedBodySymbol = Symbol('h3RawBody')

const PayloadMethods = ['PATCH', 'POST', 'PUT', 'DELETE'] as HTTPMethod[]
const PayloadMethods: HTTPMethod[] = ['PATCH', 'POST', 'PUT', 'DELETE']

/**
* Reads body of the request and returns encoded raw string (default) or `Buffer` if encoding if falsy.