Skip to content

Commit

Permalink
runtimes/js: support non-async handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre committed May 1, 2024
1 parent d99bba8 commit 112e830
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions runtimes/js/encore.dev/api/mod.ts
Expand Up @@ -30,10 +30,7 @@ export interface APIOptions {
auth?: boolean;
}

export type Handler<
Params extends object | void = void,
Response extends object | void = void
> = Params extends void
type HandlerFn<Params, Response> = Params extends void
? () => Promise<Response>
: (params: Params) => Promise<Response>;

Expand All @@ -42,8 +39,17 @@ export function api<
Response extends object | void = void
>(
options: APIOptions,
fn: Handler<Params, Response>
): Handler<Params, Response> {
fn: (params: Params) => Promise<Response>
): HandlerFn<Params, Response>;

export function api<
Params extends object | void = void,
Response extends object | void = void
>(
options: APIOptions,
fn: (params: Params) => Response
): HandlerFn<Params, Response>;
export function api(options: APIOptions, fn: any): typeof fn {
return fn;
}

Expand Down

0 comments on commit 112e830

Please sign in to comment.