Created
September 14, 2023 23:26
-
-
Save ethanniser/47ff4ab5dacf6d5d1846fd893a167bb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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