Skip to content

Commit 85676cf

Browse files
committed
feat: add map and array steps for parallel processing (#207)
## Summary Adds a new `.array()` method to the Flow class that provides compile-time type safety for array-returning step handlers while maintaining full compatibility with existing functionality. ## Key Features - **Compile-time type enforcement**: TypeScript rejects non-array return types - **Zero runtime overhead**: Pure delegation to existing `.step()` method - **Full feature parity**: Complete support for dependencies, runtime options, and validation - **Semantic clarity**: Clear intent when creating array-producing steps ```ts // Type safety - these will fail at compile time: flow.array({ slug: 'invalid' }, () => 42); // ❌ Error: not an array flow.array({ slug: 'invalid2' }, () => "string"); // ❌ Error: not an array ``` ## Implementation Details - **Pure delegation**: `return this.step(opts, handler);` for maximum code reuse - **Type constraints**: `Array<Json> | Promise<Array<Json>>` return type enforcement - **Utility type reuse**: Leverages existing `StepInput<this, Deps>`, `AwaitedReturn<THandler>`, etc. - **Identical behavior**: Produces the same step definitions as `.step()` for array handlers ## Testing - **169 total tests passing** (162 existing + 7 new integration tests) - **15 type tests** validating compile-time constraints - **27 runtime tests** ensuring behavioral equivalence with `.step()` - **7 integration tests** covering complex real-world scenarios ## Breaking Changes None. This is purely additive functionality that maintains full backward compatibility. ## Related This implements Phase 1 of the array processing roadmap from PLAN.md, laying the foundation for future phases including queue routing and `.map()` method integration.
1 parent c5399ae commit 85676cf

File tree

6 files changed

+1654
-0
lines changed

6 files changed

+1654
-0
lines changed

.changeset/tricky-sites-stare.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@pgflow/dsl': minor
3+
---
4+
5+
Add `.array()` method for type-safe array step creation
6+
7+
Introduces a new `.array()` method that provides compile-time type safety for array-returning handlers with zero runtime overhead.
8+
9+
- Enforces array return types at compile time
10+
- Pure delegation to existing `.step()` method
11+
- Full support for dependencies and runtime options
12+
- Backward compatible
13+
14+
```typescript
15+
flow.array({ slug: 'items' }, () => [1, 2, 3]); // ✅ Valid
16+
flow.array({ slug: 'invalid' }, () => 42); // ❌ Compile error
17+
```

0 commit comments

Comments
 (0)