Update API routes function pass #3
This commit is contained in:
parent
257adfec39
commit
5a0972beb8
9
dist/functions/server/handle-routes.js
vendored
9
dist/functions/server/handle-routes.js
vendored
@ -55,9 +55,16 @@ export default async function ({ req }) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (res) {
|
if (res) {
|
||||||
return Response.json(_.omit(res, "bunext_api_route_res_options"), {
|
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),
|
...(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;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
8
dist/types/index.d.ts
vendored
8
dist/types/index.d.ts
vendored
@ -295,11 +295,13 @@ export type GrabTSXModuleBatchMap = {
|
|||||||
tsx: string;
|
tsx: string;
|
||||||
page_file_path: string;
|
page_file_path: string;
|
||||||
};
|
};
|
||||||
export type BunextAPIRouteHandler<T extends BunextAPIRouteJSONRes = {
|
|
||||||
[k: string]: any;
|
|
||||||
}> = (params: BunxRouteParams) => Promise<Response | (T & Pick<BunextAPIRouteJSONRes, "bunext_api_route_res_options">)> | Response | (T & Pick<BunextAPIRouteJSONRes, "bunext_api_route_res_options">);
|
|
||||||
export type BunextAPIRouteJSONRes = {
|
export type BunextAPIRouteJSONRes = {
|
||||||
bunext_api_route_res_options?: ResponseInit;
|
bunext_api_route_res_options?: ResponseInit;
|
||||||
|
bunext_api_route_res_transform_fn?: (res: Response) => Promise<Response> | Response;
|
||||||
} & {
|
} & {
|
||||||
[k: string]: any;
|
[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;
|
||||||
|
}> = (params: BunxRouteParams) => Promise<BunextAPIRouteHandlerObjectReturn<T>> | Response | BunextAPIRouteHandlerObjectReturn<T>;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bunext",
|
"name": "@moduletrace/bunext",
|
||||||
"version": "1.0.68",
|
"version": "1.0.69",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -91,9 +91,21 @@ export default async function ({ req }: Params): Promise<Response | undefined> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
return Response.json(_.omit(res, "bunext_api_route_res_options"), {
|
let final_res = Response.json(
|
||||||
...(res.bunext_api_route_res_options || undefined),
|
_.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;
|
return undefined;
|
||||||
|
|||||||
@ -340,6 +340,24 @@ export type GrabTSXModuleBatchMap = {
|
|||||||
page_file_path: string;
|
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<
|
export type BunextAPIRouteHandler<
|
||||||
T extends BunextAPIRouteJSONRes = {
|
T extends BunextAPIRouteJSONRes = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
@ -347,15 +365,6 @@ export type BunextAPIRouteHandler<
|
|||||||
> = (
|
> = (
|
||||||
params: BunxRouteParams,
|
params: BunxRouteParams,
|
||||||
) =>
|
) =>
|
||||||
| Promise<
|
| Promise<BunextAPIRouteHandlerObjectReturn<T>>
|
||||||
| Response
|
|
||||||
| (T & Pick<BunextAPIRouteJSONRes, "bunext_api_route_res_options">)
|
|
||||||
>
|
|
||||||
| Response
|
| Response
|
||||||
| (T & Pick<BunextAPIRouteJSONRes, "bunext_api_route_res_options">);
|
| BunextAPIRouteHandlerObjectReturn<T>;
|
||||||
|
|
||||||
export type BunextAPIRouteJSONRes = {
|
|
||||||
bunext_api_route_res_options?: ResponseInit;
|
|
||||||
} & {
|
|
||||||
[k: string]: any;
|
|
||||||
};
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user