Options
All
  • Public
  • Public/Protected
  • All
Menu

Module src/fetchStateMachine/utils

Index

Functions

Const createFetchStateMachine

  • createFetchStateMachine<T>(__namedParameters: { abortSignal: AbortSignal; onAbort: () => void; onFailure: (reason: Error, additionalData?: { response?: Response }) => void; onSuccess: (responseBody: T) => void }): StateMachine<FetchStates, FetchActions, FetchActionToPayload<T>>
  • description

    Returns a state machine that handles fetch with pagination.

    see

    https://stately.ai/viz/d5231be1-4cdc-441a-9327-f99f1e7df75a

    Type parameters

    • T

    Parameters

    • __namedParameters: { abortSignal: AbortSignal; onAbort: () => void; onFailure: (reason: Error, additionalData?: { response?: Response }) => void; onSuccess: (responseBody: T) => void }
      • abortSignal: AbortSignal
      • onAbort: () => void
          • (): void
          • Returns void

      • onFailure: (reason: Error, additionalData?: { response?: Response }) => void
          • (reason: Error, additionalData?: { response?: Response }): void
          • Parameters

            • reason: Error
            • Optional additionalData: { response?: Response }
              • Optional response?: Response

            Returns void

      • onSuccess: (responseBody: T) => void
          • (responseBody: T): void
          • Parameters

            • responseBody: T

            Returns void

    Returns StateMachine<FetchStates, FetchActions, FetchActionToPayload<T>>

    } The created fetch state machine.

Const fireFetchRequest

  • fireFetchRequest(__namedParameters: { abortSignal: AbortSignal; body: Record<string, unknown>; credentials: RequestCredentials; headers: Headers; method: FetchMethod; url: RequestInfo }): Promise<{ error: undefined | Error; response: Response }>
  • description

    Fires a fetch request

    Parameters

    • __namedParameters: { abortSignal: AbortSignal; body: Record<string, unknown>; credentials: RequestCredentials; headers: Headers; method: FetchMethod; url: RequestInfo }
      • abortSignal: AbortSignal
      • body: Record<string, unknown>
      • credentials: RequestCredentials
      • headers: Headers
      • method: FetchMethod
      • url: RequestInfo

    Returns Promise<{ error: undefined | Error; response: Response }>

    } - api response or any error messages

Const getFetchStateTransitions

  • description

    Retrieves the state transitions for the fetch state machine.

    Type parameters

    • T

    Parameters

    • __namedParameters: { abortSignal: AbortSignal; onAbort: () => void; onFailure: (reason: Error, additionalData?: { response?: Response }) => void; onSuccess: (responseBody: T) => void }
      • abortSignal: AbortSignal
      • onAbort: () => void
          • (): void
          • Returns void

      • onFailure: (reason: Error, additionalData?: { response?: Response }) => void
          • (reason: Error, additionalData?: { response?: Response }): void
          • Parameters

            • reason: Error
            • Optional additionalData: { response?: Response }
              • Optional response?: Response

            Returns void

      • onSuccess: (responseBody: T) => void
          • (responseBody: T): void
          • Parameters

            • responseBody: T

            Returns void

    Returns StateTransitions<FetchStates, FetchActions, FetchActionToPayload<T>, never>

    } The state transitions for the fetch state machine.

Const isValidResponse

  • isValidResponse(response?: Response): boolean
  • description

    Checks if the response is valid.

    Parameters

    • Optional response: Response

      The response object.

    Returns boolean

    • true if the response status is 200 and ok property is true, otherwise false.

Const performFetch

  • performFetch<T>(__namedParameters: { abortSignal: AbortSignal; body: Record<string, unknown>; credentials: RequestCredentials; headers: Headers; method: FetchMethod; onAbort: () => void; onReject: (reason: Error, additionalData?: { response?: Response }) => void; onResolve: (responseBody: T) => void; url: RequestInfo }): Promise<void>
  • description

    Performs a fetch action for the fetchStateMachine.

    throws

    {Error} - If there is an error fetching search results or if the backend response format is invalid.

    Type parameters

    • T

    Parameters

    • __namedParameters: { abortSignal: AbortSignal; body: Record<string, unknown>; credentials: RequestCredentials; headers: Headers; method: FetchMethod; onAbort: () => void; onReject: (reason: Error, additionalData?: { response?: Response }) => void; onResolve: (responseBody: T) => void; url: RequestInfo }
      • abortSignal: AbortSignal
      • body: Record<string, unknown>
      • credentials: RequestCredentials
      • headers: Headers
      • method: FetchMethod
      • onAbort: () => void
          • (): void
          • Returns void

      • onReject: (reason: Error, additionalData?: { response?: Response }) => void
          • (reason: Error, additionalData?: { response?: Response }): void
          • Parameters

            • reason: Error
            • Optional additionalData: { response?: Response }
              • Optional response?: Response

            Returns void

      • onResolve: (responseBody: T) => void
          • (responseBody: T): void
          • Parameters

            • responseBody: T

            Returns void

      • url: RequestInfo

    Returns Promise<void>

    • A promise that resolves when the fetch action is completed.

Generated using TypeDoc