-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrotsky.ts
More file actions
202 lines (182 loc) 路 5.78 KB
/
Copy pathTrotsky.ts
File metadata and controls
202 lines (182 loc) 路 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import type { AtpAgent } from "@atproto/api"
import type { QueryParams } from "@atproto/api/src/client/types/app/bsky/feed/searchPosts"
import type { StepActorParam } from "./StepActor"
import type { StepPostUri } from "./StepPost"
import type { StepPostsUris } from "./StepPosts"
import type { StepCreatePostParams } from "./StepCreatePost"
import type { StepWhenPredicate } from "./StepWhen"
import type { StepTapInterceptor } from "./StepTap"
import type { StepTimelineQueryParams } from "./StepTimeline"
import type { Resolvable } from "./utils/resolvable"
import type { StepStarterPackUri } from "./StepStarterPack"
import type { StepStarterPacksUris } from "./StepStarterPacks"
import type { StepSearchStarterPacksQueryParams } from "./StepSearchStarterPacks"
import {
StepActor,
StepActors,
StepWait,
StepPost,
StepCreatePost,
StepList,
StepListUri,
StepStarterPack,
StepStarterPacks,
StepSearchPosts,
StepSearchStarterPacks,
StepStreamPosts,
StepTap,
StepWhen,
StepBuilder,
StepActorsParam,
StepPosts,
StepSave,
StepSavePath,
StepTimeline
} from "../trotsky"
/**
* Trotsky orchestrates a sequence of steps that interact with an {@link AtpAgent}.
* @typeParam P - Type of the parent object.
* @typeParam C - Type of the context object.
* @typeParam O - Type of the output object.
* @public
*/
export class Trotsky extends StepBuilder {
/**
* Adds a {@link StepActor} step.
* @param param - Parameters for the actor step.
* @returns The new {@link StepActor} instance.
*/
actor (param: Resolvable<StepActorParam>): StepActor<this> {
return this.append(StepActor<this>, param)
}
/**
* Adds a {@link StepActors} step.
* @param param - Parameters for the actors step.
* @returns The new {@link StepActors} instance.
*/
actors (param: Resolvable<StepActorsParam>): StepActors<this> {
return this.append(StepActors<this>, param)
}
/**
* Adds a {@link StepPost} step.
* @param uri - The post URI.
* @returns The new {@link StepPost} instance.
*/
post (uri: Resolvable<StepPostUri>): StepPost<this> {
return this.append(StepPost<this>, uri)
}
/**
* Adds a {@link StepPosts} step.
* @param uris - The post URIs.
* @returns The new {@link StepPosts} instance.
*/
posts (uris: Resolvable<StepPostsUris>): StepPosts<this> {
return this.append(StepPosts<this>, uris)
}
/**
* Adds a {@link StepCreatePost} step.
* @param record - Parameters for creating a post.
* @returns The new {@link StepCreatePost} instance.
*/
createPost (record: StepCreatePostParams): StepCreatePost<this> {
return this.append(StepCreatePost<this>, record)
}
/**
* Adds a {@link StepList} step.
* @param uri - The list URI.
* @returns The new {@link StepList} instance.
*/
list (uri: Resolvable<StepListUri>) {
return this.append(StepList, uri)
}
/**
* Adds a {@link StepStarterPack} step.
* @param uri - The starter pack URI.
* @returns The new {@link StepStarterPack} instance.
*/
starterPack (uri: Resolvable<StepStarterPackUri>) {
return this.append(StepStarterPack, uri)
}
/**
* Adds a {@link StepStarterPacks} step.
* @param uris - The starter pack URIs.
* @returns The new {@link StepStarterPacks} instance.
*/
starterPacks (uris: Resolvable<StepStarterPacksUris>): StepStarterPacks<this> {
return this.append(StepStarterPacks<this>, uris)
}
/**
* Adds a {@link StepSearchPosts} step.
* @param queryParams - Search parameters.
* @returns The new {@link StepSearchPosts} instance.
*/
searchPosts (queryParams: QueryParams): StepSearchPosts<this> {
return this.append(StepSearchPosts<this>, queryParams)
}
/**
* Adds a {@link StepSearchStarterPacks} step.
* @param queryParams - Search parameters.
* @returns The new {@link StepSearchStarterPacks} instance.
*/
searchStarterPacks (queryParams: StepSearchStarterPacksQueryParams): StepSearchStarterPacks<this> {
return this.append(StepSearchStarterPacks<this>, queryParams)
}
/**
* Adds a {@link StepStreamPosts} step.
* @returns The new {@link StepStreamPosts} instance.
*/
streamPosts<T = StepStreamPosts<this>>(): T {
return this.append(StepStreamPosts<this>) as T
}
/**
* Adds a {@link StepTimeline} step.
* @param queryParams - Optional query parameters for the timeline.
* @returns The new {@link StepTimeline} instance.
*/
timeline (queryParams: StepTimelineQueryParams = {}): StepTimeline<this> {
return this.append(StepTimeline<this>, queryParams)
}
/**
* Adds a {@link StepSave} step.
* @param path - The path of the JSON file to save the output. If not provided, the file path will be created using the current step name.
* @returns The current {@link Trotsky} instance.
*/
save (path: StepSavePath = null) {
this.append(StepSave<this>, path)
return this
}
/**
* Adds a {@link StepWait} step.
* @param duration - The duration to wait, in milliseconds.
* @returns The current {@link Trotsky} instance.
*/
wait (duration = 0) {
this.append(StepWait<this>, duration)
return this
}
/**
*Adds a {@link StepWhen} step.
* @param predicate - The predicate function.
* @returns The current {@link Trotsky} instance.
*/
when (predicate: Resolvable<StepWhenPredicate>) {
this.append(StepWhen<this>, predicate)
return this
}
/**
* Adds a {@link StepTap} step.
* @returns The current {@link Trotsky} instance.
*/
tap (interceptor: StepTapInterceptor) {
this.append(StepTap<this>, interceptor)
return this
}
/**
* Initializes a new {@link Trotsky} instance with the specified agent.
* @param agent - The {@link AtpAgent} instance.
* @returns A new {@link Trotsky} instance.
*/
static init (agent: AtpAgent): Trotsky {
return new Trotsky(agent)
}
}