better-call 1.0.24 → 1.0.25-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.
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +42 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +42 -35
- package/dist/index.js.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/{router-BFJOSfmb.d.cts → router-CC_up1_c.d.ts} +44 -11
- package/dist/{router-D0KeMgM6.d.ts → router-DOTL_ENw.d.cts} +44 -11
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIError, CookieOptions, CookiePrefixOptions, Endpoint, 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-
|
|
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";
|
|
2
2
|
|
|
3
3
|
//#region src/to-response.d.ts
|
|
4
4
|
type JSONResponse = {
|
|
@@ -10,5 +10,5 @@ type JSONResponse = {
|
|
|
10
10
|
};
|
|
11
11
|
declare function toResponse(data?: any, init?: ResponseInit): Response;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { APIError, CookieOptions, CookiePrefixOptions, Endpoint, EndpointContext, EndpointOptions, HTTPMethod, HasRequiredKeys, InferBody, InferBodyInput, InferHeaders, InferHeadersInput, InferInputMethod, InferMethod, InferMiddlewareBody, InferMiddlewareQuery, InferParam, InferParamInput, InferParamPath, InferParamWildCard, InferQuery, InferQueryInput, InferRequest, InferRequestInput, InferUse, InputContext, IsEmptyObject, JSONResponse, 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, toResponse };
|
|
13
|
+
export { 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, JSONResponse, 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, toResponse };
|
|
14
14
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIError, CookieOptions, CookiePrefixOptions, Endpoint, 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-
|
|
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";
|
|
2
2
|
|
|
3
3
|
//#region src/to-response.d.ts
|
|
4
4
|
type JSONResponse = {
|
|
@@ -10,5 +10,5 @@ type JSONResponse = {
|
|
|
10
10
|
};
|
|
11
11
|
declare function toResponse(data?: any, init?: ResponseInit): Response;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { APIError, CookieOptions, CookiePrefixOptions, Endpoint, EndpointContext, EndpointOptions, HTTPMethod, HasRequiredKeys, InferBody, InferBodyInput, InferHeaders, InferHeadersInput, InferInputMethod, InferMethod, InferMiddlewareBody, InferMiddlewareQuery, InferParam, InferParamInput, InferParamPath, InferParamWildCard, InferQuery, InferQueryInput, InferRequest, InferRequestInput, InferUse, InputContext, IsEmptyObject, JSONResponse, 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, toResponse };
|
|
13
|
+
export { 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, JSONResponse, 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, toResponse };
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -114,6 +114,12 @@ var InternalAPIError = class extends Error {
|
|
|
114
114
|
} : void 0;
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
+
var BetterCallError = class extends Error {
|
|
118
|
+
constructor(message) {
|
|
119
|
+
super(message);
|
|
120
|
+
this.name = "BetterCallError";
|
|
121
|
+
}
|
|
122
|
+
};
|
|
117
123
|
const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
|
|
118
124
|
|
|
119
125
|
//#endregion
|
|
@@ -495,43 +501,10 @@ const createInternalContext = async (context, { options, path }) => {
|
|
|
495
501
|
return internalContext;
|
|
496
502
|
};
|
|
497
503
|
|
|
498
|
-
//#endregion
|
|
499
|
-
//#region src/middleware.ts
|
|
500
|
-
function createMiddleware(optionsOrHandler, handler) {
|
|
501
|
-
const internalHandler = async (inputCtx) => {
|
|
502
|
-
const context = inputCtx;
|
|
503
|
-
const _handler = typeof optionsOrHandler === "function" ? optionsOrHandler : handler;
|
|
504
|
-
const internalContext = await createInternalContext(context, {
|
|
505
|
-
options: typeof optionsOrHandler === "function" ? {} : optionsOrHandler,
|
|
506
|
-
path: "/"
|
|
507
|
-
});
|
|
508
|
-
if (!_handler) throw new Error("handler must be defined");
|
|
509
|
-
const response = await _handler(internalContext);
|
|
510
|
-
const headers = internalContext.responseHeaders;
|
|
511
|
-
return context.returnHeaders ? {
|
|
512
|
-
headers,
|
|
513
|
-
response
|
|
514
|
-
} : response;
|
|
515
|
-
};
|
|
516
|
-
internalHandler.options = typeof optionsOrHandler === "function" ? {} : optionsOrHandler;
|
|
517
|
-
return internalHandler;
|
|
518
|
-
}
|
|
519
|
-
createMiddleware.create = (opts) => {
|
|
520
|
-
function fn(optionsOrHandler, handler) {
|
|
521
|
-
if (typeof optionsOrHandler === "function") return createMiddleware({ use: opts?.use }, optionsOrHandler);
|
|
522
|
-
if (!handler) throw new Error("Middleware handler is required");
|
|
523
|
-
return createMiddleware({
|
|
524
|
-
...optionsOrHandler,
|
|
525
|
-
method: "*",
|
|
526
|
-
use: [...opts?.use || [], ...optionsOrHandler.use || []]
|
|
527
|
-
}, handler);
|
|
528
|
-
}
|
|
529
|
-
return fn;
|
|
530
|
-
};
|
|
531
|
-
|
|
532
504
|
//#endregion
|
|
533
505
|
//#region src/endpoint.ts
|
|
534
506
|
const createEndpoint = (path, options, handler) => {
|
|
507
|
+
if ((options.method === "GET" || options.method === "HEAD") && options.body) throw new BetterCallError("Body is not allowed with GET or HEAD methods");
|
|
535
508
|
const internalHandler = async (...inputCtx) => {
|
|
536
509
|
const context = inputCtx[0] || {};
|
|
537
510
|
const internalContext = await createInternalContext(context, {
|
|
@@ -565,6 +538,40 @@ createEndpoint.create = (opts) => {
|
|
|
565
538
|
};
|
|
566
539
|
};
|
|
567
540
|
|
|
541
|
+
//#endregion
|
|
542
|
+
//#region src/middleware.ts
|
|
543
|
+
function createMiddleware(optionsOrHandler, handler) {
|
|
544
|
+
const internalHandler = async (inputCtx) => {
|
|
545
|
+
const context = inputCtx;
|
|
546
|
+
const _handler = typeof optionsOrHandler === "function" ? optionsOrHandler : handler;
|
|
547
|
+
const internalContext = await createInternalContext(context, {
|
|
548
|
+
options: typeof optionsOrHandler === "function" ? {} : optionsOrHandler,
|
|
549
|
+
path: "/"
|
|
550
|
+
});
|
|
551
|
+
if (!_handler) throw new Error("handler must be defined");
|
|
552
|
+
const response = await _handler(internalContext);
|
|
553
|
+
const headers = internalContext.responseHeaders;
|
|
554
|
+
return context.returnHeaders ? {
|
|
555
|
+
headers,
|
|
556
|
+
response
|
|
557
|
+
} : response;
|
|
558
|
+
};
|
|
559
|
+
internalHandler.options = typeof optionsOrHandler === "function" ? {} : optionsOrHandler;
|
|
560
|
+
return internalHandler;
|
|
561
|
+
}
|
|
562
|
+
createMiddleware.create = (opts) => {
|
|
563
|
+
function fn(optionsOrHandler, handler) {
|
|
564
|
+
if (typeof optionsOrHandler === "function") return createMiddleware({ use: opts?.use }, optionsOrHandler);
|
|
565
|
+
if (!handler) throw new Error("Middleware handler is required");
|
|
566
|
+
return createMiddleware({
|
|
567
|
+
...optionsOrHandler,
|
|
568
|
+
method: "*",
|
|
569
|
+
use: [...opts?.use || [], ...optionsOrHandler.use || []]
|
|
570
|
+
}, handler);
|
|
571
|
+
}
|
|
572
|
+
return fn;
|
|
573
|
+
};
|
|
574
|
+
|
|
568
575
|
//#endregion
|
|
569
576
|
//#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/core.js
|
|
570
577
|
/** A special constant with type `never` */
|
|
@@ -2517,5 +2524,5 @@ const createRouter = (endpoints, config$1) => {
|
|
|
2517
2524
|
};
|
|
2518
2525
|
|
|
2519
2526
|
//#endregion
|
|
2520
|
-
export { APIError, _statusCode, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie, toResponse };
|
|
2527
|
+
export { APIError, BetterCallError, _statusCode, createEndpoint, createInternalContext, createMiddleware, createRouter, generator, getCookieKey, getHTML, hideInternalStackFrames, makeErrorForHideStackFrame, parseCookies, serializeCookie, serializeSignedCookie, toResponse };
|
|
2521
2528
|
//# sourceMappingURL=index.js.map
|