Logos DX
    Preparing search index...

    Class HookContext<Args, Result, FailArgs>

    Context object passed as the last argument to hook callbacks. Provides methods to modify args, short-circuit, fail, or self-remove.

    // Replace args for downstream callbacks
    hooks.add('beforeRequest', (url, opts, ctx) => {
    ctx.args(url, { ...opts, cache: 'no-store' });
    });

    // Short-circuit: replace args AND stop the chain
    hooks.add('beforeRequest', (url, opts, ctx) => {
    return ctx.args(normalizedUrl, opts);
    });

    // Short-circuit with a result value
    hooks.add('beforeRequest', (url, opts, ctx) => {
    const cached = cache.get(url);
    if (cached) return ctx.returns(cached);
    });

    Type Parameters

    • Args extends unknown[] = unknown[]
    • Result = unknown
    • FailArgs extends unknown[] = [string]
    Index

    Constructors

    Properties

    scope: HookScope

    Request-scoped state bag shared across hook runs and engine instances.

    // In beforeRequest hook
    ctx.scope.set(CACHE_KEY, serializedKey);

    // In afterRequest hook (same scope)
    const key = ctx.scope.get<string>(CACHE_KEY);

    Accessors

    Methods

    • Replace args for downstream callbacks. When used with return, also stops the chain.

      Parameters

      Returns typeof EARLY_RETURN

      // Just replace args, continue chain
      ctx.args(newUrl, newOpts);

      // Replace args AND stop the chain
      return ctx.args(newUrl, newOpts);
    • Abort hook execution with an error. Uses the engine's handleFail to create the error.

      Parameters

      Returns never

      ctx.fail('Validation failed');
      
    • Remove this callback from future runs.

      Returns void

      hooks.add('init', (config, ctx) => {
      bootstrap(config);
      ctx.removeHook();
      });