Comparing version 1.0.2 to 1.1.0
@@ -142,3 +142,3 @@ import { IncomingMessage, ServerResponse, OutgoingMessage } from 'node:http'; | ||
static __h3_error__: boolean; | ||
toJSON(): Pick<H3Error, "statusCode" | "statusMessage" | "data" | "message">; | ||
toJSON(): Pick<H3Error, "data" | "statusCode" | "statusMessage" | "message">; | ||
statusCode: number; | ||
@@ -175,2 +175,9 @@ fatal: boolean; | ||
interface MultiPartData { | ||
data: Buffer; | ||
name?: string; | ||
filename?: string; | ||
type?: string; | ||
} | ||
/** | ||
@@ -196,2 +203,3 @@ * Reads body of the request and returns encoded raw string (default) or `Buffer` if encoding if falsy. | ||
declare function readBody<T = any>(event: H3Event): Promise<T>; | ||
declare function readMultipartFormData(event: H3Event): Promise<MultiPartData[] | undefined>; | ||
@@ -278,2 +286,13 @@ interface CacheConditions { | ||
declare function send(event: H3Event, data?: any, type?: string): Promise<void>; | ||
/** | ||
* Respond with an empty payload.<br> | ||
* Note that calling this function will close the connection and no other data can be sent to the client afterwards. | ||
* | ||
* @param event H3 event | ||
* @param code status code to be send. By default, it is `204 No Content`. | ||
*/ | ||
declare function sendNoContent(event: H3Event, code?: number): void; | ||
declare function setResponseStatus(event: H3Event, code: number, text?: string): void; | ||
declare function getResponseStatus(event: H3Event): number; | ||
declare function getResponseStatusText(event: H3Event): string; | ||
declare function defaultContentType(event: H3Event, type?: string): void; | ||
@@ -310,2 +329,2 @@ declare function sendRedirect(event: H3Event, location: string, code?: number): Promise<void>; | ||
export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CreateRouterOptions, DynamicEventHandler, Encoding, EventHandler, EventHandlerResponse, H3Error, H3Event, H3EventContext, H3Headers, H3Response, HTTPMethod, InputLayer, InputStack, Layer, LazyEventHandler, MIMES, Matcher, NodeEventContext, NodeListener, NodeMiddleware, NodePromisifiedHandler, ProxyOptions, RequestHeaders, Router, RouterMethod, RouterUse, Stack, appendHeader, appendHeaders, appendResponseHeader, appendResponseHeaders, assertMethod, callNodeListener, createApp, createAppEventHandler, createError, createEvent, createRouter, defaultContentType, defineEventHandler, defineLazyEventHandler, defineNodeListener, defineNodeMiddleware, deleteCookie, dynamicEventHandler, eventHandler, fromNodeMiddleware, getCookie, getHeader, getHeaders, getMethod, getQuery, getRequestHeader, getRequestHeaders, getResponseHeader, getResponseHeaders, getRouterParam, getRouterParams, handleCacheHeaders, isError, isEvent, isEventHandler, isMethod, isStream, lazyEventHandler, parseCookies, promisifyNodeListener, proxyRequest, readBody, readRawBody, send, sendError, sendProxy, sendRedirect, sendStream, setCookie, setHeader, setHeaders, setResponseHeader, setResponseHeaders, toEventHandler, toNodeListener, use, useBase, writeEarlyHints }; | ||
export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CreateRouterOptions, DynamicEventHandler, Encoding, EventHandler, EventHandlerResponse, H3Error, H3Event, H3EventContext, H3Headers, H3Response, HTTPMethod, InputLayer, InputStack, Layer, LazyEventHandler, MIMES, Matcher, NodeEventContext, NodeListener, NodeMiddleware, NodePromisifiedHandler, ProxyOptions, RequestHeaders, Router, RouterMethod, RouterUse, Stack, appendHeader, appendHeaders, appendResponseHeader, appendResponseHeaders, assertMethod, callNodeListener, createApp, createAppEventHandler, createError, createEvent, createRouter, defaultContentType, defineEventHandler, defineLazyEventHandler, defineNodeListener, defineNodeMiddleware, deleteCookie, dynamicEventHandler, eventHandler, fromNodeMiddleware, getCookie, getHeader, getHeaders, getMethod, getQuery, getRequestHeader, getRequestHeaders, getResponseHeader, getResponseHeaders, getResponseStatus, getResponseStatusText, getRouterParam, getRouterParams, handleCacheHeaders, isError, isEvent, isEventHandler, isMethod, isStream, lazyEventHandler, parseCookies, promisifyNodeListener, proxyRequest, readBody, readMultipartFormData, readRawBody, send, sendError, sendNoContent, sendProxy, sendRedirect, sendStream, setCookie, setHeader, setHeaders, setResponseHeader, setResponseHeaders, setResponseStatus, toEventHandler, toNodeListener, use, useBase, writeEarlyHints }; |
{ | ||
"name": "h3", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Tiny JavaScript Server", | ||
@@ -30,23 +30,23 @@ "repository": "unjs/h3", | ||
"0x": "^5.4.1", | ||
"@types/express": "^4.17.14", | ||
"@types/node": "^18.11.14", | ||
"@types/express": "^4.17.16", | ||
"@types/node": "^18.11.18", | ||
"@types/supertest": "^2.0.12", | ||
"@vitest/coverage-c8": "^0.25.8", | ||
"@vitest/coverage-c8": "^0.28.2", | ||
"autocannon": "^7.10.0", | ||
"changelogen": "^0.4.0", | ||
"changelogen": "^0.4.1", | ||
"connect": "^3.7.0", | ||
"eslint": "^8.29.0", | ||
"eslint-config-unjs": "^0.0.3", | ||
"eslint": "^8.32.0", | ||
"eslint-config-unjs": "^0.1.0", | ||
"express": "^4.18.2", | ||
"get-port": "^6.1.2", | ||
"jiti": "^1.16.0", | ||
"listhen": "^1.0.1", | ||
"jiti": "^1.16.2", | ||
"listhen": "^1.0.2", | ||
"node-fetch-native": "^1.0.1", | ||
"prettier": "^2.8.1", | ||
"prettier": "^2.8.3", | ||
"supertest": "^6.3.3", | ||
"typescript": "^4.9.4", | ||
"unbuild": "^1.0.2", | ||
"vitest": "^0.25.8" | ||
"unbuild": "^1.1.1", | ||
"vitest": "^0.28.2" | ||
}, | ||
"packageManager": "pnpm@7.18.2", | ||
"packageManager": "pnpm@7.26.0", | ||
"scripts": { | ||
@@ -53,0 +53,0 @@ "build": "unbuild", |
@@ -42,24 +42,28 @@ [![npm downloads](https://img.shields.io/npm/dm/h3.svg?style=flat-square)](https://npmjs.com/package/h3) | ||
```ts | ||
import { createServer } from 'http' | ||
import { createApp, eventHandler, toNodeListener } from 'h3' | ||
import { createServer } from "node:http"; | ||
import { createApp, eventHandler, toNodeListener } from "h3"; | ||
const app = createApp() | ||
app.use('/', eventHandler(() => 'Hello world!')) | ||
const app = createApp(); | ||
app.use( | ||
"/", | ||
eventHandler(() => "Hello world!") | ||
); | ||
createServer(toNodeListener(app)).listen(process.env.PORT || 3000) | ||
createServer(toNodeListener(app)).listen(process.env.PORT || 3000); | ||
``` | ||
<details> | ||
<summary>Example using <a href="https://github.com/unjs/listhen">listhen</a> for an elegant listener.</summary> | ||
Example using <a href="https://github.com/unjs/listhen">listhen</a> for an elegant listener: | ||
```ts | ||
import { createApp, toNodeListener } from 'h3' | ||
import { listen } from 'listhen' | ||
import { createApp, eventHandler, toNodeListener } from "h3"; | ||
import { listen } from "listhen"; | ||
const app = createApp() | ||
app.use('/', eventHandler(() => 'Hello world!')) | ||
const app = createApp(); | ||
app.use( | ||
"/", | ||
eventHandler(() => "Hello world!") | ||
); | ||
listen(toNodeListener(app)) | ||
listen(toNodeListener(app)); | ||
``` | ||
</details> | ||
@@ -73,11 +77,17 @@ ## Router | ||
```ts | ||
import { createApp, eventHandler, createRouter } from 'h3' | ||
import { createApp, eventHandler, createRouter } from "h3"; | ||
const app = createApp() | ||
const app = createApp(); | ||
const router = createRouter() | ||
.get('/', eventHandler(() => 'Hello World!')) | ||
.get('/hello/:name', eventHandler(event => `Hello ${event.context.params.name}!`)) | ||
.get( | ||
"/", | ||
eventHandler(() => "Hello World!") | ||
) | ||
.get( | ||
"/hello/:name", | ||
eventHandler((event) => `Hello ${event.context.params.name}!`) | ||
); | ||
app.use(router) | ||
app.use(router); | ||
``` | ||
@@ -143,2 +153,7 @@ | ||
- `proxyRequest(event, { target, headers?, fetchOptions?, fetch?, sendStream? })` | ||
- `sendNoContent(event, code = 204)` | ||
- `setResponseStatus(event, status)` | ||
- `getResponseStatus(event)` | ||
- `getResponseStatusText(event)` | ||
- `readMultipartFormData(event)` | ||
@@ -145,0 +160,0 @@ 👉 You can learn more about usage in [JSDocs Documentation](https://www.jsdocs.io/package/h3#package-functions). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84576
2406
180