@multiplier-labs/stepflow 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/.github/workflows/publish.yml +30 -0
  2. package/README.md +408 -0
  3. package/dist/chunk-FQCT3I2A.js +1512 -0
  4. package/dist/chunk-FQCT3I2A.js.map +1 -0
  5. package/dist/chunk-GXY66V7Q.js +111 -0
  6. package/dist/chunk-GXY66V7Q.js.map +1 -0
  7. package/dist/chunk-U5QGN3RT.js +715 -0
  8. package/dist/chunk-U5QGN3RT.js.map +1 -0
  9. package/dist/chunk-XCF4PLN7.js +575 -0
  10. package/dist/chunk-XCF4PLN7.js.map +1 -0
  11. package/dist/events/index.d.ts +346 -0
  12. package/dist/events/index.js +11 -0
  13. package/dist/events/index.js.map +1 -0
  14. package/dist/index-CPfGsmrp.d.ts +567 -0
  15. package/dist/index.d.ts +748 -0
  16. package/dist/index.js +1707 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/scheduler/index.d.ts +6 -0
  19. package/dist/scheduler/index.js +12 -0
  20. package/dist/scheduler/index.js.map +1 -0
  21. package/dist/storage/index.d.ts +402 -0
  22. package/dist/storage/index.js +13 -0
  23. package/dist/storage/index.js.map +1 -0
  24. package/dist/types-BVShq7zT.d.ts +150 -0
  25. package/dist/types-BlwFEGzj.d.ts +276 -0
  26. package/dist/types-DzkEqnQJ.d.ts +75 -0
  27. package/docs/github-packages-setup.md +97 -0
  28. package/docs/stepflow-api-reference.md +1662 -0
  29. package/package.json +85 -0
  30. package/src/core/engine.test.ts +1421 -0
  31. package/src/core/engine.ts +717 -0
  32. package/src/core/index.ts +7 -0
  33. package/src/core/orchestrator.ts +590 -0
  34. package/src/core/types.ts +242 -0
  35. package/src/events/index.ts +8 -0
  36. package/src/events/memory.test.ts +109 -0
  37. package/src/events/memory.ts +95 -0
  38. package/src/events/socketio.test.ts +428 -0
  39. package/src/events/socketio.ts +269 -0
  40. package/src/events/types.ts +121 -0
  41. package/src/events/webhook.test.ts +695 -0
  42. package/src/events/webhook.ts +591 -0
  43. package/src/index.ts +270 -0
  44. package/src/planning/index.ts +52 -0
  45. package/src/planning/planner.ts +601 -0
  46. package/src/planning/planning.test.ts +790 -0
  47. package/src/planning/registry.test.ts +445 -0
  48. package/src/planning/registry.ts +369 -0
  49. package/src/planning/types.ts +570 -0
  50. package/src/scheduler/cron.test.ts +480 -0
  51. package/src/scheduler/cron.ts +449 -0
  52. package/src/scheduler/index.ts +18 -0
  53. package/src/scheduler/postgres-persistence.test.ts +906 -0
  54. package/src/scheduler/postgres-persistence.ts +546 -0
  55. package/src/scheduler/sqlite-persistence.test.ts +235 -0
  56. package/src/scheduler/sqlite-persistence.ts +268 -0
  57. package/src/scheduler/types.ts +78 -0
  58. package/src/storage/index.ts +27 -0
  59. package/src/storage/memory.test.ts +399 -0
  60. package/src/storage/memory.ts +248 -0
  61. package/src/storage/postgres.ts +1550 -0
  62. package/src/storage/sqlite.test.ts +593 -0
  63. package/src/storage/sqlite.ts +662 -0
  64. package/src/storage/types.ts +368 -0
  65. package/src/utils/errors.test.ts +152 -0
  66. package/src/utils/errors.ts +191 -0
  67. package/src/utils/id.ts +21 -0
  68. package/src/utils/index.ts +8 -0
  69. package/src/utils/logger.test.ts +127 -0
  70. package/src/utils/logger.ts +96 -0
  71. package/src/utils/postgres-deps.ts +63 -0
  72. package/src/utils/retry.test.ts +197 -0
  73. package/src/utils/retry.ts +121 -0
  74. package/tsconfig.json +21 -0
  75. package/tsup.config.ts +14 -0
  76. package/vitest.config.ts +9 -0
package/src/index.ts ADDED
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Stepflow - Workflow Engine
3
+ *
4
+ * A framework-agnostic workflow engine that provides:
5
+ * - Workflow Definition & Registration
6
+ * - Async Execution Engine (non-blocking, fire-and-forget)
7
+ * - State Management (run/step status tracking with checkpointing)
8
+ * - Event System (real-time events for monitoring and UI updates)
9
+ * - Pluggable Storage (bring your own database/persistence layer)
10
+ * - Retry & Error Handling (configurable per-step error strategies)
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { WorkflowEngine, MemoryStorageAdapter } from 'stepflow';
15
+ *
16
+ * const engine = new WorkflowEngine({
17
+ * storage: new MemoryStorageAdapter(),
18
+ * });
19
+ *
20
+ * engine.registerWorkflow({
21
+ * kind: 'email.send_campaign',
22
+ * name: 'Send Email Campaign',
23
+ * steps: [
24
+ * {
25
+ * key: 'load_recipients',
26
+ * name: 'Load Recipients',
27
+ * handler: async (ctx) => {
28
+ * const recipients = await loadRecipients(ctx.input.campaignId);
29
+ * return { recipients };
30
+ * },
31
+ * },
32
+ * {
33
+ * key: 'send_emails',
34
+ * name: 'Send Emails',
35
+ * handler: async (ctx) => {
36
+ * const { recipients } = ctx.results.load_recipients;
37
+ * // Send emails...
38
+ * return { sent: recipients.length };
39
+ * },
40
+ * onError: 'retry',
41
+ * maxRetries: 3,
42
+ * },
43
+ * ],
44
+ * });
45
+ *
46
+ * const runId = await engine.startRun({
47
+ * kind: 'email.send_campaign',
48
+ * input: { campaignId: '123' },
49
+ * });
50
+ *
51
+ * // Subscribe to events
52
+ * engine.subscribeToRun(runId, (event) => {
53
+ * console.log(`${event.eventType}: ${event.stepKey ?? 'run'}`);
54
+ * });
55
+ * ```
56
+ */
57
+
58
+ // ============================================================================
59
+ // Core Types and Classes
60
+ // ============================================================================
61
+
62
+ export {
63
+ // Types
64
+ type WorkflowKind,
65
+ type RunStatus,
66
+ type StepStatus,
67
+ type StepErrorStrategy,
68
+ type WorkflowError,
69
+ type RunResult,
70
+ type Logger,
71
+ type SpawnChildOptions,
72
+ type WorkflowContext,
73
+ type WorkflowStep,
74
+ type WorkflowHooks,
75
+ type WorkflowDefinition,
76
+ } from "./core/types";
77
+
78
+ export {
79
+ // Main Engine
80
+ WorkflowEngine,
81
+ type WorkflowEngineConfig,
82
+ type StartRunOptions,
83
+ } from "./core/engine";
84
+
85
+ // ============================================================================
86
+ // Storage
87
+ // ============================================================================
88
+
89
+ export {
90
+ // Types
91
+ type StorageAdapter,
92
+ type WorkflowStorage,
93
+ type WorkflowRunRecord,
94
+ type WorkflowRunStepRecord,
95
+ type WorkflowEventRecord,
96
+ type ListRunsOptions,
97
+ type ListEventsOptions,
98
+ type PaginatedResult,
99
+ type CreateRunInput,
100
+ type UpdateRunInput,
101
+ type StepResult,
102
+ type StepRecord,
103
+ // Extended types for new WorkflowStorage implementations
104
+ type ExtendedWorkflowRunRecord,
105
+ type ExtendedRunStatus,
106
+ type ExtendedStepStatus,
107
+ type ExtendedListRunsOptions,
108
+ type StepflowRunsTable,
109
+ type StepflowStepResultsTable,
110
+ type StepflowDatabase,
111
+ } from "./storage/types";
112
+
113
+ export {
114
+ // In-Memory Storage
115
+ MemoryStorageAdapter,
116
+ } from "./storage/memory";
117
+
118
+ export {
119
+ // SQLite Storage
120
+ SQLiteStorageAdapter,
121
+ type SQLiteStorageConfig,
122
+ } from "./storage/sqlite";
123
+
124
+ export {
125
+ // PostgreSQL Storage
126
+ PostgresStorageAdapter,
127
+ PostgresStorageAdapter as PostgresStorage,
128
+ type PostgresStorageConfig,
129
+ } from "./storage/postgres";
130
+
131
+ // ============================================================================
132
+ // Events
133
+ // ============================================================================
134
+
135
+ export {
136
+ // Types
137
+ type EventTransport,
138
+ type WorkflowEvent,
139
+ type WorkflowEventType,
140
+ type BuiltInEventType,
141
+ type EventCallback,
142
+ type Unsubscribe,
143
+ } from "./events/types";
144
+
145
+ export {
146
+ // In-Memory Event Transport
147
+ MemoryEventTransport,
148
+ } from "./events/memory";
149
+
150
+ export {
151
+ // Socket.IO Event Transport
152
+ SocketIOEventTransport,
153
+ type SocketIOEventTransportConfig,
154
+ type SocketIOServer,
155
+ type SocketIOSocket,
156
+ type SocketIOAuthorizeFn,
157
+ } from "./events/socketio";
158
+
159
+ export {
160
+ // Webhook Event Transport
161
+ WebhookEventTransport,
162
+ type WebhookEventTransportConfig,
163
+ type WebhookEndpoint,
164
+ type WebhookPayload,
165
+ } from "./events/webhook";
166
+
167
+ // ============================================================================
168
+ // Scheduler
169
+ // ============================================================================
170
+
171
+ export {
172
+ type TriggerType,
173
+ type WorkflowSchedule,
174
+ type Scheduler,
175
+ } from "./scheduler/types";
176
+
177
+ export {
178
+ CronScheduler,
179
+ type CronSchedulerConfig,
180
+ type SchedulePersistence,
181
+ } from "./scheduler/cron";
182
+
183
+ export {
184
+ SQLiteSchedulePersistence,
185
+ type SQLiteSchedulePersistenceConfig,
186
+ } from "./scheduler/sqlite-persistence";
187
+
188
+ export {
189
+ PostgresSchedulePersistence,
190
+ type PostgresSchedulePersistenceConfig,
191
+ } from "./scheduler/postgres-persistence";
192
+
193
+ // ============================================================================
194
+ // Utilities
195
+ // ============================================================================
196
+
197
+ export {
198
+ // ID Generation
199
+ generateId,
200
+ } from "./utils/id";
201
+
202
+ export {
203
+ // Errors
204
+ WorkflowEngineError,
205
+ WorkflowNotFoundError,
206
+ WorkflowAlreadyRegisteredError,
207
+ RunNotFoundError,
208
+ StepError,
209
+ StepTimeoutError,
210
+ WaitForRunTimeoutError,
211
+ WorkflowCanceledError,
212
+ WorkflowTimeoutError,
213
+ } from "./utils/errors";
214
+
215
+ export {
216
+ // Logger
217
+ ConsoleLogger,
218
+ SilentLogger,
219
+ createScopedLogger,
220
+ sanitizeErrorForStorage,
221
+ type LogLevel,
222
+ } from "./utils/logger";
223
+
224
+ export {
225
+ // Retry
226
+ type RetryOptions,
227
+ DEFAULT_RETRY_OPTIONS,
228
+ sleep,
229
+ withRetry,
230
+ calculateRetryDelay,
231
+ } from "./utils/retry";
232
+
233
+ // ============================================================================
234
+ // Planning
235
+ // ============================================================================
236
+
237
+ export {
238
+ // Types
239
+ type ConditionOperator,
240
+ type RecipeCondition,
241
+ type RecipeDefaults,
242
+ type StepHandlerRef,
243
+ type RecipeStep,
244
+ type Recipe,
245
+ type PlanModificationType,
246
+ type PlanModification,
247
+ type PlannedStep,
248
+ type ChildWorkflowPlan,
249
+ type ResourceEstimate,
250
+ type Plan,
251
+ type PlanningPriority,
252
+ type PlanningConstraints,
253
+ type PlanningHints,
254
+ type PlanningContext,
255
+ type RecipeSelectionResult,
256
+ type PlanValidationResult,
257
+ type Planner,
258
+ type RegisteredStepHandler,
259
+ type StepHandlerRegistry,
260
+ type RecipeQueryOptions,
261
+ type RecipeRegistry,
262
+
263
+ // Implementations
264
+ MemoryStepHandlerRegistry,
265
+ MemoryRecipeRegistry,
266
+ createRegistry,
267
+ type CombinedRegistry,
268
+ RuleBasedPlanner,
269
+ type RuleBasedPlannerConfig,
270
+ } from "./planning";
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Planning module for the workflow engine.
3
+ * Provides recipes, plans, and planners for dynamic workflow orchestration.
4
+ */
5
+
6
+ // Types
7
+ export type {
8
+ // Condition types
9
+ ConditionOperator,
10
+ RecipeCondition,
11
+
12
+ // Recipe types
13
+ RecipeDefaults,
14
+ StepHandlerRef,
15
+ RecipeStep,
16
+ Recipe,
17
+
18
+ // Plan types
19
+ PlanModificationType,
20
+ PlanModification,
21
+ PlannedStep,
22
+ ChildWorkflowPlan,
23
+ ResourceEstimate,
24
+ Plan,
25
+
26
+ // Planning context types
27
+ PlanningPriority,
28
+ PlanningConstraints,
29
+ PlanningHints,
30
+ PlanningContext,
31
+
32
+ // Planner types
33
+ RecipeSelectionResult,
34
+ PlanValidationResult,
35
+ Planner,
36
+
37
+ // Registry types
38
+ RegisteredStepHandler,
39
+ StepHandlerRegistry,
40
+ RecipeQueryOptions,
41
+ RecipeRegistry,
42
+ } from "./types";
43
+
44
+ // Implementations
45
+ export {
46
+ MemoryStepHandlerRegistry,
47
+ MemoryRecipeRegistry,
48
+ createRegistry,
49
+ type CombinedRegistry,
50
+ } from "./registry";
51
+
52
+ export { RuleBasedPlanner, type RuleBasedPlannerConfig } from "./planner";