;
}
/**
* Fully describes a GET request.
*/
export interface IGetApiRequestType extends IBaseApiRequestType<"get", P, KH, Q, R> {
readonly method: "get";
}
/**
* Fully describes a POST request.
*
* POST requests require to provide the "Content-Type" header.
*/
export interface IPostApiRequestType
extends IBaseApiRequestType<"post", P, KH | "Content-Type", Q, R> {
readonly method: "post";
readonly body: (params: P) => string | FormData | ReadableStream | Buffer;
}
/**
* Fully describes a PUT request.
*
* PUT requests require to provide the "Content-Type" header.
*/
export interface IPutApiRequestType extends IBaseApiRequestType<"put", P, KH | "Content-Type", Q, R> {
readonly method: "put";
readonly body: (params: P) => string | FormData | ReadableStream | Buffer;
}
/**
* Fully describes a PATCH request.
*
* PATCH requests require to provide the "Content-Type" header.
*/
export interface IPatchApiRequestType extends IBaseApiRequestType<"patch", P, KH | "Content-Type", Q, R> {
readonly method: "patch";
readonly body: (params: P) => string | FormData | ReadableStream | Buffer;
}
/**
* Fully describes a DELETE request.
*/
export interface IDeleteApiRequestType extends IBaseApiRequestType<"delete", P, KH, Q, R> {
readonly method: "delete";
}
/**
* The union of the possible ApiRequest types
*/
export type ApiRequestType
= IGetApiRequestType
| IPostApiRequestType
| IPutApiRequestType
| IPatchApiRequestType
| IDeleteApiRequestType
;
/**
* The type of the Params of an ApiRequestType
*/
export type TypeofApiParams = T extends ApiRequestType ? P : never;
/**
* The type of the Response of an ApiRequestType
*/
export type TypeofApiResponse = T extends ApiRequestType ? R : never;
/**
* A union type of the Response statuses of an ApiRequestType
*/
export type TypeOfApiResponseStatus = TypeofApiResponse extends IResponseType ? S : never;
/**
* The type of the method that runs an ApiRequestType
*/
export type TypeofApiCall = (params: TypeofApiParams) => Promise>>;
export type ApiRequestTypeForMethod = M extends "get" ? IGetApiRequestType : M extends "post" ? IPostApiRequestType
: M extends "put" ? IPutApiRequestType
: never;
export type EmptyApiRequestBuilder = ApiRequestBuilder>;
/**
* A class for building ApiRequest(s)
*/
export declare class ApiRequestBuilder> {
private readonly _request;
constructor(_request: T);
/**
* Creates a new empty request with the GET method.
*/
static ofGet(): EmptyApiRequestBuilder<"get">;
/**
* Creates a new empty request with the POST method.
*/
static ofPost(): EmptyApiRequestBuilder<"post", {}, "Content-Type">;
/**
* Creates a new empty request with the PUT method.
*/
static ofPut(): EmptyApiRequestBuilder<"put", {}, "Content-Type">;
get(): T;
/**
* Adds query parameters
*/
withQuery(query: (params: P1) => RequestQuery): ApiRequestBuilder>;
/**
* Adds headers
*/
withHeaders(headers: RequestHeaderProducer): ApiRequestBuilder>;
/**
* Adds response decoder
*/
withResponseDecoder(response_decoder: ResponseDecoder): ApiRequestBuilder>;
}
/**
* Returns an async method that implements the provided ApiRequestType backed
* by the "fetch" API.
*/
export declare function createFetchRequestForApi(requestType: ApiRequestType
, options?: {
readonly baseUrl?: string;
readonly fetchApi?: typeof fetch;
}): (params: P) => Promise>;
/**
* An header producer that sets the Content-Type to application/json
*/
export declare const ApiHeaderJson: RequestHeaderProducer<{}, "Content-Type">;
/**
* An io-ts based ResponseDecoder, it checks the response status and the
* payload against the provided type.
*
* @param status The response status handled by this decoder
* @param type The response type corresponding to the status
* @param preprocessor A function that takes the object corresponding to the json response as input
* and returns the processed object (usefull when you want alterate the json body received)
*/
export declare function ioResponseDecoder(status: S, type: t.Type, preprocessor?: (i: any) => any): ResponseDecoder>;
/**
* An arrayBuffer ResponseDecoder
* it returns an IResponse with a Buffer value
*
* @param status The response status handled by this decoder
*/
export declare const bufferArrayResponseDecoder: (status: S) => ResponseDecoder>;
/**
* A basic ResponseDecoder that returns an Error with the status text if the
* response status is S.
*/
export declare function basicErrorResponseDecoder(status: S): ResponseDecoder>;
/**
* A basic set of responses where the 200 status corresponds to a payload of
* type R and 404 and 500 to an Error
*/
export type BasicResponseType = IResponseType<200, R, H> | IResponseType<404, string, H> | IResponseType<500, string, H>;
/**
* Returns a ResponseDecoder for BasicResponseType
*/
export declare function basicResponseDecoder(type: t.Type, preprocessor?: (i: any) => any): ResponseDecoder>;
/**
* A response decoder that ignores the payload and returns a constant value
*/
export declare function constantResponseDecoder(status: S, value: T): ResponseDecoder>;
/**
* Returns a RequestHeaderProducer that produces an Authorization header of type
* "bearer token" taking the value from the "token" parameter of each request.
*/
export declare function ParamAuthorizationBearerHeaderProducer(): RequestHeaderProducer
;
/**
* Returns a RequestHeaderProducer that produces an Authorization header of type
* "bearer token" with a fixed token value.
*/
export declare function AuthorizationBearerHeaderProducer
(token: string): RequestHeaderProducer
;
type MapTypeInApiResponse = T extends IResponseType ? IResponseType : T;
/**
* Changes the response with status S to have type B
*/
export type MapResponseType = T extends IGetApiRequestType ? IGetApiRequestType> : T extends IPostApiRequestType ? IPostApiRequestType> : T extends IPutApiRequestType ? IPutApiRequestType> : T extends IDeleteApiRequestType ? IDeleteApiRequestType> : T extends IPatchApiRequestType ? IPatchApiRequestType> : never;
/**
* The parameters of the request T
*/
export type RequestParams = T extends IGetApiRequestType ? P1 : T extends IPostApiRequestType ? P2 : T extends IPutApiRequestType ? P3 : T extends IDeleteApiRequestType ? P4 : T extends IPatchApiRequestType ? P5 : never;
/**
* The IResponseType of the request T
*/
export type RequestResponseTypes = T extends IBaseApiRequestType ? R : never;
/**
* Replaces the parameters of the request T with the type P
*/
export type ReplaceRequestParams = T extends IGetApiRequestType ? IGetApiRequestType : T extends IPostApiRequestType ? IPostApiRequestType : T extends IPutApiRequestType ? IPutApiRequestType : T extends IDeleteApiRequestType ? IDeleteApiRequestType : T extends IPatchApiRequestType ? IPatchApiRequestType : never;
/**
* Adds the status S with response type A to the responses of the request
*/
export type AddResponseType = T extends IGetApiRequestType ? IGetApiRequestType> : T extends IPostApiRequestType ? IPostApiRequestType> : T extends IPutApiRequestType ? IPutApiRequestType> : T extends IDeleteApiRequestType ? IDeleteApiRequestType> : T extends IPatchApiRequestType ? IPatchApiRequestType> : never;
/**
* Removes a status from the union of IResponseType(s)
*/
export type OmitStatusFromResponse = T extends IResponseType ? never : T;
export {};