better-call 1.0.7 → 1.0.9

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.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, U as HasRequiredKeys, t as InferBody, I as InferBodyInput, F as InferHeaders, G as InferHeadersInput, x as InferInputMethod, w as InferMethod, K as InferMiddlewareBody, L as InferMiddlewareQuery, y as InferParam, z as InferParamInput, Z as InferParamPath, $ as InferParamWildCard, v as InferQuery, u as InferQueryInput, B as InferRequest, D as InferRequestInput, J as InferUse, N as InputContext, W as IsEmptyObject, Y as MergeObject, r as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, V as Prettify, T as RequiredKeysOf, j as Router, R as RouterConfig, a0 as StandardSchemaV1, S as Status, X as UnionToIntersection, _ as _statusCode, c as createEndpoint, Q as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-mvPUuWw_.cjs';
1
+ export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, U as HasRequiredKeys, t as InferBody, I as InferBodyInput, F as InferHeaders, G as InferHeadersInput, x as InferInputMethod, w as InferMethod, K as InferMiddlewareBody, L as InferMiddlewareQuery, y as InferParam, z as InferParamInput, Z as InferParamPath, $ as InferParamWildCard, v as InferQuery, u as InferQueryInput, B as InferRequest, D as InferRequestInput, J as InferUse, N as InputContext, W as IsEmptyObject, Y as MergeObject, r as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, V as Prettify, T as RequiredKeysOf, j as Router, R as RouterConfig, a0 as StandardSchemaV1, S as Status, X as UnionToIntersection, _ as _statusCode, c as createEndpoint, Q as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-Bn_wF2y_.cjs';
2
2
 
3
3
  declare function toResponse(data?: any, init?: ResponseInit): Response;
4
4
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, U as HasRequiredKeys, t as InferBody, I as InferBodyInput, F as InferHeaders, G as InferHeadersInput, x as InferInputMethod, w as InferMethod, K as InferMiddlewareBody, L as InferMiddlewareQuery, y as InferParam, z as InferParamInput, Z as InferParamPath, $ as InferParamWildCard, v as InferQuery, u as InferQueryInput, B as InferRequest, D as InferRequestInput, J as InferUse, N as InputContext, W as IsEmptyObject, Y as MergeObject, r as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, V as Prettify, T as RequiredKeysOf, j as Router, R as RouterConfig, a0 as StandardSchemaV1, S as Status, X as UnionToIntersection, _ as _statusCode, c as createEndpoint, Q as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-mvPUuWw_.js';
1
+ export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, U as HasRequiredKeys, t as InferBody, I as InferBodyInput, F as InferHeaders, G as InferHeadersInput, x as InferInputMethod, w as InferMethod, K as InferMiddlewareBody, L as InferMiddlewareQuery, y as InferParam, z as InferParamInput, Z as InferParamPath, $ as InferParamWildCard, v as InferQuery, u as InferQueryInput, B as InferRequest, D as InferRequestInput, J as InferUse, N as InputContext, W as IsEmptyObject, Y as MergeObject, r as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, V as Prettify, T as RequiredKeysOf, j as Router, R as RouterConfig, a0 as StandardSchemaV1, S as Status, X as UnionToIntersection, _ as _statusCode, c as createEndpoint, Q as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-Bn_wF2y_.js';
2
2
 
3
3
  declare function toResponse(data?: any, init?: ResponseInit): Response;
4
4
 
package/dist/index.js CHANGED
@@ -170,6 +170,9 @@ function toResponse(data, init) {
170
170
  let body = data;
171
171
  let headers = new Headers(init?.headers);
172
172
  if (!data) {
173
+ if (data === null) {
174
+ body = JSON.stringify(null);
175
+ }
173
176
  headers.set("content-type", "application/json");
174
177
  } else if (typeof data === "string") {
175
178
  body = data;
@@ -565,9 +568,15 @@ var createEndpoint2 = (path, options, handler) => {
565
568
  options,
566
569
  path
567
570
  });
568
- const response = await handler(internalContext).catch((e) => {
569
- if (isAPIError(e) && context.asResponse) {
570
- return e;
571
+ const response = await handler(internalContext).catch(async (e) => {
572
+ if (isAPIError(e)) {
573
+ const onAPIError = options.onAPIError;
574
+ if (onAPIError) {
575
+ await onAPIError(e);
576
+ }
577
+ if (context.asResponse) {
578
+ return e;
579
+ }
571
580
  }
572
581
  throw e;
573
582
  });
@@ -4828,6 +4837,18 @@ var createRouter = (endpoints, config) => {
4828
4837
  if (!route?.data) {
4829
4838
  return new Response(null, { status: 404, statusText: "Not Found" });
4830
4839
  }
4840
+ const query = {};
4841
+ url.searchParams.forEach((value, key) => {
4842
+ if (key in query) {
4843
+ if (Array.isArray(query[key])) {
4844
+ query[key].push(value);
4845
+ } else {
4846
+ query[key] = [query[key], value];
4847
+ }
4848
+ } else {
4849
+ query[key] = value;
4850
+ }
4851
+ });
4831
4852
  const handler = route.data;
4832
4853
  const context = {
4833
4854
  path,
@@ -4836,7 +4857,7 @@ var createRouter = (endpoints, config) => {
4836
4857
  params: route.params ? JSON.parse(JSON.stringify(route.params)) : {},
4837
4858
  request,
4838
4859
  body: await getBody(handler.options.cloneRequest ? request.clone() : request),
4839
- query: Object.fromEntries(url.searchParams),
4860
+ query,
4840
4861
  _flag: "router",
4841
4862
  asResponse: true,
4842
4863
  context: config?.routerContext