import type { Request } from 'express'; import type { BodyPlainEntity, MappedEntity } from './entities'; import type { Interceptors } from './interceptors'; import type { Data } from './values'; export type RestMethod = 'delete' | 'get' | 'options' | 'patch' | 'post' | 'put'; export type RestEntityName = 'body' | 'cookies' | 'headers' | 'params' | 'query'; export type RestEntity = EntityName extends 'body' ? BodyPlainEntity : MappedEntity; export type RestEntityNamesByMethod = { [key in RestMethod]: key extends 'delete' | 'get' | 'options' ? Exclude : RestEntityName; }; export type RestEntitiesByEntityName = { [EntityName in RestEntityNamesByMethod[Method]]?: RestEntity; }; interface RestSettings { readonly delay?: number; readonly polling?: boolean; readonly status?: number; } export type RestDataResponse = ((request: Request, entities: RestEntitiesByEntityName) => Data | Promise) | Data; export type RestFileResponse = string; export type RestRouteConfig = ({ settings: RestSettings & { polling: true; }; queue: Array<{ time?: number; data: RestDataResponse; } | { time?: number; file: RestFileResponse; }>; } | { settings?: RestSettings & { polling?: false; }; data: RestDataResponse; } | { settings?: RestSettings & { polling?: false; }; file: RestFileResponse; }) & { entities?: RestEntitiesByEntityName; interceptors?: Interceptors<'rest'>; }; export type RestPathString = `/${string}`; interface BaseRestRequestConfig { interceptors?: Interceptors<'rest'>; method: Method; path: RegExp | RestPathString; routes: RestRouteConfig[]; } type RestGetRequestConfig = BaseRestRequestConfig<'get'>; type RestPostRequestConfig = BaseRestRequestConfig<'post'>; type RestPutRequestConfig = BaseRestRequestConfig<'put'>; type RestDeleteRequestConfig = BaseRestRequestConfig<'delete'>; type RestPatchRequestConfig = BaseRestRequestConfig<'patch'>; type RestOptionsRequestConfig = BaseRestRequestConfig<'options'>; export type RestRequestConfig = RestDeleteRequestConfig | RestGetRequestConfig | RestOptionsRequestConfig | RestPatchRequestConfig | RestPostRequestConfig | RestPutRequestConfig; export {};