Skip to content

Commit f98f689

Browse files
committed
doc: add examples
1 parent 6ac80ea commit f98f689

27 files changed

Lines changed: 703 additions & 19 deletions

lib/core/StepActor.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,32 @@ export type StepActorOutput = AppBskyActorGetProfile.OutputSchema
2121

2222
/**
2323
* Represents a step for retrieving and handling an actor's profile using the Bluesky API.
24+
*
2425
* @typeParam P - Type of the parent object.
2526
* @typeParam C - Type of the context object.
2627
* @typeParam O - Type of the output object, extending {@link StepActorOutput}.
28+
*
29+
* @example
30+
* Get an actor's profile:
31+
* ```ts
32+
* await Trotsky.init(agent)
33+
* .actor("bsky.app")
34+
* .tap((step) => {
35+
* console.log(step.context.displayName)
36+
* console.log(step.context.followersCount)
37+
* })
38+
* .run()
39+
* ```
40+
*
41+
* @example
42+
* Follow an actor:
43+
* ```ts
44+
* await Trotsky.init(agent)
45+
* .actor("alice.bsky.social")
46+
* .follow()
47+
* .run()
48+
* ```
49+
*
2750
* @public
2851
*/
2952
export class StepActor<P = StepBuilder, C = null, O extends StepActorOutput = StepActorOutput> extends ActorMixins<P, C, O> {

lib/core/StepActorBlock.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,33 @@ import { Step, type StepActor, type StepActorOutput } from "../trotsky"
22

33
/**
44
* Represents a step that performs an actor block operation using the Bluesky API.
5+
*
56
* @typeParam P - Type of the parent step, extending {@link StepActor}.
67
* @typeParam C - Type of the context object, extending {@link StepActorOutput}.
78
* @typeParam O - Type of the output object.
9+
*
10+
* @example
11+
* Block a specific actor:
12+
* ```ts
13+
* await Trotsky.init(agent)
14+
* .actor("spammer.bsky.social")
15+
* .block()
16+
* .run()
17+
* ```
18+
*
19+
* @example
20+
* Block actors posting spam content:
21+
* ```ts
22+
* await Trotsky.init(agent)
23+
* .searchPosts({ q: "spam content" })
24+
* .take(10)
25+
* .each()
26+
* .author()
27+
* .block()
28+
* .wait(1000)
29+
* .run()
30+
* ```
31+
*
832
* @public
933
*/
1034
export class StepActorBlock<P = StepActor, C extends StepActorOutput = StepActorOutput, O = null> extends Step<P, C, O> {

lib/core/StepActorFollow.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,33 @@ import { Step, type StepActor, type StepActorOutput } from "../trotsky"
22

33
/**
44
* Represents a step that performs an actor follow operation using the agent.
5+
*
56
* @typeParam P - Type of the parent step, extending {@link StepActor}.
67
* @typeParam C - Type of the context object, extending {@link StepActorOutput}.
78
* @typeParam O - Type of the output object.
9+
*
10+
* @example
11+
* Follow a specific actor:
12+
* ```ts
13+
* await Trotsky.init(agent)
14+
* .actor("alice.bsky.social")
15+
* .follow()
16+
* .run()
17+
* ```
18+
*
19+
* @example
20+
* Follow back all your followers:
21+
* ```ts
22+
* await Trotsky.init(agent)
23+
* .actor("myhandle.bsky.social")
24+
* .followers()
25+
* .each()
26+
* .when((step) => !step?.context?.viewer?.following)
27+
* .follow()
28+
* .wait(2000)
29+
* .run()
30+
* ```
31+
*
832
* @public
933
*/
1034
export class StepActorFollow<P = StepActor, C extends StepActorOutput = StepActorOutput, O = null> extends Step<P, C, O> {

lib/core/StepActorFollowers.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,37 @@ export type StepActorFollowersQueryParamsCursor = StepActorFollowersQueryParams[
2727
/**
2828
* Represents a step for retrieving an actor's followers using the Bluesky API.
2929
* Supports paginated retrieval of followers.
30+
*
3031
* @typeParam P - Type of the parent step, extending {@link StepActor}.
3132
* @typeParam C - Type of the context object, extending {@link StepActorOutput}.
3233
* @typeParam O - Type of the output object, extending {@link StepActorFollowersOutput}.
34+
*
35+
* @example
36+
* Get and iterate through an actor's followers:
37+
* ```ts
38+
* await Trotsky.init(agent)
39+
* .actor("bsky.app")
40+
* .followers()
41+
* .each()
42+
* .tap((step) => {
43+
* console.log(`Follower: ${step.context.handle}`)
44+
* })
45+
* .run()
46+
* ```
47+
*
48+
* @example
49+
* Follow back all your followers:
50+
* ```ts
51+
* await Trotsky.init(agent)
52+
* .actor("myhandle.bsky.social")
53+
* .followers()
54+
* .each()
55+
* .when((step) => !step?.context?.viewer?.following)
56+
* .follow()
57+
* .wait(2000)
58+
* .run()
59+
* ```
60+
*
3361
* @public
3462
*/
3563
export class StepActorFollowers<P = StepActor, C extends StepActorOutput = StepActorOutput, O extends StepActorFollowersOutput = StepActorFollowersOutput> extends StepActors<P, C, O> {

lib/core/StepActorFollowings.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,38 @@ export type StepActorFollowingsQueryParamsCursor = StepActorFollowingsQueryParam
2727
/**
2828
* Represents a step for retrieving an actor's followings using the Bluesky API.
2929
* Supports paginated retrieval of followings.
30+
*
3031
* @typeParam P - Type of the parent step, extending {@link StepActor}.
3132
* @typeParam C - Type of the context object, extending {@link StepActorOutput}.
3233
* @typeParam O - Type of the output object, extending {@link StepActorFollowingsOutput}.
34+
*
35+
* @example
36+
* Get and iterate through an actor's followings:
37+
* ```ts
38+
* await Trotsky.init(agent)
39+
* .actor("bsky.app")
40+
* .followings()
41+
* .each()
42+
* .tap((step) => {
43+
* console.log(`Following: ${step.context.handle}`)
44+
* })
45+
* .run()
46+
* ```
47+
*
48+
* @example
49+
* Check which accounts follow you back:
50+
* ```ts
51+
* await Trotsky.init(agent)
52+
* .actor("myhandle.bsky.social")
53+
* .followings()
54+
* .each()
55+
* .tap((step) => {
56+
* const mutual = step.context.viewer?.followedBy
57+
* console.log(`${step.context.handle}: ${mutual ? '✅' : '❌'}`)
58+
* })
59+
* .run()
60+
* ```
61+
*
3362
* @public
3463
*/
3564
export class StepActorFollowings<P = StepActor, C extends StepActorOutput = StepActorOutput, O extends StepActorFollowingsOutput = StepActorFollowingsOutput> extends StepActors<P, C, O> {

lib/core/StepActorLikes.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,38 @@ export type StepActorLikesQueryParamsCursor = StepActorLikesQueryParams["cursor"
2828
/**
2929
* Represents a step for retrieving an actor's likes using the Bluesky API.
3030
* Supports paginated retrieval of likes.
31+
*
3132
* @typeParam P - Type of the parent step, extending {@link StepActor}.
3233
* @typeParam C - Type of the context object, extending {@link StepActorOutput}.
3334
* @typeParam O - Type of the output object, extending {@link StepActorLikesOutput}.
35+
*
36+
* @example
37+
* Get and display an actor's liked posts:
38+
* ```ts
39+
* await Trotsky.init(agent)
40+
* .actor("alice.bsky.social")
41+
* .likes()
42+
* .take(20)
43+
* .each()
44+
* .tap((step) => {
45+
* console.log(`Liked: ${step.context.record.text}`)
46+
* })
47+
* .run()
48+
* ```
49+
*
50+
* @example
51+
* Like what your favorite users like:
52+
* ```ts
53+
* await Trotsky.init(agent)
54+
* .actor("alice.bsky.social")
55+
* .likes()
56+
* .take(10)
57+
* .each()
58+
* .like()
59+
* .wait(2000)
60+
* .run()
61+
* ```
62+
*
3463
* @public
3564
*/
3665
export class StepActorLikes<P = StepActor, C extends StepActorOutput = StepActorOutput, O extends StepActorLikesOutput = StepActorLikesOutput> extends StepPosts<P, C, O> {

lib/core/StepActorLists.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,40 @@ export type StepActorListsQueryParamsCursor = StepActorListsQueryParams["cursor"
2525

2626
/**
2727
* Represents step for retrieving the lists associated with a specific actor, extending the {@link StepLists} functionality.
28-
*
28+
*
2929
* @typeParam P - The parent step type, defaulting to {@link StepActor}.
3030
* @typeParam C - The context type, defaulting to {@link StepActorOutput}.
3131
* @typeParam O - The output type, defaulting to {@link StepActorListsOutput}.
32-
*
32+
*
33+
* @example
34+
* Get all lists created by an actor:
35+
* ```ts
36+
* await Trotsky.init(agent)
37+
* .actor("alice.bsky.social")
38+
* .lists()
39+
* .each()
40+
* .tap((step) => {
41+
* console.log(`List: ${step.context.name}`)
42+
* console.log(`Purpose: ${step.context.purpose}`)
43+
* })
44+
* .run()
45+
* ```
46+
*
47+
* @example
48+
* Get members of all lists from an actor:
49+
* ```ts
50+
* await Trotsky.init(agent)
51+
* .actor("alice.bsky.social")
52+
* .lists()
53+
* .each()
54+
* .members()
55+
* .each()
56+
* .tap((step) => {
57+
* console.log(step.context.handle)
58+
* })
59+
* .run()
60+
* ```
61+
*
3362
* @public
3463
*/
3564
export class StepActorLists<P = StepActor, C extends StepActorOutput = StepActorOutput, O extends StepListsOutput = StepActorListsOutput> extends StepLists<P, C, O> {

lib/core/StepActorMute.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,33 @@ import { Step, type StepActor, type StepActorOutput } from "../trotsky"
22

33
/**
44
* Represents a step that performs an actor mute operation using the Bluesky API.
5+
*
56
* @typeParam P - Type of the parent step, extending {@link StepActor}.
67
* @typeParam C - Type of the context object, extending {@link StepActorOutput}.
78
* @typeParam O - Type of the output object.
9+
*
10+
* @example
11+
* Mute a specific actor:
12+
* ```ts
13+
* await Trotsky.init(agent)
14+
* .actor("spammer.bsky.social")
15+
* .mute()
16+
* .run()
17+
* ```
18+
*
19+
* @example
20+
* Mute actors with specific criteria:
21+
* ```ts
22+
* await Trotsky.init(agent)
23+
* .searchPosts({ q: "spam keyword" })
24+
* .take(10)
25+
* .each()
26+
* .author()
27+
* .mute()
28+
* .wait(1000)
29+
* .run()
30+
* ```
31+
*
832
* @public
933
*/
1034
export class StepActorMute<P = StepActor, C extends StepActorOutput = StepActorOutput, O = null> extends Step<P, C, O> {

lib/core/StepActorPosts.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,39 @@ export type StepActorPostsQueryParamsCursor = StepActorPostsQueryParams["cursor"
2828
/**
2929
* Represents a step for retrieving an actor's posts using the Bluesky API.
3030
* Supports paginated retrieval of posts.
31+
*
3132
* @typeParam P - Type of the parent step, extending {@link StepActor}.
3233
* @typeParam C - Type of the context object, extending {@link StepActorOutput}.
3334
* @typeParam O - Type of the output object, extending {@link StepActorPostsOutput}.
35+
*
36+
* @example
37+
* Get an actor's recent posts:
38+
* ```ts
39+
* await Trotsky.init(agent)
40+
* .actor("bsky.app")
41+
* .posts()
42+
* .take(10)
43+
* .each()
44+
* .tap((step) => {
45+
* console.log(step.context.record.text)
46+
* })
47+
* .run()
48+
* ```
49+
*
50+
* @example
51+
* Like an actor's popular posts:
52+
* ```ts
53+
* await Trotsky.init(agent)
54+
* .actor("alice.bsky.social")
55+
* .posts()
56+
* .take(50)
57+
* .each()
58+
* .when((step) => step?.context?.likeCount > 10)
59+
* .like()
60+
* .wait(1000)
61+
* .run()
62+
* ```
63+
*
3464
* @public
3565
*/
3666
export class StepActorPosts<P = StepActor, C extends StepActorOutput = StepActorOutput, O extends StepActorPostsOutput = StepActorPostsOutput> extends StepPosts<P, C, O> {

lib/core/StepActorUnblock.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,33 @@ import { Step, type StepActor, type StepActorOutput } from "../trotsky"
44

55
/**
66
* Represents step that unblocks the current actor (if blocked).
7-
*
7+
*
88
* @typeParam P - The parent step type, defaulting to {@link StepActor}.
99
* @typeParam C - The context or child output type, defaulting to {@link StepActorOutput}.
1010
* @typeParam O - The output type produced by this step, defaulting to `null`.
11+
*
12+
* @example
13+
* Unblock a specific actor:
14+
* ```ts
15+
* await Trotsky.init(agent)
16+
* .actor("user.bsky.social")
17+
* .unblock()
18+
* .run()
19+
* ```
20+
*
21+
* @example
22+
* Unblock all blocked accounts:
23+
* ```ts
24+
* const { data: { blocks } } = await agent.app.bsky.graph.getBlocks()
25+
*
26+
* await Trotsky.init(agent)
27+
* .actors(blocks.map(b => b.did))
28+
* .each()
29+
* .unblock()
30+
* .wait(1000)
31+
* .run()
32+
* ```
33+
*
1134
* @public
1235
*/
1336
export class StepActorUnblock<P = StepActor, C extends StepActorOutput = StepActorOutput, O = null> extends Step<P, C, O> {

0 commit comments

Comments
 (0)