Skip to content

Commit bdfc3f6

Browse files
committed
[refactor] rename FetchTask to FetchUrlTask
- Replaced FetchTask with FetchUrlTask across the codebase to improve clarity and functionality. - Updated documentation to reflect the new FetchUrlTask, including usage examples and available options. - Added comprehensive tests for FetchUrlTask to ensure robust functionality and error handling. - Enhanced the task's ability to handle various response types and progress tracking during fetch operations.
1 parent 9d0163f commit bdfc3f6

File tree

5 files changed

+76
-70
lines changed

5 files changed

+76
-70
lines changed

examples/web/src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "@workglow/ai";
1313
import { installDevToolsFormatters, isDarkMode } from "@workglow/debug";
1414
import { Task, TaskGraph, Workflow } from "@workglow/task-graph";
15-
import { DebugLogTask, DelayTask, FetchTask, JsonTask, LambdaTask } from "@workglow/tasks";
15+
import { DebugLogTask, DelayTask, FetchUrlTask, JsonTask, LambdaTask } from "@workglow/tasks";
1616
import ReactDOM from "react-dom/client";
1717
import { App } from "./App";
1818
import "./main.css";
@@ -37,7 +37,7 @@ installDevToolsFormatters();
3737
TaskGraph,
3838
JsonTask,
3939
DelayTask,
40-
FetchTask,
40+
FetchUrlTask,
4141
LambdaTask,
4242
].forEach((item) => {
4343
window[item.name] = item;

packages/tasks/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A package of task types for common operations, workflow management, and data pro
88
- [Installation](#installation)
99
- [Quick Start](#quick-start)
1010
- [Available Tasks](#available-tasks)
11-
- [FetchTask](#fetchtask)
11+
- [FetchUrlTask](#fetchurltask)
1212
- [DebugLogTask](#debuglogtask)
1313
- [DelayTask](#delaytask)
1414
- [JavaScriptTask](#javascripttask)
@@ -41,10 +41,10 @@ const results = await workflow.run();
4141
```
4242

4343
```typescript
44-
import { FetchTask, DebugLogTask, DelayTask } from "@workglow/tasks";
44+
import { FetchUrlTask, DebugLogTask, DelayTask } from "@workglow/tasks";
4545

4646
// Simple sequence using Task classes directly
47-
const fetchResult = await new FetchTask({
47+
const fetchResult = await new FetchUrlTask({
4848
url: "https://api.example.com/data",
4949
response_type: "json",
5050
}).run();
@@ -72,7 +72,7 @@ await debugLog({
7272

7373
## Available Tasks
7474

75-
### FetchTask
75+
### FetchUrlTask
7676

7777
Makes HTTP requests with built-in retry logic, progress tracking, and multiple response types.
7878

@@ -97,14 +97,14 @@ Makes HTTP requests with built-in retry logic, progress tracking, and multiple r
9797

9898
```typescript
9999
// Simple GET request
100-
const response = await new FetchTask({
100+
const response = await new FetchUrlTask({
101101
url: "https://api.example.com/users",
102102
response_type: "json",
103103
}).run();
104104
console.log(response.json);
105105

106106
// POST request with headers
107-
const postResponse = await new FetchTask({
107+
const postResponse = await new FetchUrlTask({
108108
url: "https://api.example.com/users",
109109
method: "POST",
110110
headers: {
@@ -116,7 +116,7 @@ const postResponse = await new FetchTask({
116116
}).run();
117117

118118
// Text response
119-
const textResponse = await new FetchTask({
119+
const textResponse = await new FetchUrlTask({
120120
url: "https://example.com/readme.txt",
121121
response_type: "text",
122122
}).run();
@@ -380,7 +380,7 @@ Creates and executes task graphs from JSON configurations, enabling dynamic work
380380
```typescript
381381
interface JsonTaskItem {
382382
id: string; // Unique task identifier
383-
type: string; // Task type (e.g., "FetchTask", "DelayTask")
383+
type: string; // Task type (e.g., "FetchUrlTask", "DelayTask")
384384
input?: any; // Task input data
385385
config?: any; // Task configuration
386386
dependencies?: {
@@ -403,7 +403,7 @@ const linearWorkflow = await new JsonTask({
403403
json: JSON.stringify([
404404
{
405405
id: "fetch-data",
406-
type: "FetchTask",
406+
type: "FetchUrlTask",
407407
input: {
408408
url: "https://api.example.com/users",
409409
response_type: "json",
@@ -432,15 +432,15 @@ const complexWorkflow = await new JsonTask({
432432
json: JSON.stringify([
433433
{
434434
id: "fetch-users",
435-
type: "FetchTask",
435+
type: "FetchUrlTask",
436436
input: {
437437
url: "https://api.example.com/users",
438438
response_type: "json",
439439
},
440440
},
441441
{
442442
id: "fetch-posts",
443-
type: "FetchTask",
443+
type: "FetchUrlTask",
444444
input: {
445445
url: "https://api.example.com/posts",
446446
response_type: "json",
@@ -532,7 +532,7 @@ Tasks include comprehensive error handling:
532532

533533
```typescript
534534
try {
535-
const result = await new FetchTask({
535+
const result = await new FetchUrlTask({
536536
url: "https://api.example.com/data",
537537
response_type: "json",
538538
timeout: 5000,
@@ -556,7 +556,7 @@ Tasks support various configuration options:
556556

557557
```typescript
558558
// Task-specific configuration
559-
const fetchTask = new FetchTask(
559+
const fetchTask = new FetchUrlTask(
560560
{
561561
url: "https://api.example.com/data",
562562
},

packages/tasks/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
export * from "./task/DebugLogTask";
88
export * from "./task/DelayTask";
9-
export * from "./task/FetchTask";
9+
export * from "./task/FetchUrlTask";
1010
export * from "./task/JavaScriptTask";
1111
export * from "./task/JsonTask";
1212
export * from "./task/LambdaTask";
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ const outputSchema = {
9595
additionalProperties: false,
9696
} as const satisfies DataPortSchema;
9797

98-
export type FetchTaskInput = FromSchema<typeof inputSchema>;
99-
export type FetchTaskOutput = FromSchema<typeof outputSchema>;
98+
export type FetchUrlTaskInput = FromSchema<typeof inputSchema>;
99+
export type FetchUrlTaskOutput = FromSchema<typeof outputSchema>;
100100

101-
export type FetchTaskConfig = JobQueueTaskConfig;
101+
export type FetchUrlTaskConfig = JobQueueTaskConfig;
102102

103103
async function fetchWithProgress(
104104
url: string,
@@ -165,14 +165,14 @@ async function fetchWithProgress(
165165
* Extends the base Job class to provide custom execution functionality
166166
* through a provided function.
167167
*/
168-
export class FetchJob<
169-
Input extends FetchTaskInput = FetchTaskInput,
170-
Output = FetchTaskOutput,
168+
export class FetchUrlJob<
169+
Input extends FetchUrlTaskInput = FetchUrlTaskInput,
170+
Output = FetchUrlTaskOutput,
171171
> extends Job<Input, Output> {
172172
constructor(config: JobQueueTaskConfig & { input: Input } = { input: {} as Input }) {
173173
super(config);
174174
}
175-
static readonly type: string = "FetchJob";
175+
static readonly type: string = "FetchUrlJob";
176176
/**
177177
* Executes the job using the provided function.
178178
*/
@@ -257,14 +257,14 @@ export class FetchJob<
257257
}
258258

259259
/**
260-
* FetchTask provides a task for fetching data from a URL.
260+
* FetchUrlTask provides a task for fetching data from a URL.
261261
*/
262-
export class FetchTask<
263-
Input extends FetchTaskInput = FetchTaskInput,
264-
Output extends FetchTaskOutput = FetchTaskOutput,
265-
Config extends FetchTaskConfig = FetchTaskConfig,
262+
export class FetchUrlTask<
263+
Input extends FetchUrlTaskInput = FetchUrlTaskInput,
264+
Output extends FetchUrlTaskOutput = FetchUrlTaskOutput,
265+
Config extends FetchUrlTaskConfig = FetchUrlTaskConfig,
266266
> extends JobQueueTask<Input, Output, Config> {
267-
public static type = "FetchTask";
267+
public static type = "FetchUrlTask";
268268
public static category = "Input";
269269
public static title = "Fetch";
270270
public static description =
@@ -291,11 +291,11 @@ export class FetchTask<
291291

292292
// If response_type is null or undefined, return all output types (static schema)
293293
if (responseType === null || responseType === undefined) {
294-
return (this.constructor as typeof FetchTask).outputSchema();
294+
return (this.constructor as typeof FetchUrlTask).outputSchema();
295295
}
296296

297297
// If response_type is a specific value, return only that output type
298-
const staticSchema = (this.constructor as typeof FetchTask).outputSchema();
298+
const staticSchema = (this.constructor as typeof FetchUrlTask).outputSchema();
299299
if (typeof staticSchema === "boolean") {
300300
return staticSchema;
301301
}
@@ -334,7 +334,7 @@ export class FetchTask<
334334
config.queue = false; // change default to false to run directly
335335
}
336336
super(input, config);
337-
this.jobClass = FetchJob;
337+
this.jobClass = FetchUrlJob;
338338
}
339339

340340
/**
@@ -387,20 +387,20 @@ export class FetchTask<
387387
}
388388
}
389389

390-
TaskRegistry.registerTask(FetchTask);
390+
TaskRegistry.registerTask(FetchUrlTask);
391391

392-
export const fetch = async (
393-
input: FetchTaskInput,
394-
config: FetchTaskConfig = {}
395-
): Promise<FetchTaskOutput> => {
396-
const result = await new FetchTask(input, config).run();
397-
return result as FetchTaskOutput;
392+
export const fetchUrl = async (
393+
input: FetchUrlTaskInput,
394+
config: FetchUrlTaskConfig = {}
395+
): Promise<FetchUrlTaskOutput> => {
396+
const result = await new FetchUrlTask(input, config).run();
397+
return result as FetchUrlTaskOutput;
398398
};
399399

400400
declare module "@workglow/task-graph" {
401401
interface Workflow {
402-
fetch: CreateWorkflow<FetchTaskInput, FetchTaskOutput, FetchTaskConfig>;
402+
fetch: CreateWorkflow<FetchUrlTaskInput, FetchUrlTaskOutput, FetchUrlTaskConfig>;
403403
}
404404
}
405405

406-
Workflow.prototype.fetch = CreateWorkflow(FetchTask);
406+
Workflow.prototype.fetch = CreateWorkflow(FetchUrlTask);

0 commit comments

Comments
 (0)