Skip to content

Commit 4243b19

Browse files
committed
update docs
1 parent 78b6d81 commit 4243b19

File tree

9 files changed

+156
-147
lines changed

9 files changed

+156
-147
lines changed

www/docs/pages/advanced/batch-processing.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ Process large datasets in chunks:
174174

175175
```go
176176
func createChunkedProcessor(chunkSize int) flyt.Node {
177-
return flyt.NewNode(
178-
flyt.WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (any, error) {
177+
// Using fluent API for chunked processing
178+
return flyt.NewNode().
179+
WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (any, error) {
179180
items := shared.GetSlice("items")
180181
return items, nil
181-
}),
182-
flyt.WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
182+
}).
183+
WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
183184
items := prepResult.([]any)
184185
results := make([]any, 0, len(items))
185186

@@ -196,8 +197,7 @@ func createChunkedProcessor(chunkSize int) flyt.Node {
196197
}
197198

198199
return results, nil
199-
}),
200-
)
200+
})
201201
}
202202
```
203203

www/docs/pages/concepts/actions.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ flow.Connect(node1, flyt.DefaultAction, node2)
4040
### Simple Branching
4141

4242
```go
43-
validationNode := flyt.NewNode(
44-
flyt.WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
43+
// Using fluent API for cleaner code
44+
validationNode := flyt.NewNode().
45+
WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
4546
data := prepResult.(string)
4647
return len(data) > 0, nil
47-
}),
48-
flyt.WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, prepResult, execResult any) (flyt.Action, error) {
48+
}).
49+
WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, prepResult, execResult any) (flyt.Action, error) {
4950
if execResult.(bool) {
5051
return "valid", nil
5152
}
5253
return "invalid", nil
53-
}),
54-
)
54+
})
5555

5656
flow := flyt.NewFlow(validationNode)
5757
flow.Connect(validationNode, "valid", processNode)
@@ -61,20 +61,20 @@ flow.Connect(validationNode, "invalid", errorNode)
6161
### Multi-Way Branching
6262

6363
```go
64-
categoryNode := flyt.NewNode(
65-
flyt.WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
64+
// Fluent API for multi-way branching
65+
categoryNode := flyt.NewNode().
66+
WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
6667
value := prepResult.(int)
6768
if value < 10 {
6869
return "small", nil
6970
} else if value < 100 {
7071
return "medium", nil
7172
}
7273
return "large", nil
73-
}),
74-
flyt.WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, prepResult, execResult any) (flyt.Action, error) {
74+
}).
75+
WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, prepResult, execResult any) (flyt.Action, error) {
7576
return flyt.Action(execResult.(string)), nil
76-
}),
77-
)
77+
})
7878

7979
flow := flyt.NewFlow(categoryNode)
8080
flow.Connect(categoryNode, "small", smallHandler)

www/docs/pages/concepts/nodes.mdx

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ Flyt provides two styles of helper functions for creating nodes:
7777
Use `WithPrepFunc`, `WithExecFunc`, and `WithPostFunc` for type-safe operations with the Result type:
7878

7979
```go
80-
node := flyt.NewNode(
81-
flyt.WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (flyt.Result, error) {
80+
// Using fluent API for cleaner chaining
81+
node := flyt.NewNode().
82+
WithPrepFunc(func(ctx context.Context, shared *flyt.SharedStore) (flyt.Result, error) {
8283
// Use type-safe getters
8384
message := shared.GetString("message")
8485
retryCount := shared.GetIntOr("retry_count", 0)
@@ -87,17 +88,17 @@ node := flyt.NewNode(
8788
"message": message,
8889
"retry": retryCount,
8990
}), nil
90-
}),
91-
flyt.WithExecFuncAny(func(ctx context.Context, prepResult flyt.Result) (flyt.Result, error) {
91+
}).
92+
WithExecFunc(func(ctx context.Context, prepResult flyt.Result) (flyt.Result, error) {
9293
// Type-safe access to data
9394
data := prepResult.AsMapOr(nil)
9495
message := data["message"].(string)
9596

9697
// Process and return Result
9798
processed := processMessage(message)
9899
return flyt.NewResult(processed), nil
99-
}),
100-
flyt.WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, prepResult, execResult flyt.Result) (flyt.Action, error) {
100+
}).
101+
WithPostFunc(func(ctx context.Context, shared *flyt.SharedStore, prepResult, execResult flyt.Result) (flyt.Action, error) {
101102
// Type-safe result handling
102103
result := execResult.Value()
103104
shared.Set("result", result)
@@ -106,17 +107,17 @@ node := flyt.NewNode(
106107
return "max_retries", nil
107108
}
108109
return flyt.DefaultAction, nil
109-
}),
110-
)
110+
})
111111
```
112112

113113
#### Any-based Functions (Simple)
114114

115115
Use `WithPrepFuncAny`, `WithExecFuncAny`, and `WithPostFuncAny` for simpler cases or backward compatibility:
116116

117117
```go
118-
node := flyt.NewNode(
119-
flyt.WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (any, error) {
118+
// Using fluent API with any-based functions
119+
node := flyt.NewNode().
120+
WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (any, error) {
120121
// Direct any types
121122
message := shared.GetString("message")
122123
retryCount := shared.GetIntOr("retry_count", 0)
@@ -125,22 +126,21 @@ node := flyt.NewNode(
125126
"message": message,
126127
"retry": retryCount,
127128
}, nil
128-
}),
129-
flyt.WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
129+
}).
130+
WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
130131
data := prepResult.(map[string]any)
131132
// Process the data
132133
return processMessage(data["message"].(string)), nil
133-
}),
134-
flyt.WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, prepResult, execResult any) (flyt.Action, error) {
134+
}).
135+
WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, prepResult, execResult any) (flyt.Action, error) {
135136
// Store result and determine action
136137
shared.Set("result", execResult)
137138

138139
if shared.GetInt("retry_count") > 3 {
139140
return "max_retries", nil
140141
}
141142
return flyt.DefaultAction, nil
142-
}),
143-
)
143+
})
144144
```
145145

146146
### Choosing Between Result and Any
@@ -192,24 +192,31 @@ func (n *DatabaseNode) Exec(ctx context.Context, prepResult any) (any, error) {
192192
Configure node behavior with options:
193193

194194
```go
195-
// With Result type
196-
node := flyt.NewNode(
197-
flyt.WithExecFuncAny(func(ctx context.Context, input flyt.Result) (flyt.Result, error) {
195+
// With Result type using fluent API
196+
node := flyt.NewNode().
197+
WithExecFunc(func(ctx context.Context, input flyt.Result) (flyt.Result, error) {
198198
// Type-safe operations
199199
return flyt.NewResult(processData(input.Value())), nil
200-
}),
201-
flyt.WithMaxRetries(3), // Retry up to 3 times
202-
flyt.WithWait(time.Second * 2), // Wait 2 seconds between retries
203-
)
200+
}).
201+
WithMaxRetries(3). // Retry up to 3 times
202+
WithWait(time.Second * 2) // Wait 2 seconds between retries
204203

205-
// With any type
204+
// With any type using fluent API
205+
node := flyt.NewNode().
206+
WithExecFuncAny(func(ctx context.Context, input any) (any, error) {
207+
// Direct any handling
208+
return processData(input), nil
209+
}).
210+
WithMaxRetries(3). // Retry up to 3 times
211+
WithWait(time.Second * 2) // Wait 2 seconds between retries
212+
213+
// Traditional style still supported
206214
node := flyt.NewNode(
207215
flyt.WithExecFuncAny(func(ctx context.Context, input any) (any, error) {
208-
// Direct any handling
209216
return processData(input), nil
210217
}),
211-
flyt.WithMaxRetries(3), // Retry up to 3 times
212-
flyt.WithWait(time.Second * 2), // Wait 2 seconds between retries
218+
flyt.WithMaxRetries(3),
219+
flyt.WithWait(time.Second * 2),
213220
)
214221
```
215222

www/docs/pages/getting-started/quick-start.mdx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ import (
1818
)
1919

2020
func main() {
21-
// Create a node with Result type for better type safety
22-
node := flyt.NewNode(
21+
// Create a node with Result type using fluent API
22+
node := flyt.NewNode().
23+
WithExecFunc(func(ctx context.Context, prepResult flyt.Result) (flyt.Result, error) {
24+
fmt.Println("Processing data...")
25+
return flyt.NewResult("Hello, Flyt!"), nil
26+
})
27+
28+
// Or using traditional style with options
29+
node = flyt.NewNode(
2330
flyt.WithExecFunc(func(ctx context.Context, prepResult flyt.Result) (flyt.Result, error) {
2431
fmt.Println("Processing data...")
2532
return flyt.NewResult("Hello, Flyt!"), nil
@@ -44,13 +51,12 @@ func main() {
4451

4552
```go
4653
func main() {
47-
// Create a node with any type for simpler code
48-
node := flyt.NewNode(
49-
flyt.WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
54+
// Create a node with any type using fluent API
55+
node := flyt.NewNode().
56+
WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
5057
fmt.Println("Processing data...")
5158
return "Hello, Flyt!", nil
52-
}),
53-
)
59+
})
5460

5561
// Create shared store and context
5662
shared := flyt.NewSharedStore()
@@ -133,8 +139,9 @@ Let's add retry logic and error handling:
133139
func createRobustNode() flyt.Node {
134140
attempts := 0
135141

136-
return flyt.NewNode(
137-
flyt.WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
142+
// Using fluent API for configuration
143+
return flyt.NewNode().
144+
WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
138145
attempts++
139146
fmt.Printf("Attempt %d...\n", attempts)
140147

@@ -144,10 +151,9 @@ func createRobustNode() flyt.Node {
144151
}
145152

146153
return "Success!", nil
147-
}),
148-
flyt.WithMaxRetries(3),
149-
flyt.WithWait(time.Second),
150-
)
154+
}).
155+
WithMaxRetries(3).
156+
WithWait(time.Second)
151157
}
152158
```
153159

www/docs/pages/getting-started/template.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ import (
100100
)
101101

102102
func CreateCustomNode() flyt.Node {
103-
return flyt.NewNode(
104-
flyt.WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
103+
// Using fluent API
104+
return flyt.NewNode().
105+
WithExecFuncAny(func(ctx context.Context, prepResult any) (any, error) {
105106
// Your custom logic here
106107
return "custom result", nil
107-
}),
108-
)
108+
})
109109
}
110110
```
111111

www/docs/pages/index.mdx

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,46 +82,43 @@ import (
8282
)
8383

8484
func main() {
85-
// Create nodes that share data via SharedStore
86-
fetchNode := flyt.NewNode(
87-
flyt.WithExecFuncAny(func(ctx context.Context, _ any) (any, error) {
85+
// Create nodes using fluent API
86+
fetchNode := flyt.NewNode().
87+
WithExecFuncAny(func(ctx context.Context, _ any) (any, error) {
8888
fmt.Println("Fetching data...")
8989
return map[string]int{"value": 42}, nil
90-
}),
91-
flyt.WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, _, execResult any) (flyt.Action, error) {
90+
}).
91+
WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, _, execResult any) (flyt.Action, error) {
9292
shared.Set("data", execResult)
9393
return flyt.DefaultAction, nil
94-
}),
95-
)
94+
})
9695

97-
processNode := flyt.NewNode(
98-
flyt.WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (any, error) {
96+
processNode := flyt.NewNode().
97+
WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (any, error) {
9998
// Type-safe access to data
10099
data := shared.GetMap("data")
101100
return data, nil
102-
}),
103-
flyt.WithExecFuncAny(func(ctx context.Context, data any) (any, error) {
101+
}).
102+
WithExecFuncAny(func(ctx context.Context, data any) (any, error) {
104103
val := data.(map[string]any)["value"].(int)
105104
fmt.Printf("Processing: %d\n", val)
106105
return val * 2, nil
107-
}),
108-
flyt.WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, _, execResult any) (flyt.Action, error) {
106+
}).
107+
WithPostFuncAny(func(ctx context.Context, shared *flyt.SharedStore, _, execResult any) (flyt.Action, error) {
109108
shared.Set("result", execResult)
110109
return flyt.DefaultAction, nil
111-
}),
112-
)
110+
})
113111

114-
saveNode := flyt.NewNode(
115-
flyt.WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (any, error) {
112+
saveNode := flyt.NewNode().
113+
WithPrepFuncAny(func(ctx context.Context, shared *flyt.SharedStore) (any, error) {
116114
// Type-safe getter for integer result
117115
result := shared.GetInt("result")
118116
return result, nil
119-
}),
120-
flyt.WithExecFuncAny(func(ctx context.Context, result any) (any, error) {
117+
}).
118+
WithExecFuncAny(func(ctx context.Context, result any) (any, error) {
121119
fmt.Printf("Saving result: %d\n", result)
122120
return nil, nil
123-
}),
124-
)
121+
})
125122

126123
// Build and run flow
127124
flow := flyt.NewFlow(fetchNode)

0 commit comments

Comments
 (0)