better-call 1.0.25-beta.3 → 1.0.25

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, _statusCode, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie } from "./router-DOTL_ENw.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, _statusCode, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie } from "./router-DeSuoHCx.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, _statusCode, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie } from "./router-CC_up1_c.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, _statusCode, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie } from "./router-DRUBbubk.js";
2
2
 
3
3
  //#region src/to-response.d.ts
4
4
  type JSONResponse = {
package/dist/index.js CHANGED
@@ -414,19 +414,20 @@ const serializeSignedCookie = async (key, value, secret, opt) => {
414
414
  //#region src/context.ts
415
415
  const createInternalContext = async (context, { options, path }) => {
416
416
  const headers = new Headers();
417
+ let responseStatus = void 0;
417
418
  const { data, error } = await runValidation(options, context);
418
419
  if (error) throw new APIError(400, {
419
420
  message: error.message,
420
421
  code: "VALIDATION_ERROR"
421
422
  });
422
- const requestHeaders = "headers" in context ? context.headers instanceof Headers ? context.headers : new Headers(context.headers) : "request" in context && context.request instanceof Request ? context.request.headers : null;
423
- const requestCookies = requestHeaders?.get("cookie");
423
+ const requestHeaders = "headers" in context ? context.headers instanceof Headers ? context.headers : new Headers(context.headers) : "request" in context && context.request instanceof Request ? context.request.headers : new Headers();
424
+ const requestCookies = requestHeaders.get("cookie");
424
425
  const parsedCookies = requestCookies ? parseCookies(requestCookies) : void 0;
425
426
  const internalContext = {
426
427
  ...context,
427
428
  body: data.body,
428
429
  query: data.query,
429
- path: context.path || path,
430
+ path,
430
431
  context: "context" in context && context.context ? context.context : {},
431
432
  returned: void 0,
432
433
  headers: context?.headers,
@@ -474,6 +475,9 @@ const createInternalContext = async (context, { options, path }) => {
474
475
  error: (status, body, headers$1) => {
475
476
  return new APIError(status, body, headers$1);
476
477
  },
478
+ setStatus: (status) => {
479
+ responseStatus = status;
480
+ },
477
481
  json: (json, routerResponse) => {
478
482
  if (!context.asResponse) return json;
479
483
  return {
@@ -482,7 +486,10 @@ const createInternalContext = async (context, { options, path }) => {
482
486
  _flag: "json"
483
487
  };
484
488
  },
485
- responseHeaders: headers
489
+ responseHeaders: headers,
490
+ get responseStatus() {
491
+ return responseStatus;
492
+ }
486
493
  };
487
494
  for (const middleware of options.use || []) {
488
495
  const response = await middleware({
@@ -520,9 +527,20 @@ const createEndpoint = (path, options, handler) => {
520
527
  throw e;
521
528
  });
522
529
  const headers = internalContext.responseHeaders;
523
- return context.asResponse ? toResponse(response, { headers }) : context.returnHeaders ? {
530
+ const status = internalContext.responseStatus;
531
+ return context.asResponse ? toResponse(response, {
532
+ headers,
533
+ status
534
+ }) : context.returnHeaders ? context.returnStatus ? {
535
+ headers,
536
+ response,
537
+ status
538
+ } : {
524
539
  headers,
525
540
  response
541
+ } : context.returnStatus ? {
542
+ response,
543
+ status
526
544
  } : response;
527
545
  };
528
546
  internalHandler.options = options;