-
Notifications
You must be signed in to change notification settings - Fork 24
/
$relay.ts
31 lines (27 loc) · 2.04 KB
/
$relay.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* eslint-disable */
import type { FastifyInstance, onRequestHookHandler, preParsingHookHandler, preValidationHookHandler, preHandlerHookHandler } from 'fastify'
import type { Schema } from 'fast-json-stringify'
import type { HttpStatusOk } from 'aspida'
import type { ServerMethods } from '../../$server'
import type { Methods } from './'
import { depend } from 'velona'
type Hooks = {
onRequest?: onRequestHookHandler | onRequestHookHandler[]
preParsing?: preParsingHookHandler | preParsingHookHandler[]
preValidation?: preValidationHookHandler | preValidationHookHandler[]
preHandler?: preHandlerHookHandler | preHandlerHookHandler[]
}
type ControllerMethods = ServerMethods<Methods>
export function defineResponseSchema<T extends { [U in keyof ControllerMethods]?: { [V in HttpStatusOk]?: Schema }}>(methods: () => T) {
return methods
}
export function defineHooks<T extends Hooks>(hooks: (fastify: FastifyInstance) => T): (fastify: FastifyInstance) => T
export function defineHooks<T extends Record<string, any>, U extends Hooks>(deps: T, cb: (d: T, fastify: FastifyInstance) => U): { (fastify: FastifyInstance): U; inject(d: Partial<T>): (fastify: FastifyInstance) => U }
export function defineHooks<T extends Record<string, any>>(hooks: (fastify: FastifyInstance) => Hooks | T, cb?: (deps: T, fastify: FastifyInstance) => Hooks) {
return cb && typeof hooks !== 'function' ? depend(hooks, cb) : hooks
}
export function defineController(methods: (fastify: FastifyInstance) => ControllerMethods): (fastify: FastifyInstance) => ControllerMethods
export function defineController<T extends Record<string, any>>(deps: T, cb: (d: T, fastify: FastifyInstance) => ControllerMethods): { (fastify: FastifyInstance): ControllerMethods; inject(d: Partial<T>): (fastify: FastifyInstance) => ControllerMethods }
export function defineController<T extends Record<string, any>>(methods: (fastify: FastifyInstance) => ControllerMethods | T, cb?: (deps: T, fastify: FastifyInstance) => ControllerMethods) {
return cb && typeof methods !== 'function' ? depend(methods, cb) : methods
}