h3 1.9.0 → 1.10.0

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/README.md CHANGED
@@ -9,7 +9,9 @@
9
9
 
10
10
  H3 (pronounced as /eɪtʃθriː/, like h-3) is a minimal h(ttp) framework built for high performance and portability.
11
11
 
12
- 👉 [Online Playground](https://stackblitz.com/github/unjs/h3/tree/main/playground?startScript=dev)
12
+ 👉 [Online Playground](https://stackblitz.com/github/unjs/h3/tree/main/playground)
13
+
14
+ 👉 [Online Examples Playground](https://stackblitz.com/github/unjs/h3/tree/main/examples)
13
15
 
14
16
  ## Features
15
17
 
@@ -135,7 +137,7 @@ app.use(router);
135
137
 
136
138
  Routes are internally stored in a [Radix Tree](https://en.wikipedia.org/wiki/Radix_tree) and matched using [unjs/radix3](https://github.com/unjs/radix3).
137
139
 
138
- For using nested routers, see [this example](https://stackblitz.com/edit/github-2bmusk?file=app.ts&startScript=dev)
140
+ For using nested routers, see [this example](./examples/nested-router.ts)
139
141
 
140
142
  ## More app usage examples
141
143
 
@@ -314,6 +316,14 @@ PRs are welcome to add your packages.
314
316
  - [h3-valibot](https://github.com/intevel/h3-valibot)
315
317
  - `useValidateBody(event, schema)`
316
318
  - `useValidateParams(event, schema)`
319
+ - [h3-compression](https://github.com/CodeDredd/h3-compression)
320
+ - `useGZipCompression(event, response)`
321
+ - `useDeflateCompression(event, response)`
322
+ - `useBrotliCompression(event, response)`
323
+ - `useCompression(event, response)`
324
+ - `useGZipCompressionStream(event, response)`
325
+ - `useDeflateCompressionStream(event, response)`
326
+ - `useCompressionStream(event, response)`
317
327
  - [@intlify/h3](https://github.com/intlify/h3)
318
328
  - `defineI18nMiddleware(options)`
319
329
  - `useTranslation(event)`
package/dist/index.cjs CHANGED
@@ -250,8 +250,9 @@ async function validateData(data, fn) {
250
250
  function createValidationError(validateError) {
251
251
  throw createError({
252
252
  status: 400,
253
- message: validateError.message || "Validation Failed",
254
- ...validateError
253
+ statusMessage: "Validation Error",
254
+ message: validateError?.message || "Validation Error",
255
+ data: validateError
255
256
  });
256
257
  }
257
258
 
@@ -377,7 +378,7 @@ const ParsedBodySymbol = Symbol.for("h3ParsedBody");
377
378
  const PayloadMethods$1 = ["PATCH", "POST", "PUT", "DELETE"];
378
379
  function readRawBody(event, encoding = "utf8") {
379
380
  assertMethod(event, PayloadMethods$1);
380
- const _rawBody = event._requestBody || event.web?.request?.body || event.node.req[RawBodySymbol] || event.node.req.body;
381
+ const _rawBody = event._requestBody || event.web?.request?.body || event.node.req[RawBodySymbol] || event.node.req.rawBody || event.node.req.body;
381
382
  if (_rawBody) {
382
383
  const promise2 = Promise.resolve(_rawBody).then((_resolved) => {
383
384
  if (Buffer.isBuffer(_resolved)) {
package/dist/index.d.cts CHANGED
@@ -213,7 +213,7 @@ type HTTPHeaderName = _HTTPHeaderName | Lowercase<_HTTPHeaderName> | (string & {
213
213
  * This can be used to pass additional information about the error.
214
214
  * @property {boolean} internal - Setting this property to `true` will mark the error as an internal error.
215
215
  */
216
- declare class H3Error<DataT = any> extends Error {
216
+ declare class H3Error<DataT = unknown> extends Error {
217
217
  static __h3_error__: boolean;
218
218
  statusCode: number;
219
219
  fatal: boolean;
@@ -232,10 +232,10 @@ declare class H3Error<DataT = any> extends Error {
232
232
  * @param input {string | (Partial<H3Error> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
233
233
  * @return {H3Error} - An instance of H3Error.
234
234
  */
235
- declare function createError<DataT = any>(input: string | (Partial<H3Error<DataT>> & {
235
+ declare function createError<DataT = unknown>(input: string | (Partial<H3Error<DataT>> & {
236
236
  status?: number;
237
237
  statusText?: string;
238
- })): H3Error;
238
+ })): H3Error<DataT>;
239
239
  /**
240
240
  * Receives an error and returns the corresponding response.
241
241
  * H3 internally uses this function to handle unhandled errors.
@@ -253,7 +253,7 @@ declare function sendError(event: H3Event, error: Error | H3Error, debug?: boole
253
253
  * @param input {*} - The input to check.
254
254
  * @return {boolean} - Returns true if the input is an instance of H3Error, false otherwise.
255
255
  */
256
- declare function isError(input: any): input is H3Error;
256
+ declare function isError<DataT = unknown>(input: any): input is H3Error<DataT>;
257
257
 
258
258
  interface Layer {
259
259
  route: string;
@@ -582,7 +582,7 @@ declare function defaultContentType(event: H3Event, type?: string): void;
582
582
  declare function sendRedirect(event: H3Event, location: string, code?: number): Promise<void>;
583
583
  declare function getResponseHeaders(event: H3Event): ReturnType<H3Event["res"]["getHeaders"]>;
584
584
  declare function getResponseHeader(event: H3Event, name: HTTPHeaderName): ReturnType<H3Event["res"]["getHeader"]>;
585
- declare function setResponseHeaders(event: H3Event, headers: Record<string, Parameters<OutgoingMessage["setHeader"]>[1]>): void;
585
+ declare function setResponseHeaders(event: H3Event, headers: Record<HTTPHeaderName, Parameters<OutgoingMessage["setHeader"]>[1]>): void;
586
586
  declare const setHeaders: typeof setResponseHeaders;
587
587
  declare function setResponseHeader(event: H3Event, name: HTTPHeaderName, value: Parameters<OutgoingMessage["setHeader"]>[1]): void;
588
588
  declare const setHeader: typeof setResponseHeader;
package/dist/index.d.mts CHANGED
@@ -213,7 +213,7 @@ type HTTPHeaderName = _HTTPHeaderName | Lowercase<_HTTPHeaderName> | (string & {
213
213
  * This can be used to pass additional information about the error.
214
214
  * @property {boolean} internal - Setting this property to `true` will mark the error as an internal error.
215
215
  */
216
- declare class H3Error<DataT = any> extends Error {
216
+ declare class H3Error<DataT = unknown> extends Error {
217
217
  static __h3_error__: boolean;
218
218
  statusCode: number;
219
219
  fatal: boolean;
@@ -232,10 +232,10 @@ declare class H3Error<DataT = any> extends Error {
232
232
  * @param input {string | (Partial<H3Error> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
233
233
  * @return {H3Error} - An instance of H3Error.
234
234
  */
235
- declare function createError<DataT = any>(input: string | (Partial<H3Error<DataT>> & {
235
+ declare function createError<DataT = unknown>(input: string | (Partial<H3Error<DataT>> & {
236
236
  status?: number;
237
237
  statusText?: string;
238
- })): H3Error;
238
+ })): H3Error<DataT>;
239
239
  /**
240
240
  * Receives an error and returns the corresponding response.
241
241
  * H3 internally uses this function to handle unhandled errors.
@@ -253,7 +253,7 @@ declare function sendError(event: H3Event, error: Error | H3Error, debug?: boole
253
253
  * @param input {*} - The input to check.
254
254
  * @return {boolean} - Returns true if the input is an instance of H3Error, false otherwise.
255
255
  */
256
- declare function isError(input: any): input is H3Error;
256
+ declare function isError<DataT = unknown>(input: any): input is H3Error<DataT>;
257
257
 
258
258
  interface Layer {
259
259
  route: string;
@@ -582,7 +582,7 @@ declare function defaultContentType(event: H3Event, type?: string): void;
582
582
  declare function sendRedirect(event: H3Event, location: string, code?: number): Promise<void>;
583
583
  declare function getResponseHeaders(event: H3Event): ReturnType<H3Event["res"]["getHeaders"]>;
584
584
  declare function getResponseHeader(event: H3Event, name: HTTPHeaderName): ReturnType<H3Event["res"]["getHeader"]>;
585
- declare function setResponseHeaders(event: H3Event, headers: Record<string, Parameters<OutgoingMessage["setHeader"]>[1]>): void;
585
+ declare function setResponseHeaders(event: H3Event, headers: Record<HTTPHeaderName, Parameters<OutgoingMessage["setHeader"]>[1]>): void;
586
586
  declare const setHeaders: typeof setResponseHeaders;
587
587
  declare function setResponseHeader(event: H3Event, name: HTTPHeaderName, value: Parameters<OutgoingMessage["setHeader"]>[1]): void;
588
588
  declare const setHeader: typeof setResponseHeader;
package/dist/index.d.ts CHANGED
@@ -213,7 +213,7 @@ type HTTPHeaderName = _HTTPHeaderName | Lowercase<_HTTPHeaderName> | (string & {
213
213
  * This can be used to pass additional information about the error.
214
214
  * @property {boolean} internal - Setting this property to `true` will mark the error as an internal error.
215
215
  */
216
- declare class H3Error<DataT = any> extends Error {
216
+ declare class H3Error<DataT = unknown> extends Error {
217
217
  static __h3_error__: boolean;
218
218
  statusCode: number;
219
219
  fatal: boolean;
@@ -232,10 +232,10 @@ declare class H3Error<DataT = any> extends Error {
232
232
  * @param input {string | (Partial<H3Error> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
233
233
  * @return {H3Error} - An instance of H3Error.
234
234
  */
235
- declare function createError<DataT = any>(input: string | (Partial<H3Error<DataT>> & {
235
+ declare function createError<DataT = unknown>(input: string | (Partial<H3Error<DataT>> & {
236
236
  status?: number;
237
237
  statusText?: string;
238
- })): H3Error;
238
+ })): H3Error<DataT>;
239
239
  /**
240
240
  * Receives an error and returns the corresponding response.
241
241
  * H3 internally uses this function to handle unhandled errors.
@@ -253,7 +253,7 @@ declare function sendError(event: H3Event, error: Error | H3Error, debug?: boole
253
253
  * @param input {*} - The input to check.
254
254
  * @return {boolean} - Returns true if the input is an instance of H3Error, false otherwise.
255
255
  */
256
- declare function isError(input: any): input is H3Error;
256
+ declare function isError<DataT = unknown>(input: any): input is H3Error<DataT>;
257
257
 
258
258
  interface Layer {
259
259
  route: string;
@@ -582,7 +582,7 @@ declare function defaultContentType(event: H3Event, type?: string): void;
582
582
  declare function sendRedirect(event: H3Event, location: string, code?: number): Promise<void>;
583
583
  declare function getResponseHeaders(event: H3Event): ReturnType<H3Event["res"]["getHeaders"]>;
584
584
  declare function getResponseHeader(event: H3Event, name: HTTPHeaderName): ReturnType<H3Event["res"]["getHeader"]>;
585
- declare function setResponseHeaders(event: H3Event, headers: Record<string, Parameters<OutgoingMessage["setHeader"]>[1]>): void;
585
+ declare function setResponseHeaders(event: H3Event, headers: Record<HTTPHeaderName, Parameters<OutgoingMessage["setHeader"]>[1]>): void;
586
586
  declare const setHeaders: typeof setResponseHeaders;
587
587
  declare function setResponseHeader(event: H3Event, name: HTTPHeaderName, value: Parameters<OutgoingMessage["setHeader"]>[1]): void;
588
588
  declare const setHeader: typeof setResponseHeader;
package/dist/index.mjs CHANGED
@@ -243,8 +243,9 @@ async function validateData(data, fn) {
243
243
  function createValidationError(validateError) {
244
244
  throw createError({
245
245
  status: 400,
246
- message: validateError.message || "Validation Failed",
247
- ...validateError
246
+ statusMessage: "Validation Error",
247
+ message: validateError?.message || "Validation Error",
248
+ data: validateError
248
249
  });
249
250
  }
250
251
 
@@ -370,7 +371,7 @@ const ParsedBodySymbol = Symbol.for("h3ParsedBody");
370
371
  const PayloadMethods$1 = ["PATCH", "POST", "PUT", "DELETE"];
371
372
  function readRawBody(event, encoding = "utf8") {
372
373
  assertMethod(event, PayloadMethods$1);
373
- const _rawBody = event._requestBody || event.web?.request?.body || event.node.req[RawBodySymbol] || event.node.req.body;
374
+ const _rawBody = event._requestBody || event.web?.request?.body || event.node.req[RawBodySymbol] || event.node.req.rawBody || event.node.req.body;
374
375
  if (_rawBody) {
375
376
  const promise2 = Promise.resolve(_rawBody).then((_resolved) => {
376
377
  if (Buffer.isBuffer(_resolved)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Minimal H(TTP) framework built for high performance and portability.",
5
5
  "repository": "unjs/h3",
6
6
  "license": "MIT",
@@ -27,18 +27,18 @@
27
27
  "radix3": "^1.1.0",
28
28
  "ufo": "^1.3.2",
29
29
  "uncrypto": "^0.1.3",
30
- "unenv": "^1.7.4"
30
+ "unenv": "^1.8.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "0x": "^5.7.0",
34
34
  "@types/express": "^4.17.21",
35
- "@types/node": "^20.9.2",
36
- "@types/supertest": "^2.0.16",
37
- "@vitest/coverage-v8": "^0.34.6",
38
- "autocannon": "^7.12.0",
35
+ "@types/node": "^20.10.4",
36
+ "@types/supertest": "^6.0.2",
37
+ "@vitest/coverage-v8": "^1.0.2",
38
+ "autocannon": "^7.14.0",
39
39
  "changelogen": "^0.5.5",
40
40
  "connect": "^3.7.0",
41
- "eslint": "^8.54.0",
41
+ "eslint": "^8.55.0",
42
42
  "eslint-config-unjs": "^0.2.1",
43
43
  "express": "^4.18.2",
44
44
  "get-port": "^7.0.0",
@@ -49,22 +49,21 @@
49
49
  "react": "^18.2.0",
50
50
  "react-dom": "^18.2.0",
51
51
  "supertest": "^6.3.3",
52
- "typescript": "^5.2.2",
52
+ "typescript": "^5.3.3",
53
53
  "unbuild": "^2.0.0",
54
- "vitest": "^0.34.6",
54
+ "vitest": "^1.0.2",
55
55
  "zod": "^3.22.4"
56
56
  },
57
- "packageManager": "pnpm@8.10.5",
57
+ "packageManager": "pnpm@8.11.0",
58
58
  "scripts": {
59
59
  "build": "unbuild",
60
60
  "dev": "vitest",
61
- "lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test playground",
62
- "lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test playground -w",
61
+ "lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test playground examples",
62
+ "lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test playground examples -w",
63
63
  "play": "listhen -w ./playground/app.ts",
64
64
  "profile": "0x -o -D .profile -P 'autocannon -c 100 -p 10 -d 40 http://localhost:$PORT' ./playground/server.cjs",
65
65
  "release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
66
66
  "release-rc": "pnpm test && pnpm build && changelogen --release --prerelease rc --push --publish --publishTag rc",
67
- "test": "pnpm lint && vitest --run typecheck && vitest --run --coverage",
68
- "test:types": "vitest typecheck"
67
+ "test": "pnpm lint && vitest --run --coverage"
69
68
  }
70
69
  }