Skip to main content
Version: 1.x.x

Command


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

Description

Fetch command it is designed to prepare the necessary setup to execute the request to the server. We can setup basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.

Usage

We should not use this class directly in the standard development flow. We can initialize it using the createCommand method on the Builder class.

Defined in command/command.ts:32

Parameters

NameDetails

builder

Required

Builder<GlobalErrorType, ClientOptions>

commandOptions

Required

CommandConfig<EndpointType, ClientOptions>

commandDump

Optional

CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType | LocalErrorType, EndpointType, ClientOptions, MappedData>

dataMapper

Optional

(data: RequestDataType) => MappedData

Properties

abortKey

Description

Defined in command/command.ts:61

Type

string

auth

Description

Defined in command/command.ts:47

Type

boolean

builder

Description

Defined in command/command.ts:75

Type

Builder<GlobalErrorType, ClientOptions>

cache

Description

Defined in command/command.ts:57

Type

boolean

cacheKey

Description

Defined in command/command.ts:62

Type

string

cacheTime

Description

Defined in command/command.ts:58

Type

number

cancelable

Description

Defined in command/command.ts:53

Type

boolean

commandDump

Description

Defined in command/command.ts:77

Type

CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType | LocalErrorType, EndpointType, ClientOptions, MappedData>

commandOptions

Description

Defined in command/command.ts:76

Type

CommandConfig<EndpointType, ClientOptions>

data

Description

Defined in command/command.ts:50

Type

MappedData extends undefined ? RequestDataType : MappedData

deduplicate

Description

Defined in command/command.ts:66

Type

boolean

deduplicateTime

Description

Defined in command/command.ts:67

Type

number

effectKey

Description

Defined in command/command.ts:64

Type

string

endpoint

Description

Defined in command/command.ts:45

Type

EndpointType

garbageCollection

Description

Defined in command/command.ts:56

Type

number

headers

Description

Defined in command/command.ts:46

Type

HeadersInit

method

Description

Defined in command/command.ts:48

Type

HttpMethodsType

offline

Description

Defined in command/command.ts:60

Type

boolean

options

Description

Defined in command/command.ts:52

Type

ClientOptions

params

Description

Defined in command/command.ts:49

Type

ExtractRouteParams<EndpointType>

queryParams

Description

Defined in command/command.ts:51

Type

QueryParamsType

queueKey

Description

Defined in command/command.ts:63

Type

string

queued

Description

Defined in command/command.ts:59

Type

boolean

retry

Description

Defined in command/command.ts:54

Type

number

retryTime

Description

Defined in command/command.ts:55

Type

number

used

Description

Defined in command/command.ts:65

Type

boolean

Methods

dataMapper()

Description

Defined in command/command.ts:88

Return

(data: RequestDataType) => MappedData

exec()

Description

Method to use the command WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.

Defined in command/command.ts:394

Return

Promise<[Data | null, Error | null, HttpStatus]>

send()

Description

Method used to perform requests with usage of cache and queues

Defined in command/command.ts:443

Return

Promise<[Data | null, Error | null, HttpStatus]>

abort()

Preview

abort()

Description

Defined in command/command.ts:378

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

clone()

Preview

clone<D, P, Q, MapperData>(options, mapper)

Description

Defined in command/command.ts:306

Parameters

NameDetails

options

Optional

CommandCurrentType<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType | LocalErrorType, EndpointType, ClientOptions, MapperData>

mapper

Optional

(data: RequestDataType) => MapperData

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, D, P, Q, MapperData>

dump()

Preview

dump()

Description

Defined in command/command.ts:255

Return

{
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
commandOptions: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean;
disableResponseInterceptors: boolean;
effectKey: string;
endpoint: GenericEndpoint;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
data: MappedData extends undefined ? RequestDataType : MappedData | \null\ | \undefined\;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean | undefined;
disableResponseInterceptors: boolean | undefined;
effectKey: string;
endpoint: string;
garbageCollection: number;
headers: HeadersInit;
method: GET | POST | PUT | PATCH | DELETE;
offline: boolean;
options: ClientOptions | T extends Command<any, any, any, any, any, any, infer O, any, any, any> ? O : never;
params: Params | \null\ | \undefined\;
queryParams: QueryParamsType | \null\ | \undefined\;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
updatedAbortKey: boolean;
updatedCacheKey: boolean;
updatedEffectKey: boolean;
updatedQueueKey: boolean;
used: boolean;
}

setAbortKey()

Preview

setAbortKey(abortKey)

Description

Defined in command/command.ts:199

Parameters

NameDetails

abortKey

Required

string

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setAuth()

Preview

setAuth(auth)

Description

Defined in command/command.ts:146

Parameters

NameDetails

auth

Required

boolean

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setCache()

Preview

setCache(cache)

Description

Defined in command/command.ts:187

Parameters

NameDetails

cache

Required

boolean

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setCacheKey()

Preview

setCacheKey(cacheKey)

Description

Defined in command/command.ts:204

Parameters

NameDetails

cacheKey

Required

string

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setCacheTime()

Preview

setCacheTime(cacheTime)

Description

Defined in command/command.ts:191

Parameters

NameDetails

cacheTime

Required

number

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setCancelable()

Preview

setCancelable(cancelable)

Description

Defined in command/command.ts:169

Parameters

NameDetails

cancelable

Required

boolean

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setData()

Preview

setData(data)

Description

Defined in command/command.ts:154

Parameters

NameDetails

data

Required

RequestDataType

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, true, HasParams, HasQuery, MappedData>

setDataMapper()

Preview

setDataMapper<DataMapper>(mapper)

Description

Defined in command/command.ts:235

Parameters

NameDetails

mapper

Required

(data: RequestDataType) => DataMapper

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, DataMapper>

setDeduplicate()

Preview

setDeduplicate(deduplicate)

Description

Defined in command/command.ts:219

Parameters

NameDetails

deduplicate

Required

boolean

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setDeduplicateTime()

Preview

setDeduplicateTime(deduplicateTime)

Description

Defined in command/command.ts:223

Parameters

NameDetails

deduplicateTime

Required

number

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setEffectKey()

Preview

setEffectKey(effectKey)

Description

Defined in command/command.ts:214

Parameters

NameDetails

effectKey

Required

string

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setGarbageCollection()

Preview

setGarbageCollection(garbageCollection)

Description

Defined in command/command.ts:181

Parameters

NameDetails

garbageCollection

Required

number

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setHeaders()

Preview

setHeaders(headers)

Description

Defined in command/command.ts:142

Parameters

NameDetails

headers

Required

HeadersInit

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setOffline()

Preview

setOffline(offline)

Description

Defined in command/command.ts:231

Parameters

NameDetails

offline

Required

boolean

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setOptions()

Preview

setOptions(options)

Description

Defined in command/command.ts:165

Parameters

NameDetails

options

Required

ClientOptions

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, true, MappedData>

setParams()

Preview

setParams(params)

Description

Defined in command/command.ts:150

Parameters

NameDetails

params

Required

ExtractRouteParams<EndpointType>

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, true, HasQuery, MappedData>

setQueryParams()

Preview

setQueryParams(queryParams)

Description

Defined in command/command.ts:161

Parameters

NameDetails

queryParams

Required

QueryParamsType

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, true, MappedData>

setQueueKey()

Preview

setQueueKey(queueKey)

Description

Defined in command/command.ts:209

Parameters

NameDetails

queueKey

Required

string

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setQueued()

Preview

setQueued(queued)

Description

Defined in command/command.ts:195

Parameters

NameDetails

queued

Required

boolean

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setRetry()

Preview

setRetry(retry)

Description

Defined in command/command.ts:173

Parameters

NameDetails

retry

Required

number

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setRetryTime()

Preview

setRetryTime(retryTime)

Description

Defined in command/command.ts:177

Parameters

NameDetails

retryTime

Required

number

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>

setUsed()

Preview

setUsed(used)

Description

Defined in command/command.ts:227

Parameters

NameDetails

used

Required

boolean

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, HasParams, HasQuery, MappedData>