Update API routes function pass #3

This commit is contained in:
2026-04-10 11:54:17 +01:00
parent 257adfec39
commit 5a0972beb8
5 changed files with 49 additions and 19 deletions
+15 -3
View File
@@ -91,9 +91,21 @@ export default async function ({ req }: Params): Promise<Response | undefined> {
}
if (res) {
return Response.json(_.omit(res, "bunext_api_route_res_options"), {
...(res.bunext_api_route_res_options || undefined),
});
let final_res = Response.json(
_.omit(res, [
"bunext_api_route_res_options",
"bunext_api_route_res_transform_fn",
]),
{
...(res.bunext_api_route_res_options || undefined),
},
);
if (res.bunext_api_route_res_transform_fn) {
final_res = await res.bunext_api_route_res_transform_fn(final_res);
}
return final_res;
}
return undefined;
+20 -11
View File
@@ -340,6 +340,24 @@ export type GrabTSXModuleBatchMap = {
page_file_path: string;
};
export type BunextAPIRouteJSONRes = {
bunext_api_route_res_options?: ResponseInit;
bunext_api_route_res_transform_fn?: (
res: Response,
) => Promise<Response> | Response;
} & {
[k: string]: any;
};
export type BunextAPIRouteHandlerObjectReturn<T> =
| Response
| (T &
Pick<
BunextAPIRouteJSONRes,
| "bunext_api_route_res_options"
| "bunext_api_route_res_transform_fn"
>);
export type BunextAPIRouteHandler<
T extends BunextAPIRouteJSONRes = {
[k: string]: any;
@@ -347,15 +365,6 @@ export type BunextAPIRouteHandler<
> = (
params: BunxRouteParams,
) =>
| Promise<
| Response
| (T & Pick<BunextAPIRouteJSONRes, "bunext_api_route_res_options">)
>
| Promise<BunextAPIRouteHandlerObjectReturn<T>>
| Response
| (T & Pick<BunextAPIRouteJSONRes, "bunext_api_route_res_options">);
export type BunextAPIRouteJSONRes = {
bunext_api_route_res_options?: ResponseInit;
} & {
[k: string]: any;
};
| BunextAPIRouteHandlerObjectReturn<T>;