h3 0.7.4 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -5
- package/package.json +7 -8
package/dist/index.d.ts
CHANGED
|
@@ -10,10 +10,7 @@ interface H3Event {
|
|
|
10
10
|
context: Record<string, any>;
|
|
11
11
|
}
|
|
12
12
|
declare type CompatibilityEvent = H3Event | IncomingMessage;
|
|
13
|
-
declare type
|
|
14
|
-
declare type JSONValue = _JSONValue<_JSONValue>;
|
|
15
|
-
declare type _H3Response = void | JSONValue | Buffer;
|
|
16
|
-
declare type H3Response = _H3Response | Promise<_H3Response>;
|
|
13
|
+
declare type H3Response = any;
|
|
17
14
|
interface EventHandler<T extends H3Response = H3Response> {
|
|
18
15
|
'__is_handler__'?: true;
|
|
19
16
|
(event: CompatibilityEvent): T;
|
|
@@ -243,4 +240,4 @@ interface Router extends AddRouteShortcuts {
|
|
|
243
240
|
}
|
|
244
241
|
declare function createRouter(): Router;
|
|
245
242
|
|
|
246
|
-
export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CompatibilityEvent, CompatibilityEventHandler, DynamicEventHandler, Encoding, EventHandler, H3Error, H3Event, H3Response, HTTPMethod, Handler, IncomingMessage, InputLayer, InputStack,
|
|
243
|
+
export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CompatibilityEvent, CompatibilityEventHandler, DynamicEventHandler, Encoding, EventHandler, H3Error, H3Event, H3Response, HTTPMethod, Handler, IncomingMessage, InputLayer, InputStack, Layer, LazyEventHandler, LazyHandler, MIMES, Matcher, Middleware, NodeHandler, PromisifiedHandler, Router, RouterMethod, RouterUse, ServerResponse, Stack, appendHeader, assertMethod, callHandler, createApp, createAppEventHandler, createError, createEvent, createRouter, defaultContentType, defineEventHandler, defineHandle, defineHandler, defineLazyEventHandler, defineLazyHandler, defineMiddleware, deleteCookie, dynamicEventHandler, eventHandler, handleCacheHeaders, isError, isEvent, isEventHandler, isMethod, isStream, lazyEventHandler, lazyHandle, promisifyHandle, promisifyHandler, send, sendError, sendRedirect, sendStream, setCookie, toEventHandler, use, useBase, useBody, useCookie, useCookies, useMethod, useQuery, useRawBody };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "h3",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "Tiny JavaScript Server",
|
|
5
5
|
"repository": "unjs/h3",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"cookie-es": "^0.5.0",
|
|
22
22
|
"destr": "^1.1.1",
|
|
23
|
-
"radix3": "^0.1.
|
|
23
|
+
"radix3": "^0.1.2",
|
|
24
24
|
"ufo": "^0.8.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"connect": "latest",
|
|
36
36
|
"eslint": "latest",
|
|
37
37
|
"express": "latest",
|
|
38
|
-
"get-port": "^
|
|
38
|
+
"get-port": "^6.1.2",
|
|
39
39
|
"jiti": "latest",
|
|
40
40
|
"listhen": "latest",
|
|
41
41
|
"standard-version": "latest",
|
|
@@ -44,15 +44,14 @@
|
|
|
44
44
|
"unbuild": "latest",
|
|
45
45
|
"vitest": "latest"
|
|
46
46
|
},
|
|
47
|
-
"packageManager": "pnpm@
|
|
47
|
+
"packageManager": "pnpm@7.0.0",
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "unbuild",
|
|
50
50
|
"dev": "vitest",
|
|
51
51
|
"lint": "eslint --ext ts,mjs,cjs .",
|
|
52
52
|
"play": "jiti ./playground/index.ts",
|
|
53
53
|
"profile": "0x -o -D .profile -P 'autocannon -c 100 -p 10 -d 40 http://localhost:$PORT' ./playground/server.cjs",
|
|
54
|
-
"release": "pnpm
|
|
55
|
-
"test": "vitest run"
|
|
56
|
-
}
|
|
57
|
-
"readme": "[](https://npmjs.com/package/h3)\n[](https://npmjs.com/package/h3)\n[](https://bundlephobia.com/result?p=h3)\n[](https://github.com/unjs/h3/actions)\n[](https://codecov.io/gh/unjs/h3)\n[](https://www.jsdocs.io/package/h3)\n\n> H3 is a minimal h(ttp) framework built for high performance and portability\n\n<!--  -->\n\n## Features\n\n✔️ **Portable:** Works perfectly in Serverless, Workers, and Node.js\n\n✔️ **Compatible:** Support connect/express middleware\n\n✔️ **Minimal:** Small, tree-shakable and zero-dependency\n\n✔️ **Modern:** Native promise support\n\n✔️ **Extendable:** Ships with a set of composable utilities but can be extended\n\n✔️ **Router:** Super fast route matching using [unjs/radix3](https://github.com/unjs/radix3)\n\n## Install\n\n```bash\n# Using npm\nnpm install h3\n\n# Using yarn\nyarn add h3\n\n# Using pnpm\npnpm add h3\n```\n\n## Usage\n\n```ts\nimport { createServer } from 'http'\nimport { createApp } from 'h3'\n\nconst app = createApp()\napp.use('/', () => 'Hello world!')\n\ncreateServer(app).listen(process.env.PORT || 3000)\n```\n\n<details>\n <summary>Example using <a href=\"https://github.com/unjs/listhen\">listhen</a> for an elegant listener.</summary>\n\n```ts\nimport { createApp } from 'h3'\nimport { listen } from 'listhen'\n\nconst app = createApp()\napp.use('/', () => 'Hello world!')\n\nlisten(app)\n```\n</details>\n\n## Router\n\nThe `app` instance created by `h3` uses a middleware stack (see [how it works](#how-it-works)) with the ability to match route prefix and apply matched middleware.\n\nTo opt-in using a more advanced and convenient routing system, we can create a router instance and register it to app instance.\n\n```ts\nimport { createApp, createRouter } from 'h3'\n\nconst app = createApp()\n\nconst router = createRouter()\n .get('/', () => 'Hello World!')\n .get('/hello/:name', req => `Hello ${req.context.params.name}!`)\n\napp.use(router)\n```\n\n**Tip:** We can register same route more than once with different methods.\n\nRoutes are internally stored in a [Radix Tree](https://en.wikipedia.org/wiki/Radix_tree) and matched using [unjs/radix3](https://github.com/unjs/radix3).\n\n## More usage examples\n\n```js\n// Handle can directly return object or Promise<object> for JSON response\napp.use('/api', (req) => ({ url: req.url }))\n\n// We can have better matching other than quick prefix match\napp.use('/odd', () => 'Is odd!', { match: url => url.substr(1) % 2 })\n\n// Handle can directly return string for HTML response\napp.use(() => '<h1>Hello world!</h1>')\n\n// We can chain calls to .use()\napp.use('/1', () => '<h1>Hello world!</h1>')\n .use('/2', () => '<h1>Goodbye!</h1>')\n\n// Legacy middleware with 3rd argument are automatically promisified\napp.use((req, res, next) => { req.setHeader('X-Foo', 'bar'); next() })\n\n// Force promisify a legacy middleware\n// app.use(someMiddleware, { promisify: true })\n\n// Lazy loaded routes using { lazy: true }\n// app.use('/big', () => import('./big'), { lazy: true })\n```\n\n## Utilities\n\nInstead of adding helpers to `req` and `res`, h3 exposes them as composable utilities.\n\n- `useRawBody(req, encoding?)`\n- `useBody(req)`\n- `useCookies(req)`\n- `useCookie(req, name)`\n- `setCookie(res, name, value, opts?)`\n- `deleteCookie(res, name, opts?)`\n- `useQuery(req)`\n- `send(res, data, type?)`\n- `sendRedirect(res, location, code=302)`\n- `appendHeader(res, name, value)`\n- `createError({ statusCode, statusMessage, data? })`\n- `sendError(res, error, debug?)`\n- `defineHandle(handle)`\n- `defineMiddleware(middlware)`\n- `useMethod(req, default?)`\n- `isMethod(req, expected, allowHead?)`\n- `assertMethod(req, expected, allowHead?)`\n\n👉 You can learn more about usage in [JSDocs Documentation](https://www.jsdocs.io/package/h3#package-functions).\n\n## How it works?\n\nUsing `createApp`, it returns a standard `(req, res)` handler function and internally an array called middleware stack. using`use()` method we can add an item to this internal stack.\n\nWhen a request comes, each stack item that matches the route will be called and resolved until [`res.writableEnded`](https://nodejs.org/api/http.html#http_response_writableended) flag is set, which means the response is sent. If `writableEnded` is not set after all middleware, a `404` error will be thrown. And if one of the stack items resolves to a value, it will be serialized and sent as response as a shorthand method to sending responses.\n\nFor maximum compatibility with connect/express middleware (`req, res, next?` signature), h3 converts classic middleware into a promisified version ready to use with stack runner:\n\n- If middleware has 3rd next/callback param, the promise will `resolve/reject` when called\n- If middleware returns a promise, it will be **chained** to the main promise\n- If calling middleware throws an immediate error, the promise will be rejected\n- On `close` and `error` events of res, the promise will `resolve/reject` (to ensure if middleware simply calls `res.end`)\n\n## License\n\nMIT\n"
|
|
54
|
+
"release": "pnpm test && pnpm test && pnpm build && standard-version && pnpm publish && git push --follow-tags",
|
|
55
|
+
"test": "pnpm lint && vitest run --coverage"
|
|
56
|
+
}
|
|
58
57
|
}
|