Skip to content

Commit

Permalink
feat: add routePath field for unified-invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Codpoe committed Oct 15, 2024
1 parent 366fc3a commit 9012a8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/servite/src/plugins/unified-invocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export default function ${apiName}(args, { routerParams = {}, ...opts } = {}) {
${apiName}.raw = (args, opts) => {
return ${apiName}(args, { ...opts, _raw: true });
};
${apiName}.routePath = '${route.routePath}';
`;
}
},
Expand Down
12 changes: 9 additions & 3 deletions packages/servite/src/runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export interface EventHandlerForUnifiedInvocation<
? FetchOptions & { routerParams: RouterParams }
: FetchOptions,
) => Promise<Response>;
/**
* The routePath of the handler.
*
* Convenient integration with request libraries such as swr and react-query
*/
routePath: string;
}

type GetRequestArgs<T extends EventHandlerRequest> =
Expand All @@ -85,11 +91,11 @@ type GetRequestArgs<T extends EventHandlerRequest> =

export function defineEventHandler<
Request extends EventHandlerRequest = EventHandlerRequest,
Response = EventHandlerResponse,
Response = any,
>(
handler:
| EventHandler<Request, Response>
| EventHandlerObject<Request, Response>,
| EventHandler<Request, EventHandlerResponse<Response>>
| EventHandlerObject<Request, EventHandlerResponse<Response>>,
) {
return _defineEventHandler(
handler,
Expand Down

0 comments on commit 9012a8e

Please sign in to comment.