Skip to main content
Version: 2.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:33

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

CommandMapperType<RequestDataType, MappedData>

Properties

abortKey

Description

Defined in command/command.ts:62

Type

string

auth

Description

Defined in command/command.ts:48

Type

boolean

builder

Description

Defined in command/command.ts:76

Type

Builder<GlobalErrorType, ClientOptions>

cache

Description

Defined in command/command.ts:58

Type

boolean

cacheKey

Description

Defined in command/command.ts:63

Type

string

cacheTime

Description

Defined in command/command.ts:59

Type

number

cancelable

Description

Defined in command/command.ts:54

Type

boolean

commandDump

Description

Defined in command/command.ts:78

Type

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

commandOptions

Description

Defined in command/command.ts:77

Type

CommandConfig<EndpointType, ClientOptions>

data

Description

Defined in command/command.ts:51

Type

MappedData extends never ? RequestDataType : MappedData

deduplicate

Description

Defined in command/command.ts:67

Type

boolean

deduplicateTime

Description

Defined in command/command.ts:68

Type

number

effectKey

Description

Defined in command/command.ts:65

Type

string

endpoint

Description

Defined in command/command.ts:46

Type

EndpointType

garbageCollection

Description

Defined in command/command.ts:57

Type

number

headers

Description

Defined in command/command.ts:47

Type

HeadersInit

method

Description

Defined in command/command.ts:49

Type

HttpMethodsType

offline

Description

Defined in command/command.ts:61

Type

boolean

options

Description

Defined in command/command.ts:53

Type

ClientOptions

params

Description

Defined in command/command.ts:50

Type

ExtractRouteParams<EndpointType>

queryParams

Description

Defined in command/command.ts:52

Type

QueryParamsType

queueKey

Description

Defined in command/command.ts:64

Type

string

queued

Description

Defined in command/command.ts:60

Type

boolean

retry

Description

Defined in command/command.ts:55

Type

number

retryTime

Description

Defined in command/command.ts:56

Type

number

used

Description

Defined in command/command.ts:66

Type

boolean

Methods

dataMapper()

Description

Defined in command/command.ts:89

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:395

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:444

Return

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

abort()

Preview

abort()

Description

Defined in command/command.ts:379

Return

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

clone()

Preview

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

Description

Defined in command/command.ts:307

Parameters

NameDetails

options

Optional

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

mapper

Optional

CommandMapperType<RequestDataType, NewMappedData>

Return

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

dump()

Preview

dump()

Description

Defined in command/command.ts:256

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 never ? 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, 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:200

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:147

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:188

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:205

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:192

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:170

Parameters

NameDetails

cancelable

Required

boolean

Return

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

setData()

Preview

setData<D>(data)

Description

Defined in command/command.ts:155

Parameters

NameDetails

data

Required

D

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, D extends null ? false : true, HasParams, HasQuery, MappedData>

setDataMapper()

Preview

setDataMapper<DataMapper>(mapper)

Description

Defined in command/command.ts:236

Parameters

NameDetails

mapper

Required

DataMapper

Return

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

setDeduplicate()

Preview

setDeduplicate(deduplicate)

Description

Defined in command/command.ts:220

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:224

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:215

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:182

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:143

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:232

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:166

Parameters

NameDetails

options

Required

ClientOptions

Return

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

setParams()

Preview

setParams<P>(params)

Description

Defined in command/command.ts:151

Parameters

NameDetails

params

Required

P

Return

Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, ClientOptions, HasData, P extends null ? false : true, HasQuery, MappedData>

setQueryParams()

Preview

setQueryParams(queryParams)

Description

Defined in command/command.ts:162

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:210

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:196

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:174

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:178

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:228

Parameters

NameDetails

used

Required

boolean

Return

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