better-call 1.0.29 → 1.1.0-beta.1

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
- import { APIError, BetterCallError, CookieOptions, CookiePrefixOptions, Endpoint, EndpointBaseOptions, EndpointBodyMethodOptions, EndpointContext, EndpointOptions, HTTPMethod, HasRequiredKeys, InferBody, InferBodyInput, InferHeaders, InferHeadersInput, InferInputMethod, InferMethod, InferMiddlewareBody, InferMiddlewareQuery, InferParam, InferParamInput, InferParamPath, InferParamWildCard, InferQuery, InferQueryInput, InferRequest, InferRequestInput, InferUse, InputContext, IsEmptyObject, MergeObject, Method, Middleware, MiddlewareContext, MiddlewareInputContext, MiddlewareOptions, MiddlewareResponse, OpenAPIParameter, OpenAPISchemaType, Path, Prettify, RequiredKeysOf, Router, RouterConfig, StandardSchemaV1, Status, StrictEndpoint, UnionToIntersection, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie, statusCodes } from "./router-rGV6mTr8.cjs";
1
+ import { APIError, BetterCallError, CookieOptions, CookiePrefixOptions, Endpoint, EndpointBaseOptions, EndpointBodyMethodOptions, EndpointContext, EndpointOptions, HTTPMethod, HasRequiredKeys, InferBody, InferBodyInput, InferHeaders, InferHeadersInput, InferInputMethod, InferMethod, InferMiddlewareBody, InferMiddlewareQuery, InferParam, InferParamInput, InferParamPath, InferParamWildCard, InferQuery, InferQueryInput, InferRequest, InferRequestInput, InferUse, InputContext, IsEmptyObject, MergeObject, Method, Middleware, MiddlewareContext, MiddlewareInputContext, MiddlewareOptions, MiddlewareResponse, OpenAPIParameter, OpenAPISchemaType, Path, Prettify, RequiredKeysOf, Router, RouterConfig, StandardSchemaV1, Status, StrictEndpoint, UnionToIntersection, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie, statusCodes } from "./router-DguGh6Qa.cjs";
2
2
 
3
3
  //#region src/to-response.d.ts
4
4
  type JSONResponse = {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { APIError, BetterCallError, CookieOptions, CookiePrefixOptions, Endpoint, EndpointBaseOptions, EndpointBodyMethodOptions, EndpointContext, EndpointOptions, HTTPMethod, HasRequiredKeys, InferBody, InferBodyInput, InferHeaders, InferHeadersInput, InferInputMethod, InferMethod, InferMiddlewareBody, InferMiddlewareQuery, InferParam, InferParamInput, InferParamPath, InferParamWildCard, InferQuery, InferQueryInput, InferRequest, InferRequestInput, InferUse, InputContext, IsEmptyObject, MergeObject, Method, Middleware, MiddlewareContext, MiddlewareInputContext, MiddlewareOptions, MiddlewareResponse, OpenAPIParameter, OpenAPISchemaType, Path, Prettify, RequiredKeysOf, Router, RouterConfig, StandardSchemaV1, Status, StrictEndpoint, UnionToIntersection, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie, statusCodes } from "./router-NaFkuy-s.js";
1
+ import { APIError, BetterCallError, CookieOptions, CookiePrefixOptions, Endpoint, EndpointBaseOptions, EndpointBodyMethodOptions, EndpointContext, EndpointOptions, HTTPMethod, HasRequiredKeys, InferBody, InferBodyInput, InferHeaders, InferHeadersInput, InferInputMethod, InferMethod, InferMiddlewareBody, InferMiddlewareQuery, InferParam, InferParamInput, InferParamPath, InferParamWildCard, InferQuery, InferQueryInput, InferRequest, InferRequestInput, InferUse, InputContext, IsEmptyObject, MergeObject, Method, Middleware, MiddlewareContext, MiddlewareInputContext, MiddlewareOptions, MiddlewareResponse, OpenAPIParameter, OpenAPISchemaType, Path, Prettify, RequiredKeysOf, Router, RouterConfig, StandardSchemaV1, Status, StrictEndpoint, UnionToIntersection, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie, statusCodes } from "./router-EvGJRGFD.js";
2
2
 
3
3
  //#region src/to-response.d.ts
4
4
  type JSONResponse = {
package/dist/index.js CHANGED
@@ -446,7 +446,7 @@ const createInternalContext = async (context, { options, path }) => {
446
446
  ...context,
447
447
  body: data.body,
448
448
  query: data.query,
449
- path: context.path || path,
449
+ path: context.path || path || "virtual:",
450
450
  context: "context" in context && context.context ? context.context : {},
451
451
  returned: void 0,
452
452
  headers: context?.headers,
@@ -529,7 +529,10 @@ const createInternalContext = async (context, { options, path }) => {
529
529
 
530
530
  //#endregion
531
531
  //#region src/endpoint.ts
532
- const createEndpoint = (path, options, handler) => {
532
+ function createEndpoint(pathOrOptions, handlerOrOptions, handlerOrNever) {
533
+ const path = typeof pathOrOptions === "string" ? pathOrOptions : void 0;
534
+ const options = typeof handlerOrOptions === "object" ? handlerOrOptions : pathOrOptions;
535
+ const handler = typeof handlerOrOptions === "function" ? handlerOrOptions : handlerOrNever;
533
536
  if ((options.method === "GET" || options.method === "HEAD") && options.body) throw new BetterCallError("Body is not allowed with GET or HEAD methods");
534
537
  const internalHandler = async (...inputCtx) => {
535
538
  const context = inputCtx[0] || {};
@@ -565,7 +568,7 @@ const createEndpoint = (path, options, handler) => {
565
568
  internalHandler.options = options;
566
569
  internalHandler.path = path;
567
570
  return internalHandler;
568
- };
571
+ }
569
572
  createEndpoint.create = (opts) => {
570
573
  return (path, options, handler) => {
571
574
  return createEndpoint(path, {
@@ -2389,7 +2392,7 @@ async function generator(endpoints, config$1) {
2389
2392
  const components = { schemas: {} };
2390
2393
  Object.entries(endpoints).forEach(([_, value]) => {
2391
2394
  const options = value.options;
2392
- if (options.metadata?.SERVER_ONLY) return;
2395
+ if (!value.path || options.metadata?.SERVER_ONLY) return;
2393
2396
  if (options.method === "GET") paths[value.path] = { get: {
2394
2397
  tags: ["Default", ...options.metadata?.openapi?.tags || []],
2395
2398
  description: options.metadata?.openapi?.description,
@@ -2478,7 +2481,7 @@ const createRouter = (endpoints, config$1) => {
2478
2481
  const router = createRouter$1();
2479
2482
  const middlewareRouter = createRouter$1();
2480
2483
  for (const endpoint of Object.values(endpoints)) {
2481
- if (!endpoint.options) continue;
2484
+ if (!endpoint.options || !endpoint.path) continue;
2482
2485
  if (endpoint.options?.metadata?.SERVER_ONLY) continue;
2483
2486
  const methods = Array.isArray(endpoint.options?.method) ? endpoint.options.method : [endpoint.options?.method];
2484
2487
  for (const method of methods) addRoute(router, method, endpoint.path, endpoint);