UNPKG

@n1k1t/mock-server

Version:

Powerful util to setup mocks over HTTP APIs

48 lines 1.8 kB
import type { InternalHttpRequestContext, InternalSocketIoRequestContext } from '../transports'; import type { SetRequiredKeys, TFunction } from '../../../types'; export interface IEndpointResponse<T> { code: 'OK' | 'INTERNAL_ERROR' | 'VALIDATION_ERROR' | 'NOT_FOUND'; timestamp: number; data: T; } export interface IEndpointInput { incoming?: { query?: any; data?: any; }; outgoing?: any; } export interface IEndpointSchema<TInput extends IEndpointInput> { incoming: { data?: NonNullable<TInput['incoming']>['data']; query?: NonNullable<TInput['incoming']>['query']; }; outgoing: IEndpointResponse<TInput['outgoing']>; } export declare class Endpoint<TInput extends IEndpointInput = {}, TSchema extends IEndpointSchema<TInput> = IEndpointSchema<TInput>> { TSchema: TSchema; TCompiled: SetRequiredKeys<Endpoint<TInput, TSchema>, 'handler'>; handler?: TFunction<any, [ (InternalHttpRequestContext<TSchema['outgoing']['data']> | InternalSocketIoRequestContext<TSchema['outgoing']['data']>) & { incoming: TSchema['incoming']; } ]>; http?: { method: string; path: string; }; io?: { path: string; }; bindToHttp<This extends NonNullable<Endpoint<TInput, TSchema>['http']>>(http: This): this & { http: This; }; bindToIo<Q extends NonNullable<Endpoint<TInput, TSchema>['io']>>(io: Q): this & { io: Q; }; assignHandler<Q extends NonNullable<Endpoint<TInput, TSchema>['handler']>>(handler: Q): this & { handler: Q; }; static build<TInput extends IEndpointInput = {}, TSchema extends IEndpointSchema<TInput> = IEndpointSchema<TInput>>(): Endpoint<TInput, TSchema>; } //# sourceMappingURL=endpoint.d.ts.map