Skip to main content
Version: 1.x.x

Builder


import { Builder } from "@hyper-fetch/core"

Description

Builder is a class that allows you to configure the connection with the server and then use it to create commands which, when called using the appropriate method, will cause the server to be queried for the endpoint and method specified in the command.

Defined in builder/builder.ts:35

Parameters

NameDetails

options

Required

BuilderConfig

Properties

appManager

Description

Defined in builder/builder.ts:48

Type

AppManager

cache

Description

Defined in builder/builder.ts:53

Type

Cache

commandManager

Description

Defined in builder/builder.ts:47

Type

CommandManager

debug

Description

Defined in builder/builder.ts:37

Type

boolean

effects

Description

Defined in builder/builder.ts:58

Type

FetchEffectInstance[]

fetchDispatcher

Description

Defined in builder/builder.ts:54

Type

Dispatcher

logger

Description

Defined in builder/builder.ts:84

Type

LoggerType

loggerManager

Description

Defined in builder/builder.ts:49

Type

LoggerManager

options

Description

Defined in builder/builder.ts:86

Type

BuilderConfig

queryParamsConfig

Description

Defined in builder/builder.ts:65

Type

QueryStringifyOptions

submitDispatcher

Description

Defined in builder/builder.ts:55

Type

Dispatcher

url

Description

Defined in builder/builder.ts:36

Type

string

__onAuthCallbacks

Description

Defined in builder/builder.ts:43

Type

RequestInterceptorCallback[]

__onErrorCallbacks

Description

Defined in builder/builder.ts:40

Type

ResponseInterceptorCallback<any, any>[]

__onRequestCallbacks

Description

Defined in builder/builder.ts:44

Type

RequestInterceptorCallback[]

__onResponseCallbacks

Description

Defined in builder/builder.ts:42

Type

ResponseInterceptorCallback<any, any>[]

__onSuccessCallbacks

Description

Defined in builder/builder.ts:41

Type

ResponseInterceptorCallback<any, any>[]

Methods

client()

Description

Defined in builder/builder.ts:52

Return

(command: CommandInstance, requestId: string) => Promise<ClientResponseType<any, any>>

commandConfig()

Description

Defined in builder/builder.ts:62

Return

(commandOptions: CommandConfig<string, RequestConfigType>) => Partial<CommandConfig<string, RequestConfigType>>

headerMapper()

Description

Method to get default headers and to map them based on the data format exchange, by default it handles FormData / JSON formats.

Defined in builder/builder.ts:77

Return

(command: T) => HeadersInit

payloadMapper()

Description

Method to get request data and transform them to the required format. It handles FormData and JSON by default.

Defined in builder/builder.ts:81

Return

(data: unknown) => string | FormData

requestConfig()

Description

Defined in builder/builder.ts:61

Return

(command: CommandInstance) => RequestConfigType

stringifyQueryParams()

Description

Method to stringify query params from objects.

Defined in builder/builder.ts:72

Return

(queryParams: ClientQueryParamsType | string | NegativeTypes) => string

addEffect()

Preview

addEffect(effect)

Description

Add persistent effects which trigger on the request lifecycle

Defined in builder/builder.ts:222

Parameters

NameDetails

effect

Required

FetchEffectInstance | FetchEffectInstance[]

Return

this

clear()

Preview

clear()

Description

Clears the builder instance and remove all listeners on it's dependencies

Defined in builder/builder.ts:269

Return

void

createCommand()

Preview

createCommand<ResponseType, RequestDataType, LocalErrorType, QueryParamsType>()

Description

Create commands based on the builder setup

Defined in builder/builder.ts:291

Return

(params: CommandConfig<EndpointType, RequestConfigType>) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, RequestConfigType, false, false, false, undefined>

onAuth()

Preview

onAuth(callback)

Description

Method of manipulating commands before sending the request. We can for example add custom header with token to the request which command had the auth set to true.

Defined in builder/builder.ts:176

Parameters

NameDetails

callback

Required

RequestInterceptorCallback

Return

Builder<GlobalErrorType, RequestConfigType>

onError()

Preview

onError<ErrorType>(callback)

Description

Method for intercepting error responses. It can be used for example to refresh tokens.

Defined in builder/builder.ts:184

Parameters

NameDetails

callback

Required

ResponseInterceptorCallback<any, GlobalErrorType | ErrorType>

Return

Builder<GlobalErrorType, RequestConfigType>

onRequest()

Preview

onRequest(callback)

Description

Method of manipulating commands before sending the request.

Defined in builder/builder.ts:204

Parameters

NameDetails

callback

Required

RequestInterceptorCallback

Return

Builder<GlobalErrorType, RequestConfigType>

onResponse()

Preview

onResponse<ErrorType>(callback)

Description

Method for intercepting any responses.

Defined in builder/builder.ts:212

Parameters

NameDetails

callback

Required

ResponseInterceptorCallback<any, GlobalErrorType | ErrorType>

Return

Builder<GlobalErrorType, RequestConfigType>

onSuccess()

Preview

onSuccess<ErrorType>(callback)

Description

Method for intercepting success responses.

Defined in builder/builder.ts:194

Parameters

NameDetails

callback

Required

ResponseInterceptorCallback<any, GlobalErrorType | ErrorType>

Return

Builder<GlobalErrorType, RequestConfigType>

removeEffect()

Preview

removeEffect(effect)

Description

Remove effects from builder

Defined in builder/builder.ts:231

Parameters

NameDetails

effect

Required

string | FetchEffectInstance

Return

this

setClient()

Preview

setClient(callback)

Description

Set custom http client to handle graphql, rest, firebase or other

Defined in builder/builder.ts:168

Parameters

NameDetails

callback

Required

(builder: BuilderInstance) => ClientType

Return

Builder<GlobalErrorType, RequestConfigType>

setCommandConfig()

Preview

setCommandConfig(callback)

Description

This method allows to configure global defaults for the command configuration like method, auth, deduplication etc.

Defined in builder/builder.ts:101

Parameters

NameDetails

callback

Required

(command: CommandInstance) => Partial<CommandConfig<string, RequestConfigType>>

Return

Builder<GlobalErrorType, RequestConfigType>

setDebug()

Preview

setDebug(debug)

Description

This method enables the logger usage and display the logs in console

Defined in builder/builder.ts:111

Parameters

NameDetails

debug

Required

boolean

Return

Builder<GlobalErrorType, RequestConfigType>

setHeaderMapper()

Preview

setHeaderMapper(headerMapper)

Description

Set the custom header mapping function

Defined in builder/builder.ts:152

Parameters

NameDetails

headerMapper

Required

ClientHeaderMappingCallback

Return

Builder<GlobalErrorType, RequestConfigType>

setLogger()

Preview

setLogger(callback)

Description

Set the new logger instance to the builder

Defined in builder/builder.ts:127

Parameters

NameDetails

callback

Required

(builder: BuilderInstance) => LoggerManager

Return

Builder<GlobalErrorType, RequestConfigType>

setLoggerSeverity()

Preview

setLoggerSeverity(severity)

Description

Set the logger severity of the messages displayed to the console

Defined in builder/builder.ts:119

Parameters

NameDetails

severity

Required

SeverityType

Return

Builder<GlobalErrorType, RequestConfigType>

setPayloadMapper()

Preview

setPayloadMapper(payloadMapper)

Description

Set the request payload mapping function which get triggered before request get send

Defined in builder/builder.ts:160

Parameters

NameDetails

payloadMapper

Required

ClientPayloadMappingCallback

Return

Builder<GlobalErrorType, RequestConfigType>

setQueryParamsConfig()

Preview

setQueryParamsConfig(queryParamsConfig)

Description

Set config for the query params stringify method, we can set here, among others, arrayFormat, skipNull, encode, skipEmptyString and more

Defined in builder/builder.ts:135

Parameters

NameDetails

queryParamsConfig

Required

QueryStringifyOptions

Return

Builder<GlobalErrorType, RequestConfigType>

setStringifyQueryParams()

Preview

setStringifyQueryParams(stringifyFn)

Description

Set the custom query params stringify method to the builder

Defined in builder/builder.ts:144

Parameters

NameDetails

stringifyFn

Required

Custom callback handling query params stringify

StringifyCallbackType

Return

Builder<GlobalErrorType, RequestConfigType>

__modifyAuth()

Preview

__modifyAuth(command)

Description

Helper used by http client to apply the modifications on response error

Defined in builder/builder.ts:241

Parameters

NameDetails

command

Required

CommandInstance

Return

Promise<CommandInstance>

__modifyErrorResponse()

Preview

__modifyErrorResponse(response, command)

Description

Private helper to run async on-error response processing

Defined in builder/builder.ts:251

Parameters

NameDetails

response

Required

ClientResponseType<any, GlobalErrorType>

command

Required

CommandInstance

Return

Promise<ClientResponseType<any, GlobalErrorType>>

__modifyRequest()

Preview

__modifyRequest(command)

Description

Private helper to run async pre-request processing

Defined in builder/builder.ts:246

Parameters

NameDetails

command

Required

CommandInstance

Return

Promise<CommandInstance>

__modifyResponse()

Preview

__modifyResponse(response, command)

Description

Private helper to run async response processing

Defined in builder/builder.ts:263

Parameters

NameDetails

response

Required

ClientResponseType<any, GlobalErrorType>

command

Required

CommandInstance

Return

Promise<ClientResponseType<any, GlobalErrorType>>

__modifySuccessResponse()

Preview

__modifySuccessResponse(response, command)

Description

Private helper to run async on-success response processing

Defined in builder/builder.ts:257

Parameters

NameDetails

response

Required

ClientResponseType<any, GlobalErrorType>

command

Required

CommandInstance

Return

Promise<ClientResponseType<any, GlobalErrorType>>