h3 0.7.7 → 0.7.10

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.cjs CHANGED
@@ -183,14 +183,17 @@ class H3Error extends Error {
183
183
  constructor() {
184
184
  super(...arguments);
185
185
  this.statusCode = 500;
186
- this.statusMessage = "H3Error";
186
+ this.statusMessage = "Internal Server Error";
187
187
  }
188
188
  }
189
189
  function createError(input) {
190
+ if (typeof input === "string") {
191
+ return new H3Error(input);
192
+ }
190
193
  if (input instanceof H3Error) {
191
194
  return input;
192
195
  }
193
- const err = new H3Error(input.message ?? input.statusMessage);
196
+ const err = new H3Error(input.message ?? input.statusMessage, input.cause ? { cause: input.cause } : void 0);
194
197
  if (input.statusCode) {
195
198
  err.statusCode = input.statusCode;
196
199
  }
package/dist/index.d.ts CHANGED
@@ -2,20 +2,22 @@ import http from 'http';
2
2
  import { CookieSerializeOptions } from 'cookie-es';
3
3
  import * as ufo from 'ufo';
4
4
 
5
+ interface H3EventContext extends Record<string, any> {
6
+ }
5
7
  interface H3Event {
6
8
  '__is_event__': true;
7
9
  event: H3Event;
8
10
  req: IncomingMessage;
9
11
  res: ServerResponse;
10
- context: Record<string, any>;
12
+ context: H3EventContext;
11
13
  }
12
14
  declare type CompatibilityEvent = H3Event | IncomingMessage;
13
- declare type H3Response = any;
14
- interface EventHandler<T extends H3Response = H3Response> {
15
+ declare type H3Response<T = any> = T | Promise<T>;
16
+ interface EventHandler<T = any> {
15
17
  '__is_handler__'?: true;
16
- (event: CompatibilityEvent): T;
18
+ (event: CompatibilityEvent): H3Response<T>;
17
19
  }
18
- declare function defineEventHandler<T extends H3Response = H3Response>(handler: EventHandler<T>): EventHandler<T>;
20
+ declare function defineEventHandler<T = any>(handler: EventHandler<T>): EventHandler<T>;
19
21
  declare const eventHandler: typeof defineEventHandler;
20
22
  declare type LazyEventHandler = () => EventHandler | Promise<EventHandler>;
21
23
  declare function defineLazyEventHandler(factory: LazyEventHandler): EventHandler;
@@ -88,7 +90,7 @@ interface AppOptions {
88
90
  }
89
91
  declare function createApp(options?: AppOptions): App;
90
92
  declare function use(app: App, arg1: string | Handler | InputLayer | InputLayer[], arg2?: Handler | Partial<InputLayer> | Handler[] | Middleware | Middleware[], arg3?: Partial<InputLayer>): App;
91
- declare function createAppEventHandler(stack: Stack, options: AppOptions): EventHandler<Promise<void>>;
93
+ declare function createAppEventHandler(stack: Stack, options: AppOptions): EventHandler<void>;
92
94
 
93
95
  /**
94
96
  * H3 Runtime Error
@@ -111,7 +113,7 @@ declare class H3Error extends Error {
111
113
  * @param input {Partial<H3Error>}
112
114
  * @return {H3Error} An instance of the H3Error
113
115
  */
114
- declare function createError(input: Partial<H3Error>): H3Error;
116
+ declare function createError(input: string | Partial<H3Error>): H3Error;
115
117
  /**
116
118
  * Receive an error and return the corresponding response.<br>
117
119
  * H3 internally uses this function to handle unhandled errors.<br>
@@ -240,4 +242,4 @@ interface Router extends AddRouteShortcuts {
240
242
  }
241
243
  declare function createRouter(): Router;
242
244
 
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 };
245
+ export { AddRouteShortcuts, App, AppOptions, AppUse, CacheConditions, CompatibilityEvent, CompatibilityEventHandler, DynamicEventHandler, Encoding, EventHandler, H3Error, H3Event, H3EventContext, 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/dist/index.mjs CHANGED
@@ -175,14 +175,17 @@ class H3Error extends Error {
175
175
  constructor() {
176
176
  super(...arguments);
177
177
  this.statusCode = 500;
178
- this.statusMessage = "H3Error";
178
+ this.statusMessage = "Internal Server Error";
179
179
  }
180
180
  }
181
181
  function createError(input) {
182
+ if (typeof input === "string") {
183
+ return new H3Error(input);
184
+ }
182
185
  if (input instanceof H3Error) {
183
186
  return input;
184
187
  }
185
- const err = new H3Error(input.message ?? input.statusMessage);
188
+ const err = new H3Error(input.message ?? input.statusMessage, input.cause ? { cause: input.cause } : void 0);
186
189
  if (input.statusCode) {
187
190
  err.statusCode = input.statusCode;
188
191
  }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "0.7.7",
3
+ "version": "0.7.10",
4
4
  "description": "Tiny JavaScript Server",
5
5
  "repository": "unjs/h3",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./dist/index.d.ts",
10
11
  "import": "./dist/index.mjs",
11
12
  "require": "./dist/index.cjs"
12
13
  }
@@ -21,7 +22,7 @@
21
22
  "cookie-es": "^0.5.0",
22
23
  "destr": "^1.1.1",
23
24
  "radix3": "^0.1.2",
24
- "ufo": "^0.8.3"
25
+ "ufo": "^0.8.4"
25
26
  },
26
27
  "devDependencies": {
27
28
  "0x": "latest",
@@ -44,7 +45,7 @@
44
45
  "unbuild": "latest",
45
46
  "vitest": "latest"
46
47
  },
47
- "packageManager": "pnpm@7.0.0",
48
+ "packageManager": "pnpm@7.2.1",
48
49
  "scripts": {
49
50
  "build": "unbuild",
50
51
  "dev": "vitest",