@jagreehal/workflow 1.4.0 → 1.6.0
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.
- package/README.md +664 -332
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +179 -1
- package/dist/core.d.ts +179 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +9 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3266 -2
- package/dist/index.d.ts +3266 -2
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/visualize.cjs +6 -6
- package/dist/visualize.cjs.map +1 -1
- package/dist/visualize.js +6 -6
- package/dist/visualize.js.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.js +1 -1
- package/dist/workflow.js.map +1 -1
- package/docs/advanced.md +895 -0
- package/docs/api.md +257 -0
- package/docs/coming-from-neverthrow.md +920 -0
- package/docs/visualize-examples.md +330 -0
- package/package.json +7 -6
package/docs/api.md
CHANGED
|
@@ -193,3 +193,260 @@ ExtractCause<Result> // Extract cause type from Result
|
|
|
193
193
|
```typescript
|
|
194
194
|
UnwrapError<E, C> // Error thrown by unwrap()
|
|
195
195
|
```
|
|
196
|
+
|
|
197
|
+
## Circuit Breaker
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
createCircuitBreaker(name, config) // Create circuit breaker instance
|
|
201
|
+
isCircuitOpenError(error) // Check if error is circuit open
|
|
202
|
+
circuitBreakerPresets.critical // Preset configurations
|
|
203
|
+
circuitBreakerPresets.lenient
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Types
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
CircuitState // 'CLOSED' | 'OPEN' | 'HALF_OPEN'
|
|
210
|
+
CircuitBreakerConfig // Configuration options
|
|
211
|
+
CircuitBreakerStats // Runtime statistics
|
|
212
|
+
CircuitBreaker // Circuit breaker interface
|
|
213
|
+
CircuitOpenError // Error when circuit is open
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Saga / Compensation
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
createSagaWorkflow(deps, options) // Create saga with auto-inferred errors
|
|
220
|
+
runSaga(fn, options) // Low-level saga execution
|
|
221
|
+
isSagaCompensationError(error) // Check for compensation failure
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Types
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
SagaContext<E> // Context with step() and tryStep()
|
|
228
|
+
SagaStepOptions<T> // Step options with compensate
|
|
229
|
+
SagaCompensationError // Error with compensation details
|
|
230
|
+
SagaEvent // Saga lifecycle events
|
|
231
|
+
SagaResult<T, E> // Result type for sagas
|
|
232
|
+
CompensationAction<T> // Compensation function type
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Rate Limiting
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
createRateLimiter(name, config) // Token bucket rate limiter
|
|
239
|
+
createConcurrencyLimiter(name, cfg) // Concurrent execution limiter
|
|
240
|
+
createCombinedLimiter(name, config) // Rate + concurrency combined
|
|
241
|
+
rateLimiterPresets.api // Preset configurations
|
|
242
|
+
isRateLimitExceededError(error) // Check if rate limited
|
|
243
|
+
isQueueFullError(error) // Check if queue full
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Types
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
RateLimiterConfig // Rate limiter configuration
|
|
250
|
+
ConcurrencyLimiterConfig // Concurrency limiter config
|
|
251
|
+
RateLimiter // Rate limiter interface
|
|
252
|
+
ConcurrencyLimiter // Concurrency limiter interface
|
|
253
|
+
RateLimitExceededError // Error when rate exceeded
|
|
254
|
+
QueueFullError // Error when queue full
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Versioning
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
migrateState(state, target, migrations) // Apply migrations
|
|
261
|
+
createVersionedStateLoader(config) // Create loader with migrations
|
|
262
|
+
createVersionedState(state, version) // Wrap state with version
|
|
263
|
+
parseVersionedState(json) // Parse from JSON
|
|
264
|
+
stringifyVersionedState(state) // Serialize to JSON
|
|
265
|
+
createKeyRenameMigration(renames) // Migration helper
|
|
266
|
+
createKeyRemoveMigration(keys) // Migration helper
|
|
267
|
+
createValueTransformMigration(transforms) // Migration helper
|
|
268
|
+
composeMigrations(migrations) // Combine migrations
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Types
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
Version // Version number type
|
|
275
|
+
VersionedState // State with version
|
|
276
|
+
MigrationFn // Migration function type
|
|
277
|
+
Migrations // Migration map type
|
|
278
|
+
MigrationError // Error during migration
|
|
279
|
+
VersionIncompatibleError // Version mismatch error
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## Conditional Execution
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
when(condition, operation, opts, ctx) // Run if true
|
|
286
|
+
unless(condition, operation, opts, ctx) // Run if false
|
|
287
|
+
whenOr(cond, op, default, opts, ctx) // Run if true, else default
|
|
288
|
+
unlessOr(cond, op, default, opts, ctx) // Run if false, else default
|
|
289
|
+
createConditionalHelpers(ctx) // Factory for bound helpers
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Types
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
ConditionalOptions // { name?, key?, reason? }
|
|
296
|
+
ConditionalContext // { workflowId, onEvent? }
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Webhook / Event Triggers
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
createWebhookHandler(workflow, fn, config) // Create HTTP handler
|
|
303
|
+
createSimpleHandler(config) // Simple endpoint handler
|
|
304
|
+
createEventHandler(workflow, fn, config) // Queue event handler
|
|
305
|
+
createResultMapper(mappings, options) // Map errors to HTTP codes
|
|
306
|
+
createExpressHandler(handler) // Express middleware
|
|
307
|
+
toWebhookRequest(req) // Convert Express request
|
|
308
|
+
sendWebhookResponse(res, response) // Send Express response
|
|
309
|
+
validationError(message, field, details) // Create validation error
|
|
310
|
+
requireFields(fields) // Field validator
|
|
311
|
+
composeValidators(...validators) // Combine validators
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Types
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
WebhookRequest<Body> // Generic HTTP request
|
|
318
|
+
WebhookResponse<T> // Generic HTTP response
|
|
319
|
+
WebhookHandler<TBody> // Handler function type
|
|
320
|
+
ValidationError // Validation error type
|
|
321
|
+
EventMessage<T> // Queue message type
|
|
322
|
+
EventProcessingResult // Processing result type
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Policy Middleware
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
mergePolicies(...policies) // Combine policies
|
|
329
|
+
createPolicyApplier(...policies) // Create policy applier
|
|
330
|
+
withPolicy(policy, options) // Apply single policy
|
|
331
|
+
withPolicies(policies, name) // Apply multiple policies
|
|
332
|
+
createPolicyRegistry() // Create policy registry
|
|
333
|
+
stepOptions() // Fluent builder
|
|
334
|
+
retryPolicies.standard // Retry presets
|
|
335
|
+
timeoutPolicies.api // Timeout presets
|
|
336
|
+
servicePolicies.httpApi // Combined presets
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Types
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
Policy // Policy type
|
|
343
|
+
PolicyFactory // Factory type
|
|
344
|
+
NamedPolicy // Named policy type
|
|
345
|
+
PolicyRegistry // Registry interface
|
|
346
|
+
StepOptionsBuilder // Fluent builder type
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Persistence
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
createMemoryCache(options) // In-memory cache
|
|
353
|
+
createFileCache(options) // File-based cache
|
|
354
|
+
createKVCache(options) // Key-value store cache
|
|
355
|
+
createStatePersistence(store, prefix) // State persistence
|
|
356
|
+
createHydratingCache(memory, persist, id) // Hydrating cache
|
|
357
|
+
serializeState(state) // Serialize resume state
|
|
358
|
+
deserializeState(data) // Deserialize resume state
|
|
359
|
+
stringifyState(state, meta) // JSON stringify
|
|
360
|
+
parseState(json) // JSON parse
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Types
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
SerializedState // JSON-safe state
|
|
367
|
+
MemoryCacheOptions // Memory cache config
|
|
368
|
+
FileCacheOptions // File cache config
|
|
369
|
+
KeyValueStore // KV store interface
|
|
370
|
+
StatePersistence // Persistence interface
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Devtools
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
createDevtools(options) // Create devtools instance
|
|
377
|
+
renderDiff(diff) // Render run diff
|
|
378
|
+
quickVisualize(events) // Quick visualization
|
|
379
|
+
createConsoleLogger(options) // Console event logger
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Types
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
WorkflowRun // Captured run data
|
|
386
|
+
RunDiff // Diff between runs
|
|
387
|
+
StepDiff // Step-level diff
|
|
388
|
+
TimelineEntry // Timeline data
|
|
389
|
+
Devtools // Devtools interface
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## HITL Orchestration
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
createHITLOrchestrator(options) // Create orchestrator
|
|
396
|
+
createMemoryApprovalStore() // In-memory approval store
|
|
397
|
+
createMemoryWorkflowStateStore() // In-memory state store
|
|
398
|
+
createApprovalWebhookHandler(store) // Webhook for approvals
|
|
399
|
+
createApprovalChecker(store, key) // Approval status checker
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Types
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
HITLOrchestrator // Orchestrator interface
|
|
406
|
+
ApprovalStore // Approval storage interface
|
|
407
|
+
WorkflowStateStore // State storage interface
|
|
408
|
+
HITLExecutionResult // Execution result type
|
|
409
|
+
ApprovalStatus // Approval status type
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Testing
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
createWorkflowHarness(deps, options) // Create test harness
|
|
416
|
+
createMockFn<T, E>() // Create mock function
|
|
417
|
+
createTestClock(startTime) // Deterministic clock
|
|
418
|
+
createSnapshot(invocations, result) // Create snapshot
|
|
419
|
+
compareSnapshots(snapshot1, snapshot2) // Compare snapshots
|
|
420
|
+
okOutcome(value) // Helper for ok outcome
|
|
421
|
+
errOutcome(error) // Helper for err outcome
|
|
422
|
+
throwOutcome(error) // Helper for throw outcome
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### Types
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
WorkflowHarness<E, Deps> // Test harness interface
|
|
429
|
+
MockStep<E> // Mock step function
|
|
430
|
+
MockFunction<T, E> // Mock function interface
|
|
431
|
+
ScriptedOutcome<T, E> // Scripted step outcome
|
|
432
|
+
StepInvocation // Invocation record
|
|
433
|
+
AssertionResult // Assertion result
|
|
434
|
+
WorkflowSnapshot // Snapshot for comparison
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
## OpenTelemetry (Autotel)
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
createAutotelAdapter(config) // Create metrics adapter
|
|
441
|
+
createAutotelEventHandler(options) // Event handler for debug
|
|
442
|
+
withAutotelTracing(trace, options) // Wrap with tracing
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Types
|
|
446
|
+
|
|
447
|
+
```typescript
|
|
448
|
+
AutotelAdapterConfig // Adapter configuration
|
|
449
|
+
AutotelMetrics // Collected metrics
|
|
450
|
+
AutotelAdapter // Adapter interface
|
|
451
|
+
AutotelTraceFn // Trace function type
|
|
452
|
+
```
|