h3 2.0.0-beta.2 → 2.0.0-beta.3

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.
@@ -8,7 +8,7 @@ import { serve as serve$1 } from "srvx/bun";
8
8
  function serve(app, options) {
9
9
  freezeApp(app);
10
10
  return serve$1({
11
- fetch: app._fetch,
11
+ fetch: app.fetch,
12
12
  ...options
13
13
  });
14
14
  }
@@ -8,7 +8,7 @@ import { serve as serve$1 } from "srvx/cloudflare";
8
8
  function serve(app, options) {
9
9
  freezeApp(app);
10
10
  return serve$1({
11
- fetch: app._fetch,
11
+ fetch: app.fetch,
12
12
  ...options
13
13
  });
14
14
  }
@@ -8,7 +8,7 @@ import { serve as serve$1 } from "srvx/deno";
8
8
  function serve(app, options) {
9
9
  freezeApp(app);
10
10
  return serve$1({
11
- fetch: app._fetch,
11
+ fetch: app.fetch,
12
12
  ...options
13
13
  });
14
14
  }
@@ -8,7 +8,7 @@ import { serve as serve$1 } from "srvx/generic";
8
8
  function serve(app, options) {
9
9
  freezeApp(app);
10
10
  return serve$1({
11
- fetch: app._fetch,
11
+ fetch: app.fetch,
12
12
  ...options
13
13
  });
14
14
  }
@@ -8,7 +8,7 @@ import { serve as serve$1 } from "srvx/node";
8
8
  function serve(app, options) {
9
9
  freezeApp(app);
10
10
  return serve$1({
11
- fetch: app._fetch,
11
+ fetch: app.fetch,
12
12
  ...options
13
13
  });
14
14
  }
@@ -8,7 +8,7 @@ import { serve as serve$1 } from "srvx/service-worker";
8
8
  function serve(app, options) {
9
9
  freezeApp(app);
10
10
  return serve$1({
11
- fetch: app._fetch,
11
+ fetch: app.fetch,
12
12
  ...options
13
13
  });
14
14
  }
package/dist/h3.d.mts CHANGED
@@ -113,7 +113,7 @@ interface EventHandler<_RequestT extends EventHandlerRequest = EventHandlerReque
113
113
  (event: H3Event<_RequestT>): _ResponseT;
114
114
  meta?: H3RouteMeta;
115
115
  }
116
- type EventHandlerFetch<T extends Response | TypedResponse = Response> = (req: ServerRequest | URL | string, init?: RequestInit) => Promise<T>;
116
+ type EventHandlerFetch<T extends Response | TypedResponse = Response> = (req: ServerRequest | URL | string) => Promise<T>;
117
117
  interface EventHandlerObject<_RequestT extends EventHandlerRequest = EventHandlerRequest, _ResponseT extends EventHandlerResponse = EventHandlerResponse> {
118
118
  handler: EventHandler<_RequestT, _ResponseT>;
119
119
  middleware?: Middleware[];
@@ -339,15 +339,21 @@ declare class H3$1 {
339
339
  */
340
340
  constructor(config?: H3Config);
341
341
  /**
342
- * A [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)-like API allowing to fetch app routes.
342
+ * A [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)-compatible API allowing to fetch app routes.
343
+ *
344
+ * Input should be standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object.
345
+ *
346
+ * Returned value is a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) Promise.
347
+ */
348
+ fetch(_request: ServerRequest): Response | Promise<Response>;
349
+ /**
350
+ * A [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)-compatible API allowing to fetch app routes.
343
351
  *
344
352
  * Input can be a URL, relative path or standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object.
345
353
  *
346
354
  * Returned value is a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) Promise.
347
355
  */
348
- fetch(_request: ServerRequest | URL | string, options?: RequestInit): Promise<Response>;
349
- /** (internal fetch) */
350
- _fetch(_request: ServerRequest | URL | string, options?: RequestInit, context?: H3EventContext): Response | Promise<Response>;
356
+ request(request: ServerRequest | URL | string, options?: RequestInit, context?: H3EventContext): Response | Promise<Response>;
351
357
  /**
352
358
  * @internal
353
359
  */
package/dist/h3.mjs CHANGED
@@ -465,19 +465,17 @@ const H3Core = /* @__PURE__ */ (() => {
465
465
  this._middleware = [];
466
466
  this.config = config;
467
467
  this.fetch = this.fetch.bind(this);
468
- this._fetch = this._fetch.bind(this);
468
+ this.request = this.request.bind(this);
469
469
  this.handler = this.handler.bind(this);
470
470
  config.plugins?.forEach((plugin) => plugin(this));
471
471
  }
472
- fetch(request, options) {
473
- try {
474
- return Promise.resolve(this._fetch(request, options));
475
- } catch (error) {
476
- return Promise.reject(error);
477
- }
472
+ fetch(request) {
473
+ return this._request(request);
474
+ }
475
+ request(_req, _init, context) {
476
+ return this._request(toRequest(_req, _init), context);
478
477
  }
479
- _fetch(_req, _init, context) {
480
- const request = toRequest(_req, _init);
478
+ _request(request, context) {
481
479
  const event = new H3Event(request, context, this);
482
480
  let handlerRes;
483
481
  try {
@@ -712,8 +710,9 @@ function defineValidatedHandler(def) {
712
710
  });
713
711
  }
714
712
  function handlerWithFetch(handler) {
715
- return Object.assign(handler, { fetch: (_req, _init) => {
716
- const req = toRequest(_req, _init);
713
+ return Object.assign(handler, { fetch: (req) => {
714
+ if (typeof req === "string") req = new URL(req, "http://_");
715
+ if (req instanceof URL) req = new Request(req);
717
716
  const event = new H3Event(req);
718
717
  try {
719
718
  return Promise.resolve(toResponse(handler(event), event));
@@ -754,7 +753,7 @@ function defineLazyEventHandler(load) {
754
753
  */
755
754
  function toWebHandler(app) {
756
755
  return (request, context) => {
757
- return Promise.resolve(app._fetch(request, void 0, context));
756
+ return Promise.resolve(app.request(request, void 0, context));
758
757
  };
759
758
  }
760
759
  function fromWebHandler(handler) {
@@ -1494,7 +1493,7 @@ async function proxy(event, target, opts = {}) {
1494
1493
  };
1495
1494
  let response;
1496
1495
  try {
1497
- response = target[0] === "/" ? await event.app._fetch(createSubRequest(event, target, fetchOptions)) : await fetch(target, fetchOptions);
1496
+ response = target[0] === "/" ? await event.app.fetch(createSubRequest(event, target, fetchOptions)) : await fetch(target, fetchOptions);
1498
1497
  } catch (error) {
1499
1498
  throw new HTTPError({
1500
1499
  status: 502,
@@ -1536,7 +1535,7 @@ function getProxyRequestHeaders(event, opts) {
1536
1535
  */
1537
1536
  async function fetchWithEvent(event, url, init) {
1538
1537
  if (url[0] !== "/") return fetch(url, init);
1539
- return event.app._fetch(createSubRequest(event, url, {
1538
+ return event.app.fetch(createSubRequest(event, url, {
1540
1539
  ...init,
1541
1540
  headers: mergeHeaders(getProxyRequestHeaders(event, { host: true }), init?.headers)
1542
1541
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "Minimal H(TTP) framework built for high performance and portability.",
5
5
  "homepage": "https://h3.dev",
6
6
  "repository": "h3js/h3",