Logos DX
    Preparing search index...

    Class FetchEngine<H, P, S, RH>

    Creates a wrapper around fetch with configurable defaults, retry logic, request deduplication, caching, and rate limiting.

    Provides resilient HTTP client for production applications that need reliable API communication with comprehensive error handling.

    // Basic setup with error handling
    const api = new FetchEngine({
    baseUrl: 'https://api.example.com',
    defaultType: 'json',
    headers: { 'Authorization': 'Bearer token' }
    });

    const [user, err] = await attempt(() => api.get('/users/123'));
    if (err) {
    console.error('Failed to fetch user:', err);
    return;
    }
    // Advanced setup with plugins
    const api = new FetchEngine({
    baseUrl: 'https://api.example.com',
    plugins: [
    retryPlugin({ maxAttempts: 3, baseDelay: 1000 }),
    cachePlugin({ ttl: 60000 }),
    dedupePlugin(true)
    ]
    });

    Type Parameters

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    config: ConfigStore<H, P, S>

    Options store for accessing all configuration.

    headers: HeadersManager<H>

    Headers manager for adding/removing/resolving headers.

    Hook engine for the request lifecycle pipeline.

    Register hooks to intercept, modify, or short-circuit requests. Plugins install their hooks here at negative priorities so user hooks at priority 0 run after built-in policies.

    name: string
    params: ParamsManager<P>

    Params manager for adding/removing/resolving URL parameters.

    state: FetchState<S>

    State store for managing instance state.

    useDefault: symbol

    Symbol to use the default value or configuration.

    When returned from determineType, uses built-in content-type detection.

    Accessors

    Methods

    • Returns facts about the the internal state of the observable instance.

      Returns {
          hasSpy: boolean;
          listenerCounts: Record<string, number>;
          listeners: (keyof EventMap<S, H, P>)[];
          rgxListeners: string[];
      }

    • Returns if the observable instance has the given event

      Parameters

      Returns boolean

    • Returns if the observable instance has a regex event

      Parameters

      Returns boolean

    • Returns if the observable instance has the given event

      Parameters

      • event: string

      Returns boolean

    • Get cache statistics.

      Returns any

    • Clear all cached responses.

      Returns void

    • Clear a specific cache entry.

      Parameters

      • key: string

      Returns void

    • Enables or disables debugging for the observable instance. Works in conjunction with your spy function. Provides a stack trace of events that are triggered, listened to, and cleaned up.

      Parameters

      • Optionalon: boolean

        Whether to enable or disable debugging

      Returns void

    • Delete a specific cache entry.

      Parameters

      • key: string

      Returns Promise<boolean>

    • Destroy the FetchEngine instance.

      Aborts all pending requests and cleans up resources. After calling destroy(), the instance cannot be used.

      Returns void

    • Invalidate cache entries matching a predicate.

      Parameters

      • predicate: (key: string) => boolean

      Returns Promise<number>

    • Invalidate cache entries by path pattern.

      Parameters

      • pattern: string | RegExp | ((key: string) => boolean)

      Returns Promise<number>

    • Check if the engine has been destroyed.

      Returns boolean

    • Observes given component as an extension of this observable instance.

      Type Parameters

      • C

      Parameters

      • component: C

        Component to wrap events around

      • Optionaloptions: ObserveOptions

        Optional configuration including signal for cleanup

      Returns Child<C, EventMap<S, H, P>>

      const obs = new ObserverEngine();

      const modal = {};

      obs.observe(modal);

      modal.on('modal-open', () => {});

      obs.trigger('modal-open'); // opens modal
      modal.trigger('modal-open'); // opens modal

      modal.cleanup(); // clears all event listeners

    post

    • Sets the spy function for the observable instance.

      Parameters

      • spy: Spy<EventMap<S, H, P>>

        The spy function to set

      • Optionalforce: boolean

        Whether to force the spy function to be set even if one is already set

      Returns void

    • Install a plugin at runtime.

      The plugin's install() method is called with this engine instance. Returns an unsubscribe function that removes the plugin's hooks.

      Parameters

      Returns () => void

      Cleanup function to uninstall the plugin

    • Copies all matching listeners from source to target without removing them from the source. Target's existing listeners are preserved.

      Useful when forking an engine so both instances react to the same events independently.

      Type Parameters

      • Shape extends Record<string, any>

      Parameters

      Returns void

      const primary = new ObserverEngine();
      const mirror = new ObserverEngine();

      primary.on('update', handler);

      ObserverEngine.copy(primary, mirror);
      // Both engines now have the 'update' listener
      // Copy everything except internal events
      ObserverEngine.copy(primary, mirror, {
      exclude: [/^__/]
      });
    • Transfers all matching listeners from source to target, removing them from the source. Target's existing listeners are preserved.

      Useful when cloning an engine (e.g. FetchEngine) and carrying over observability listeners to the new instance.

      Type Parameters

      • Shape extends Record<string, any>

      Parameters

      Returns void

      const old = new ObserverEngine();
      const next = new ObserverEngine();

      old.on('ready', handler);

      ObserverEngine.transfer(old, next);
      // `next` now owns the 'ready' listener; `old` has none
      // Transfer only specific events
      ObserverEngine.transfer(old, next, {
      filter: ['ready', /^user\./]
      });