type DescriptorHolder = { $MODEL_TYPE: 'descriptor'; descriptor: PropertyDescriptor; __type__: T; }; type Dictionary = { [K: string]: T; }; type Awaitable = T | Promise; type Optional = T | null | undefined; type HookCallback = (event: E) => Awaitable; type HooksDefinition = Dictionary>; type HooksRegistrar = { [K in keyof D]?: D[K][]; }; type Hookable = { $hooks: HooksRegistrar | null; }; type AdapterI = { execute(context: {}): Awaitable; isNotFound(error: unknown): Awaitable; }; /** * Extendable error class used inside Foscia. */ declare class FosciaError extends Error { /** * Construct a new FosciaError. Prefix the given message with "[foscia]". * * @param message */ constructor(message: string); } type ActionHooksDefinition = { preparing: HookCallback; running: HookCallback<{ context: C; runner: Function; }>; success: HookCallback<{ context: C; result: unknown; }>; error: HookCallback<{ context: C; error: unknown; }>; finally: HookCallback<{ context: C; }>; }; type Action = { useContext(): Promise; updateContext(newContext: NewContext): Action; use(enhancer: ContextEnhancer): Action; run(runner: ContextRunner): Promise>; } & Hookable> & ExtendedAction; type ActionParsedExtension = { [K in keyof E]: E[K] extends DescriptorHolder ? E[K] : DescriptorHolder; }; type ExtendedAction = { [K in keyof E]: E[K] extends DescriptorHolder ? T : E[K]; }; type ContextEnhancer = (action: Action) => Awaitable | void>; type ContextRunner = (action: Action) => R; /** * Configure an abort signal on the request to * [make it abortable](https://developer.chrome.com/blog/abortable-fetch/). * * @param controllerOrSignal * * @category Enhancers */ declare function abortSignal(controllerOrSignal?: Optional): (action: Action) => Promise & { signal: Optional; }, {}>>; declare namespace abortSignal { var extension: ActionParsedExtension<{ abortSignal(this: Action, controllerOrSignal?: Optional): Action; }>; } /** * The HTTP method to use in request. */ type HttpMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'; /** * The configuration object for a request which is used as an action's context * when using HttpAdapter. */ type HttpRequestConfig = { method?: HttpMethod; baseURL?: string; path?: string; params?: Dictionary | string; headers?: Dictionary; body?: unknown; bodyAs?: BodyAsTransformer; signal?: AbortSignal | null; requestTransformers?: RequestTransformer[]; responseTransformers?: ResponseTransformer[]; errorTransformers?: ErrorTransformer[]; }; /** * The configuration for the HTTP adapter implementation. */ type HttpAdapterConfig = { fetch?: typeof fetch; baseURL?: string | null; serializeParams?: HttpParamsSerializer; appendParams?: ParamsAppender | null; defaultHeaders?: Dictionary; defaultBodyAs?: BodyAsTransformer | null; requestTransformers?: RequestTransformer[]; responseTransformers?: ResponseTransformer[]; errorTransformers?: ErrorTransformer[]; }; type HttpParamsSerializer = (params: Dictionary) => string | undefined; type HttpRequestInit = { method: HttpMethod; headers: Dictionary; body: BodyInit; signal?: AbortSignal | null; }; type HttpRequest = { context: HttpRequestConfig; url: string; init: HttpRequestInit; }; type RequestTransformer = (request: HttpRequest) => Awaitable; type ResponseTransformer = (response: Response) => Awaitable; type ErrorTransformer = (error: unknown) => Awaitable; type BodyAsTransformer = (body: unknown, headers: Dictionary) => Awaitable; type ParamsAppender = (context: HttpRequestConfig) => Awaitable; /** * HTTP DELETE method shortcut for the {@link makeRequest} function. * * @param pathOrBaseURL * @param body * @param config * * @category Enhancers */ declare function makeDelete(pathOrBaseURL: string, body?: HttpRequestConfig['body'], config?: Omit): (action: Action) => Promise & ({ method?: HttpMethod | undefined; baseURL: string; path?: string | undefined; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; } | { method?: HttpMethod | undefined; baseURL?: string | undefined; path: string; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; }), {}>>; declare namespace makeDelete { var extension: ActionParsedExtension<{ makeDelete(this: Action, pathOrBaseURL: string, body?: unknown, config?: Omit | undefined): Action; }>; } /** * HTTP GET method shortcut for the {@link makeRequest} function. * * @param pathOrBaseURL * @param config * * @category Enhancers */ declare function makeGet(pathOrBaseURL: string, config?: Omit): (action: Action) => Promise & ({ method?: HttpMethod | undefined; baseURL: string; path?: string | undefined; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; } | { method?: HttpMethod | undefined; baseURL?: string | undefined; path: string; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; }), {}>>; declare namespace makeGet { var extension: ActionParsedExtension<{ makeGet(this: Action, pathOrBaseURL: string, config?: Omit | undefined): Action; }>; } /** * HTTP PATCH method shortcut for the {@link makeRequest} function. * * @param pathOrBaseURL * @param body * @param config * * @category Enhancers */ declare function makePatch(pathOrBaseURL: string, body?: HttpRequestConfig['body'], config?: Omit): (action: Action) => Promise & ({ method?: HttpMethod | undefined; baseURL: string; path?: string | undefined; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; } | { method?: HttpMethod | undefined; baseURL?: string | undefined; path: string; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; }), {}>>; declare namespace makePatch { var extension: ActionParsedExtension<{ makePatch(this: Action, pathOrBaseURL: string, body?: unknown, config?: Omit | undefined): Action; }>; } /** * HTTP POST method shortcut for the {@link makeRequest} function. * * @param pathOrBaseURL * @param body * @param config * * @category Enhancers */ declare function makePost(pathOrBaseURL: string, body?: HttpRequestConfig['body'], config?: Omit): (action: Action) => Promise & ({ method?: HttpMethod | undefined; baseURL: string; path?: string | undefined; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; } | { method?: HttpMethod | undefined; baseURL?: string | undefined; path: string; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; }), {}>>; declare namespace makePost { var extension: ActionParsedExtension<{ makePost(this: Action, pathOrBaseURL: string, body?: unknown, config?: Omit | undefined): Action; }>; } /** * HTTP PUT method shortcut for the {@link makeRequest} function. * * @param pathOrBaseURL * @param body * @param config * * @category Enhancers */ declare function makePut(pathOrBaseURL: string, body?: HttpRequestConfig['body'], config?: Omit): (action: Action) => Promise & ({ method?: HttpMethod | undefined; baseURL: string; path?: string | undefined; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; } | { method?: HttpMethod | undefined; baseURL?: string | undefined; path: string; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; }), {}>>; declare namespace makePut { var extension: ActionParsedExtension<{ makePut(this: Action, pathOrBaseURL: string, body?: unknown, config?: Omit | undefined): Action; }>; } /** * Prepare a generic HTTP request. * If given path starts with scheme (HTTPS, etc.), it will be used as the base * URL of action, otherwise it will only be used as path. * * @param pathOrBaseURL * @param config * * @category Enhancers */ declare function makeRequest(pathOrBaseURL: string, config?: HttpRequestConfig): (action: Action) => Promise & ({ method?: HttpMethod | undefined; baseURL: string; path?: string | undefined; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; } | { method?: HttpMethod | undefined; baseURL?: string | undefined; path: string; params?: string | Dictionary | undefined; headers?: Dictionary | undefined; body?: unknown; bodyAs?: BodyAsTransformer | undefined; signal?: AbortSignal | null | undefined; requestTransformers?: RequestTransformer[] | undefined; responseTransformers?: ResponseTransformer[] | undefined; errorTransformers?: ErrorTransformer[] | undefined; }), {}>>; declare namespace makeRequest { var extension: ActionParsedExtension<{ makeRequest(this: Action, pathOrBaseURL: string, config?: HttpRequestConfig | undefined): Action; }>; } /** * Set the given query param on the request. * The new params will be merged with the previous ones. * * @param key * @param value * * @category Enhancers */ declare function param(key: string | Dictionary, value?: unknown): (action: Action) => Promise & { params: { [x: string]: any; }; }, {}>>; declare namespace param { var extension: ActionParsedExtension<{ param(this: Action, key: string | Dictionary, value?: unknown): Action; }>; } declare class HttpAdapterError extends FosciaError { request: HttpRequest; constructor(message: string, request: HttpRequest); } declare class InterruptedError extends HttpAdapterError { source: unknown; constructor(message: string, request: HttpRequest, source: unknown); } declare class AbortedError extends InterruptedError { } declare abstract class ResponseError extends HttpAdapterError { response: Response; constructor(request: HttpRequest, response: Response); } declare class InvalidRequestError extends ResponseError { } declare class ConflictError extends InvalidRequestError { } declare class ForbiddenError extends InvalidRequestError { } declare class NotFoundError extends InvalidRequestError { } declare class ServerError extends ResponseError { } declare class TooManyRequestsError extends InvalidRequestError { } declare class UnauthorizedError extends InvalidRequestError { } /** * Adapter implementation for HTTP interaction using fetch. */ declare class HttpAdapter implements AdapterI { private baseURL; private fetch; private serializeParams; private appendParams; private defaultHeaders; private defaultBodyAs; private requestTransformers; private responseTransformers; private errorTransformers; constructor(config?: HttpAdapterConfig); configure(config?: HttpAdapterConfig, override?: boolean): void; /** * @inheritDoc */ execute(context: HttpRequestConfig): Promise; /** * @inheritDoc */ isNotFound(error: unknown): boolean; protected makeRequest(context: HttpRequestConfig): Promise; protected makeRequestURL(context: HttpRequestConfig): Promise; /** * Create the request init object from the given context. * May also affect the headers and body. * * @param context */ protected makeRequestInit(context: HttpRequestConfig): Promise; protected makeRequestMethod(context: HttpRequestConfig): Promise; protected makeRequestURLEndpoint(context: HttpRequestConfig): Promise; protected clearRequestURLEndpoint(endpoint: string): string; protected makeRequestURLParams(context: HttpRequestConfig): Promise; protected makeRequestURLAdditionalParams(context: HttpRequestConfig): Promise; protected makeRequestURLContextParams(context: HttpRequestConfig): Promise; protected makeRequestURLParamsFromString(params: string): string; protected makeRequestURLParamsFromObject(params: Dictionary): string | undefined; protected runRequest(request: HttpRequest): Promise; protected makeRequestError(request: HttpRequest, error: unknown): Promise; protected makeResponseError(request: HttpRequest, response: Response): Promise; protected transformRequest(context: HttpRequestConfig, request: HttpRequest): Promise; protected transformResponse(context: HttpRequestConfig, response: Response): Promise; protected transformError(context: HttpRequestConfig, error: unknown): Promise; } declare function appendIncludeParams(context: {}, params: Dictionary, key: string, transform: (include: string[]) => any): Promise>; declare function bodyAsJson(body: any): string; declare function deepParamsSerializer(params: Dictionary): string | undefined; declare function paramsSerializer(params: Dictionary): string | undefined; export { AbortedError, BodyAsTransformer, ConflictError, ErrorTransformer, ForbiddenError, HttpAdapter, HttpAdapterConfig, HttpAdapterError, HttpMethod, HttpParamsSerializer, HttpRequest, HttpRequestConfig, HttpRequestInit, InterruptedError, InvalidRequestError, NotFoundError, ParamsAppender, RequestTransformer, ResponseError, ResponseTransformer, ServerError, TooManyRequestsError, UnauthorizedError, abortSignal, appendIncludeParams, bodyAsJson, deepParamsSerializer, makeDelete, makeGet, makePatch, makePost, makePut, makeRequest, param, paramsSerializer };