Skip to content

Instantly share code, notes, and snippets.

@ethanniser
Created September 14, 2023 23:26
Show Gist options
  • Save ethanniser/47ff4ab5dacf6d5d1846fd893a167bb8 to your computer and use it in GitHub Desktop.
Save ethanniser/47ff4ab5dacf6d5d1846fd893a167bb8 to your computer and use it in GitHub Desktop.
import type {
DecoratorBase,
DefinitionBase,
Handler,
InputSchema,
LocalHook,
MergeSchema,
RouteBase,
RouteSchema,
UnwrapRoute,
} from "elysia/types";
import { type Elysia } from "elysia";
type RouteArgs<
BasePath extends string,
Decorators extends DecoratorBase,
Definitions extends DefinitionBase,
ParentSchema extends RouteSchema,
Routes extends RouteBase,
Path extends string,
LocalSchema extends InputSchema<keyof Definitions["type"] & string>,
Route extends MergeSchema<
UnwrapRoute<LocalSchema, Definitions["type"]>,
ParentSchema
>,
Function extends Handler<Route, Decorators, `${BasePath}${Path}`>
> = {
handler: Function;
hooks?: LocalHook<
LocalSchema,
Route,
Decorators,
Definitions["error"],
`${BasePath}${Path}`
>;
};
export function elysiaHandler<
BasePath extends string,
Decorators extends DecoratorBase,
Definitions extends DefinitionBase,
ParentSchema extends RouteSchema,
Routes extends RouteBase,
Path extends string,
LocalSchema extends InputSchema<keyof Definitions["type"] & string>,
Route extends MergeSchema<
UnwrapRoute<LocalSchema, Definitions["type"]>,
ParentSchema
>,
Function extends Handler<Route, Decorators, `${BasePath}${Path}`>
>(
elysiaInstance: Elysia<
BasePath,
Decorators,
Definitions,
ParentSchema,
Routes
>,
path: Path,
obj: RouteArgs<
BasePath,
Decorators,
Definitions,
ParentSchema,
Routes,
Path,
LocalSchema,
Route,
Function
>
) {
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment