better-call 1.0.25-beta.2 → 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.d.cts +1 -1
- package/dist/client.d.ts +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/client.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Endpoint, HasRequiredKeys, Router, UnionToIntersection } from "./router-
|
|
1
|
+
import { Endpoint, HasRequiredKeys, Router, UnionToIntersection } from "./router-DOTL_ENw.cjs";
|
|
2
2
|
import { BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
|
|
3
3
|
|
|
4
4
|
//#region src/client.d.ts
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Endpoint, HasRequiredKeys, Router, UnionToIntersection } from "./router-
|
|
1
|
+
import { Endpoint, HasRequiredKeys, Router, UnionToIntersection } from "./router-CC_up1_c.js";
|
|
2
2
|
import { BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
|
|
3
3
|
|
|
4
4
|
//#region src/client.d.ts
|
package/dist/index.cjs
CHANGED
|
@@ -117,6 +117,12 @@ var InternalAPIError = class extends Error {
|
|
|
117
117
|
} : void 0;
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
|
+
var BetterCallError = class extends Error {
|
|
121
|
+
constructor(message) {
|
|
122
|
+
super(message);
|
|
123
|
+
this.name = "BetterCallError";
|
|
124
|
+
}
|
|
125
|
+
};
|
|
120
126
|
const APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
|
|
121
127
|
|
|
122
128
|
//#endregion
|
|
@@ -498,43 +504,10 @@ const createInternalContext = async (context, { options, path }) => {
|
|
|
498
504
|
return internalContext;
|
|
499
505
|
};
|
|
500
506
|
|
|
501
|
-
//#endregion
|
|
502
|
-
//#region src/middleware.ts
|
|
503
|
-
function createMiddleware(optionsOrHandler, handler) {
|
|
504
|
-
const internalHandler = async (inputCtx) => {
|
|
505
|
-
const context = inputCtx;
|
|
506
|
-
const _handler = typeof optionsOrHandler === "function" ? optionsOrHandler : handler;
|
|
507
|
-
const internalContext = await createInternalContext(context, {
|
|
508
|
-
options: typeof optionsOrHandler === "function" ? {} : optionsOrHandler,
|
|
509
|
-
path: "/"
|
|
510
|
-
});
|
|
511
|
-
if (!_handler) throw new Error("handler must be defined");
|
|
512
|
-
const response = await _handler(internalContext);
|
|
513
|
-
const headers = internalContext.responseHeaders;
|
|
514
|
-
return context.returnHeaders ? {
|
|
515
|
-
headers,
|
|
516
|
-
response
|
|
517
|
-
} : response;
|
|
518
|
-
};
|
|
519
|
-
internalHandler.options = typeof optionsOrHandler === "function" ? {} : optionsOrHandler;
|
|
520
|
-
return internalHandler;
|
|
521
|
-
}
|
|
522
|
-
createMiddleware.create = (opts) => {
|
|
523
|
-
function fn(optionsOrHandler, handler) {
|
|
524
|
-
if (typeof optionsOrHandler === "function") return createMiddleware({ use: opts?.use }, optionsOrHandler);
|
|
525
|
-
if (!handler) throw new Error("Middleware handler is required");
|
|
526
|
-
return createMiddleware({
|
|
527
|
-
...optionsOrHandler,
|
|
528
|
-
method: "*",
|
|
529
|
-
use: [...opts?.use || [], ...optionsOrHandler.use || []]
|
|
530
|
-
}, handler);
|
|
531
|
-
}
|
|
532
|
-
return fn;
|
|
533
|
-
};
|
|
534
|
-
|
|
535
507
|
//#endregion
|
|
536
508
|
//#region src/endpoint.ts
|
|
537
509
|
const createEndpoint = (path, options, handler) => {
|
|
510
|
+
if ((options.method === "GET" || options.method === "HEAD") && options.body) throw new BetterCallError("Body is not allowed with GET or HEAD methods");
|
|
538
511
|
const internalHandler = async (...inputCtx) => {
|
|
539
512
|
const context = inputCtx[0] || {};
|
|
540
513
|
const internalContext = await createInternalContext(context, {
|
|
@@ -568,6 +541,40 @@ createEndpoint.create = (opts) => {
|
|
|
568
541
|
};
|
|
569
542
|
};
|
|
570
543
|
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region src/middleware.ts
|
|
546
|
+
function createMiddleware(optionsOrHandler, handler) {
|
|
547
|
+
const internalHandler = async (inputCtx) => {
|
|
548
|
+
const context = inputCtx;
|
|
549
|
+
const _handler = typeof optionsOrHandler === "function" ? optionsOrHandler : handler;
|
|
550
|
+
const internalContext = await createInternalContext(context, {
|
|
551
|
+
options: typeof optionsOrHandler === "function" ? {} : optionsOrHandler,
|
|
552
|
+
path: "/"
|
|
553
|
+
});
|
|
554
|
+
if (!_handler) throw new Error("handler must be defined");
|
|
555
|
+
const response = await _handler(internalContext);
|
|
556
|
+
const headers = internalContext.responseHeaders;
|
|
557
|
+
return context.returnHeaders ? {
|
|
558
|
+
headers,
|
|
559
|
+
response
|
|
560
|
+
} : response;
|
|
561
|
+
};
|
|
562
|
+
internalHandler.options = typeof optionsOrHandler === "function" ? {} : optionsOrHandler;
|
|
563
|
+
return internalHandler;
|
|
564
|
+
}
|
|
565
|
+
createMiddleware.create = (opts) => {
|
|
566
|
+
function fn(optionsOrHandler, handler) {
|
|
567
|
+
if (typeof optionsOrHandler === "function") return createMiddleware({ use: opts?.use }, optionsOrHandler);
|
|
568
|
+
if (!handler) throw new Error("Middleware handler is required");
|
|
569
|
+
return createMiddleware({
|
|
570
|
+
...optionsOrHandler,
|
|
571
|
+
method: "*",
|
|
572
|
+
use: [...opts?.use || [], ...optionsOrHandler.use || []]
|
|
573
|
+
}, handler);
|
|
574
|
+
}
|
|
575
|
+
return fn;
|
|
576
|
+
};
|
|
577
|
+
|
|
571
578
|
//#endregion
|
|
572
579
|
//#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/core.js
|
|
573
580
|
/** A special constant with type `never` */
|
|
@@ -2521,6 +2528,7 @@ const createRouter = (endpoints, config$1) => {
|
|
|
2521
2528
|
|
|
2522
2529
|
//#endregion
|
|
2523
2530
|
exports.APIError = APIError;
|
|
2531
|
+
exports.BetterCallError = BetterCallError;
|
|
2524
2532
|
exports._statusCode = _statusCode;
|
|
2525
2533
|
exports.createEndpoint = createEndpoint;
|
|
2526
2534
|
exports.createInternalContext = createInternalContext;
|