Skip to content

Packages  ›  trotsky  ›  StepTap

StepTap class ​

Represents a step that allows interception of the current Step instance for custom processing or side effects.

Signature:

typescript
export declare class StepTap<P = StepBuilder, C = unknown, O = null> extends Step<P, C, O>

Extends: Step<P, C, O>

Remarks ​

The StepTap class enables the execution of a provided interceptor function, which receives the current step as its argument. This is useful for debugging, logging, or performing side effects without altering the main flow.

Example 1 ​

Log actor information:

ts
await Trotsky.init(agent)
  .actor("bsky.app")
  .tap((step) => {
    console.log(`Handle: ${step.context.handle}`)
    console.log(`Followers: ${step.context.followersCount}`)
  })
  .run()

Example 2 ​

Debug post processing:

ts
await Trotsky.init(agent)
  .searchPosts({ q: "typescript" })
  .take(10)
  .each()
  .tap((step) => {
    console.log(`Processing post: ${step.context.uri}`)
    console.log(`Likes: ${step.context.likeCount}`)
  })
  .like()
  .run()

Constructors ​

Constructor

Modifiers

Description

(constructor)(agent, parent, interceptor)

Creates an instance of StepTap.

Properties ​

Property

Modifiers

Type

Description

_interceptor

protected

StepTapInterceptor

The interceptor function to be executed during the apply phase. It receives the current Step instance and can perform custom operations.

Methods ​

Method

Modifiers

Description

apply()

Executes the interceptor function with the current step as its argument.

clone(rest)

Clones the current step and returns a new instance with the same parameters.