@emmvish/stable-request 2.2.0 → 2.3.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.
Files changed (84) hide show
  1. package/README.md +267 -0
  2. package/dist/constants/index.d.ts.map +1 -1
  3. package/dist/constants/index.js +1 -0
  4. package/dist/constants/index.js.map +1 -1
  5. package/dist/core/stable-api-gateway.js +17 -1
  6. package/dist/core/stable-api-gateway.js.map +1 -1
  7. package/dist/core/stable-function.d.ts +9 -1
  8. package/dist/core/stable-function.d.ts.map +1 -1
  9. package/dist/core/stable-function.js +185 -169
  10. package/dist/core/stable-function.js.map +1 -1
  11. package/dist/core/stable-request.js.map +1 -1
  12. package/dist/core/stable-workflow-graph.d.ts +1 -1
  13. package/dist/core/stable-workflow-graph.d.ts.map +1 -1
  14. package/dist/core/stable-workflow.d.ts +1 -1
  15. package/dist/core/stable-workflow.d.ts.map +1 -1
  16. package/dist/core/stable-workflow.js +20 -3
  17. package/dist/core/stable-workflow.js.map +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/types/index.d.ts +153 -146
  23. package/dist/types/index.d.ts.map +1 -1
  24. package/dist/utilities/execute-branch-workflow.d.ts +1 -1
  25. package/dist/utilities/execute-branch-workflow.d.ts.map +1 -1
  26. package/dist/utilities/execute-branch-workflow.js +138 -3
  27. package/dist/utilities/execute-branch-workflow.js.map +1 -1
  28. package/dist/utilities/execute-concurrently.d.ts +1 -1
  29. package/dist/utilities/execute-concurrently.d.ts.map +1 -1
  30. package/dist/utilities/execute-concurrently.js +128 -6
  31. package/dist/utilities/execute-concurrently.js.map +1 -1
  32. package/dist/utilities/execute-gateway-item.d.ts +3 -3
  33. package/dist/utilities/execute-gateway-item.d.ts.map +1 -1
  34. package/dist/utilities/execute-gateway-item.js.map +1 -1
  35. package/dist/utilities/execute-non-linear-workflow.d.ts +1 -1
  36. package/dist/utilities/execute-non-linear-workflow.d.ts.map +1 -1
  37. package/dist/utilities/execute-non-linear-workflow.js +14 -4
  38. package/dist/utilities/execute-non-linear-workflow.js.map +1 -1
  39. package/dist/utilities/execute-phase.d.ts +1 -1
  40. package/dist/utilities/execute-phase.d.ts.map +1 -1
  41. package/dist/utilities/execute-phase.js +17 -0
  42. package/dist/utilities/execute-phase.js.map +1 -1
  43. package/dist/utilities/execute-sequentially.d.ts +1 -1
  44. package/dist/utilities/execute-sequentially.d.ts.map +1 -1
  45. package/dist/utilities/execute-sequentially.js +4 -7
  46. package/dist/utilities/execute-sequentially.js.map +1 -1
  47. package/dist/utilities/execute-with-timeout.d.ts +6 -0
  48. package/dist/utilities/execute-with-timeout.d.ts.map +1 -0
  49. package/dist/utilities/execute-with-timeout.js +28 -0
  50. package/dist/utilities/execute-with-timeout.js.map +1 -0
  51. package/dist/utilities/execute-workflow-graph.d.ts +1 -1
  52. package/dist/utilities/execute-workflow-graph.d.ts.map +1 -1
  53. package/dist/utilities/execute-workflow-graph.js +96 -2
  54. package/dist/utilities/execute-workflow-graph.js.map +1 -1
  55. package/dist/utilities/extract-common-request-config-options.d.ts +1 -1
  56. package/dist/utilities/extract-common-request-config-options.d.ts.map +1 -1
  57. package/dist/utilities/extract-common-request-config-options.js +3 -2
  58. package/dist/utilities/extract-common-request-config-options.js.map +1 -1
  59. package/dist/utilities/index.d.ts +1 -0
  60. package/dist/utilities/index.d.ts.map +1 -1
  61. package/dist/utilities/index.js +1 -0
  62. package/dist/utilities/index.js.map +1 -1
  63. package/dist/utilities/metrics-aggregator.d.ts +5 -41
  64. package/dist/utilities/metrics-aggregator.d.ts.map +1 -1
  65. package/dist/utilities/metrics-aggregator.js +1 -42
  66. package/dist/utilities/metrics-aggregator.js.map +1 -1
  67. package/dist/utilities/prepare-api-function-options.d.ts +1 -1
  68. package/dist/utilities/prepare-api-function-options.d.ts.map +1 -1
  69. package/dist/utilities/prepare-api-function-options.js +1 -0
  70. package/dist/utilities/prepare-api-function-options.js.map +1 -1
  71. package/dist/utilities/prepare-api-request-data.d.ts +1 -1
  72. package/dist/utilities/prepare-api-request-data.d.ts.map +1 -1
  73. package/dist/utilities/prepare-api-request-data.js.map +1 -1
  74. package/dist/utilities/prepare-api-request-options.d.ts +1 -1
  75. package/dist/utilities/prepare-api-request-options.d.ts.map +1 -1
  76. package/dist/utilities/prepare-api-request-options.js +9 -6
  77. package/dist/utilities/prepare-api-request-options.js.map +1 -1
  78. package/dist/utilities/validate-workflow-graph.d.ts +5 -5
  79. package/dist/utilities/validate-workflow-graph.d.ts.map +1 -1
  80. package/dist/utilities/validate-workflow-graph.js.map +1 -1
  81. package/dist/utilities/workflow-graph-builder.d.ts +8 -8
  82. package/dist/utilities/workflow-graph-builder.d.ts.map +1 -1
  83. package/dist/utilities/workflow-graph-builder.js.map +1 -1
  84. package/package.json +1 -1
@@ -130,27 +130,30 @@ export interface API_GATEWAY_OPTIONS<RequestDataType = any, ResponseDataType = a
130
130
  commonPreExecution?: RequestPreExecutionOptions;
131
131
  commonCache?: CacheConfig;
132
132
  commonStatePersistence?: StatePersistenceConfig;
133
+ commonExecutionTimeout?: number;
133
134
  commonFunctionHookParams?: FunctionHookParams;
134
- commonFunctionResponseAnalyzer?: <TArgs extends any[], TReturn>(options: FunctionResponseAnalysisHookOptions<TArgs, TReturn>) => boolean | Promise<boolean>;
135
+ commonFunctionResponseAnalyzer?: (options: FunctionResponseAnalysisHookOptions<FunctionArgsType, FunctionReturnType>) => boolean | Promise<boolean>;
135
136
  commonReturnResult?: boolean;
136
- commonFinalFunctionErrorAnalyzer?: <TArgs extends any[]>(options: FinalFunctionErrorAnalysisHookOptions<TArgs>) => boolean | Promise<boolean>;
137
- commonHandleFunctionErrors?: <TArgs extends any[]>(options: HandleFunctionErrorHookOptions<TArgs>) => any | Promise<any>;
138
- commonHandleSuccessfulFunctionAttemptData?: <TArgs extends any[], TReturn>(options: HandleSuccessfulFunctionAttemptDataHookOptions<TArgs, TReturn>) => any | Promise<any>;
139
- commonFunctionPreExecution?: <TArgs extends any[], TReturn>(options: FunctionPreExecutionOptions<TArgs, TReturn>) => any;
140
- commonFunctionCache?: <TArgs extends any[], TReturn>(config: FunctionCacheConfig<TArgs, TReturn>) => any;
137
+ commonFinalFunctionErrorAnalyzer?: (options: FinalFunctionErrorAnalysisHookOptions<FunctionArgsType>) => boolean | Promise<boolean>;
138
+ commonHandleFunctionErrors?: (options: HandleFunctionErrorHookOptions<FunctionArgsType>) => any | Promise<any>;
139
+ commonHandleSuccessfulFunctionAttemptData?: (options: HandleSuccessfulFunctionAttemptDataHookOptions<FunctionArgsType, FunctionReturnType>) => any | Promise<any>;
140
+ commonFunctionPreExecution?: FunctionPreExecutionOptions<FunctionArgsType, FunctionReturnType>;
141
+ commonFunctionCache?: FunctionCacheConfig<FunctionArgsType, FunctionReturnType>;
141
142
  concurrentExecution?: boolean;
142
- requestGroups?: RequestGroup<RequestDataType, ResponseDataType>[];
143
+ requestGroups?: RequestGroup<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
143
144
  stopOnFirstError?: boolean;
144
145
  sharedBuffer?: Record<string, any>;
145
146
  maxConcurrentRequests?: number;
146
147
  rateLimit?: RateLimitConfig;
147
- circuitBreaker?: CircuitBreakerConfig;
148
+ circuitBreaker?: CircuitBreakerConfig | CircuitBreaker;
148
149
  executionContext?: Partial<ExecutionContext>;
149
150
  metricsGuardrails?: MetricsGuardrails;
151
+ enableRacing?: boolean;
152
+ maxTimeout?: number;
150
153
  }
151
- export interface RequestGroup<RequestDataType = any, ResponseDataType = any> {
154
+ export interface RequestGroup<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
152
155
  id: string;
153
- commonConfig?: Omit<API_GATEWAY_OPTIONS<RequestDataType, ResponseDataType>, "concurrentExecution" | "stopOnFirstError" | "requestGroups" | "maxConcurrentRequests" | "rateLimit" | "circuitBreaker">;
156
+ commonConfig?: Omit<API_GATEWAY_OPTIONS<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, "concurrentExecution" | "stopOnFirstError" | "requestGroups" | "maxConcurrentRequests" | "rateLimit" | "circuitBreaker" | "maxTimeout" | "executionContext" | "enableRacing" | "metricsGuardrails">;
154
157
  }
155
158
  export type API_GATEWAY_REQUEST_OPTIONS_TYPE<RequestDataType, ResponseDataType> = Omit<STABLE_REQUEST<RequestDataType, ResponseDataType>, 'reqData'> & {
156
159
  reqData?: Partial<STABLE_REQUEST<RequestDataType, ResponseDataType>['reqData']>;
@@ -160,32 +163,32 @@ export interface API_GATEWAY_REQUEST<RequestDataType = any, ResponseDataType = a
160
163
  groupId?: string;
161
164
  requestOptions: API_GATEWAY_REQUEST_OPTIONS_TYPE<RequestDataType, ResponseDataType>;
162
165
  }
163
- export type API_GATEWAY_FUNCTION_OPTIONS_TYPE<TArgs extends any[], TReturn> = Omit<STABLE_FUNCTION<TArgs, TReturn>, 'fn' | 'args'> & {
164
- fn?: STABLE_FUNCTION<TArgs, TReturn>['fn'];
165
- args?: TArgs;
166
+ export type API_GATEWAY_FUNCTION_OPTIONS_TYPE<FunctionArgsType extends any[], FunctionReturnType> = Omit<STABLE_FUNCTION<FunctionArgsType, FunctionReturnType>, 'fn' | 'args'> & {
167
+ fn?: STABLE_FUNCTION<FunctionArgsType, FunctionReturnType>['fn'];
168
+ args?: FunctionArgsType;
166
169
  };
167
- export interface API_GATEWAY_FUNCTION<TArgs extends any[] = any[], TReturn = any> {
170
+ export interface API_GATEWAY_FUNCTION<FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
168
171
  id: string;
169
172
  groupId?: string;
170
- functionOptions: API_GATEWAY_FUNCTION_OPTIONS_TYPE<TArgs, TReturn>;
173
+ functionOptions: API_GATEWAY_FUNCTION_OPTIONS_TYPE<FunctionArgsType, FunctionReturnType>;
171
174
  }
172
175
  export type RequestOrFunctionType = RequestOrFunction.REQUEST | RequestOrFunction.FUNCTION;
173
- export type API_GATEWAY_ITEM<RequestDataType = any, ResponseDataType = any, TArgs extends any[] = any[], TReturn = any> = {
176
+ export type API_GATEWAY_ITEM<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> = {
174
177
  type: RequestOrFunction.REQUEST;
175
178
  request: API_GATEWAY_REQUEST<RequestDataType, ResponseDataType>;
176
179
  } | {
177
180
  type: RequestOrFunction.FUNCTION;
178
- function: API_GATEWAY_FUNCTION<TArgs, TReturn>;
181
+ function: API_GATEWAY_FUNCTION<FunctionArgsType, FunctionReturnType>;
179
182
  };
180
- export interface API_GATEWAY_RESPONSE<ResponseDataType = any> {
183
+ export interface API_GATEWAY_RESPONSE<ResponseDataType = any, FunctionReturnType = any> {
181
184
  requestId: string;
182
185
  groupId?: string;
183
186
  success: boolean;
184
- data?: ResponseDataType;
187
+ data?: ResponseDataType | FunctionReturnType | boolean;
185
188
  error?: string;
186
189
  type?: RequestOrFunctionType;
187
190
  }
188
- export interface API_GATEWAY_RESULT<ResponseDataType = any> extends Array<API_GATEWAY_RESPONSE<ResponseDataType>> {
191
+ export interface API_GATEWAY_RESULT<ResponseDataType = any, FunctionReturnType = any> extends Array<API_GATEWAY_RESPONSE<ResponseDataType, FunctionReturnType>> {
189
192
  metrics?: {
190
193
  totalRequests: number;
191
194
  successfulRequests: number;
@@ -236,13 +239,13 @@ export interface ReqFnResponse<ResponseDataType = any> {
236
239
  };
237
240
  fromCache?: boolean;
238
241
  }
239
- export interface FnExecResponse<TReturn = any> {
242
+ export interface FnExecResponse<FunctionReturnType = any> {
240
243
  ok: boolean;
241
244
  isRetryable: boolean;
242
245
  timestamp: string;
243
246
  executionTime: number;
244
247
  error?: string;
245
- data?: TReturn | {
248
+ data?: FunctionReturnType | {
246
249
  trialMode: TRIAL_MODE_OPTIONS;
247
250
  };
248
251
  fromCache?: boolean;
@@ -304,43 +307,43 @@ export interface FunctionHookParams {
304
307
  handleErrorsParams?: any;
305
308
  finalErrorAnalyzerParams?: any;
306
309
  }
307
- interface FunctionObservabilityHooksOptions<TArgs extends any[] = any[]> {
308
- fn: (...args: TArgs) => any;
309
- args: TArgs;
310
+ interface FunctionObservabilityHooksOptions<FunctionArgsType extends any[] = any[]> {
311
+ fn: (...args: FunctionArgsType) => any;
312
+ args: FunctionArgsType;
310
313
  params?: any;
311
314
  maxSerializableChars?: number;
312
315
  preExecutionResult?: any;
313
316
  commonBuffer?: Record<string, any>;
314
317
  executionContext?: ExecutionContext;
315
318
  }
316
- interface FunctionAnalysisHookOptions<TArgs extends any[] = any[]> extends Omit<FunctionObservabilityHooksOptions<TArgs>, "maxSerializableChars"> {
319
+ interface FunctionAnalysisHookOptions<FunctionArgsType extends any[] = any[]> extends Omit<FunctionObservabilityHooksOptions<FunctionArgsType>, "maxSerializableChars"> {
317
320
  trialMode?: TRIAL_MODE_OPTIONS;
318
321
  params?: any;
319
322
  preExecutionResult?: any;
320
323
  executionContext?: ExecutionContext;
321
324
  commonBuffer?: Record<string, any>;
322
325
  }
323
- export interface FunctionResponseAnalysisHookOptions<TArgs extends any[] = any[], TReturn = any> extends FunctionAnalysisHookOptions<TArgs> {
324
- data: TReturn;
326
+ export interface FunctionResponseAnalysisHookOptions<FunctionArgsType extends any[] = any[], FunctionReturnType = any> extends FunctionAnalysisHookOptions<FunctionArgsType> {
327
+ data: FunctionReturnType;
325
328
  }
326
- export interface FinalFunctionErrorAnalysisHookOptions<TArgs extends any[] = any[]> extends FunctionAnalysisHookOptions<TArgs> {
329
+ export interface FinalFunctionErrorAnalysisHookOptions<FunctionArgsType extends any[] = any[]> extends FunctionAnalysisHookOptions<FunctionArgsType> {
327
330
  error: any;
328
331
  }
329
- export interface HandleFunctionErrorHookOptions<TArgs extends any[] = any[]> extends FunctionObservabilityHooksOptions<TArgs> {
332
+ export interface HandleFunctionErrorHookOptions<FunctionArgsType extends any[] = any[]> extends FunctionObservabilityHooksOptions<FunctionArgsType> {
330
333
  errorLog: FUNCTION_ERROR_LOG;
331
334
  }
332
- export interface HandleSuccessfulFunctionAttemptDataHookOptions<TArgs extends any[] = any[], TReturn = any> extends FunctionObservabilityHooksOptions<TArgs> {
333
- successfulAttemptData: SUCCESSFUL_FUNCTION_ATTEMPT_DATA<TReturn>;
335
+ export interface HandleSuccessfulFunctionAttemptDataHookOptions<FunctionArgsType extends any[] = any[], FunctionReturnType = any> extends FunctionObservabilityHooksOptions<FunctionArgsType> {
336
+ successfulAttemptData: SUCCESSFUL_FUNCTION_ATTEMPT_DATA<FunctionReturnType>;
334
337
  }
335
338
  export interface PreExecutionHookOptions<RequestDataType = any, ResponseDataType = any> {
336
339
  inputParams?: any;
337
340
  commonBuffer?: Record<string, any>;
338
341
  stableRequestOptions: STABLE_REQUEST<RequestDataType, ResponseDataType>;
339
342
  }
340
- export interface FunctionPreExecutionHookOptions<TArgs extends any[] = any[], TReturn = any> {
343
+ export interface FunctionPreExecutionHookOptions<FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
341
344
  inputParams?: any;
342
345
  commonBuffer?: Record<string, any>;
343
- stableFunctionOptions: STABLE_FUNCTION<TArgs, TReturn>;
346
+ stableFunctionOptions: STABLE_FUNCTION<FunctionArgsType, FunctionReturnType>;
344
347
  }
345
348
  interface WorkflowPreExecutionHookOptions {
346
349
  params?: any;
@@ -348,15 +351,15 @@ interface WorkflowPreExecutionHookOptions {
348
351
  workflowId: string;
349
352
  branchId?: string;
350
353
  }
351
- export interface PrePhaseExecutionHookOptions<RequestDataType = any, ResponseDataType = any> extends WorkflowPreExecutionHookOptions {
354
+ export interface PrePhaseExecutionHookOptions<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> extends WorkflowPreExecutionHookOptions {
352
355
  phaseId: string;
353
356
  phaseIndex: number;
354
- phase: STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType>;
357
+ phase: STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
355
358
  }
356
- export interface PreBranchExecutionHookOptions<RequestDataType = any, ResponseDataType = any> extends Omit<WorkflowPreExecutionHookOptions, 'branchId'> {
359
+ export interface PreBranchExecutionHookOptions<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> extends Omit<WorkflowPreExecutionHookOptions, 'branchId'> {
357
360
  branchId: string;
358
361
  branchIndex: number;
359
- branch: STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType>;
362
+ branch: STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
360
363
  }
361
364
  export interface RequestPreExecutionOptions<RequestDataType = any, ResponseDataType = any> {
362
365
  preExecutionHook: (options: PreExecutionHookOptions<RequestDataType, ResponseDataType>) => any | Promise<any>;
@@ -364,8 +367,8 @@ export interface RequestPreExecutionOptions<RequestDataType = any, ResponseDataT
364
367
  applyPreExecutionConfigOverride?: boolean;
365
368
  continueOnPreExecutionHookFailure?: boolean;
366
369
  }
367
- export interface FunctionPreExecutionOptions<TArgs extends any[] = any[], TReturn = any> {
368
- preExecutionHook: (options: FunctionPreExecutionHookOptions<TArgs, TReturn>) => any | Promise<any>;
370
+ export interface FunctionPreExecutionOptions<FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
371
+ preExecutionHook: (options: FunctionPreExecutionHookOptions<FunctionArgsType, FunctionReturnType>) => any | Promise<any>;
369
372
  preExecutionHookParams?: any;
370
373
  applyPreExecutionConfigOverride?: boolean;
371
374
  continueOnPreExecutionHookFailure?: boolean;
@@ -407,10 +410,10 @@ export interface STABLE_REQUEST<RequestDataType = any, ResponseDataType = any> {
407
410
  statePersistence?: StatePersistenceConfig;
408
411
  metricsGuardrails?: MetricsGuardrails;
409
412
  }
410
- export interface STABLE_FUNCTION<TArgs extends any[] = any[], TReturn = any> {
411
- fn: (...args: TArgs) => TReturn | Promise<TReturn>;
412
- args: TArgs;
413
- responseAnalyzer?: (options: FunctionResponseAnalysisHookOptions<TArgs, TReturn>) => boolean | Promise<boolean>;
413
+ export interface STABLE_FUNCTION<FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
414
+ fn: (...args: FunctionArgsType) => FunctionReturnType | Promise<FunctionReturnType>;
415
+ args: FunctionArgsType;
416
+ responseAnalyzer?: (options: FunctionResponseAnalysisHookOptions<FunctionArgsType, FunctionReturnType>) => boolean | Promise<boolean>;
414
417
  returnResult?: boolean;
415
418
  attempts?: number;
416
419
  performAllAttempts?: boolean;
@@ -419,26 +422,27 @@ export interface STABLE_FUNCTION<TArgs extends any[] = any[], TReturn = any> {
419
422
  retryStrategy?: RETRY_STRATEGY_TYPES;
420
423
  jitter?: number;
421
424
  logAllErrors?: boolean;
422
- handleErrors?: (options: HandleFunctionErrorHookOptions<TArgs>) => any | Promise<any>;
425
+ handleErrors?: (options: HandleFunctionErrorHookOptions<FunctionArgsType>) => any | Promise<any>;
423
426
  logAllSuccessfulAttempts?: boolean;
424
- handleSuccessfulAttemptData?: (options: HandleSuccessfulFunctionAttemptDataHookOptions<TArgs, TReturn>) => any | Promise<any>;
427
+ handleSuccessfulAttemptData?: (options: HandleSuccessfulFunctionAttemptDataHookOptions<FunctionArgsType, FunctionReturnType>) => any | Promise<any>;
425
428
  maxSerializableChars?: number;
426
- finalErrorAnalyzer?: (options: FinalFunctionErrorAnalysisHookOptions<TArgs>) => boolean | Promise<boolean>;
429
+ finalErrorAnalyzer?: (options: FinalFunctionErrorAnalysisHookOptions<FunctionArgsType>) => boolean | Promise<boolean>;
427
430
  trialMode?: TRIAL_MODE_OPTIONS;
428
431
  hookParams?: FunctionHookParams;
429
- preExecution?: FunctionPreExecutionOptions<TArgs, TReturn>;
432
+ preExecution?: FunctionPreExecutionOptions<FunctionArgsType, FunctionReturnType>;
430
433
  commonBuffer?: Record<string, any>;
431
- cache?: FunctionCacheConfig<TArgs, TReturn>;
434
+ cache?: FunctionCacheConfig<FunctionArgsType, FunctionReturnType>;
432
435
  executionContext?: ExecutionContext;
433
436
  circuitBreaker?: CircuitBreakerConfig | CircuitBreaker;
434
437
  statePersistence?: StatePersistenceConfig;
435
438
  rateLimit?: RateLimitConfig;
436
439
  maxConcurrentRequests?: number;
437
440
  metricsGuardrails?: MetricsGuardrails;
441
+ executionTimeout?: number;
438
442
  }
439
443
  export interface STABLE_REQUEST_RESULT<ResponseDataType = any> {
440
444
  success: boolean;
441
- data?: ResponseDataType;
445
+ data?: ResponseDataType | boolean;
442
446
  error?: string;
443
447
  errorLogs?: ERROR_LOG[];
444
448
  successfulAttempts?: SUCCESSFUL_ATTEMPT_DATA<ResponseDataType>[];
@@ -455,12 +459,12 @@ export interface STABLE_REQUEST_RESULT<ResponseDataType = any> {
455
459
  validation?: MetricsValidationResult;
456
460
  };
457
461
  }
458
- export interface STABLE_FUNCTION_RESULT<TReturn = any> {
462
+ export interface STABLE_FUNCTION_RESULT<FunctionReturnType = any, ReturnResult extends boolean = boolean> {
459
463
  success: boolean;
460
- data?: TReturn;
464
+ data?: ReturnResult extends true ? FunctionReturnType : boolean;
461
465
  error?: string;
462
466
  errorLogs?: FUNCTION_ERROR_LOG[];
463
- successfulAttempts?: SUCCESSFUL_FUNCTION_ATTEMPT_DATA<TReturn>[];
467
+ successfulAttempts?: SUCCESSFUL_FUNCTION_ATTEMPT_DATA<FunctionReturnType>[];
464
468
  metrics?: {
465
469
  totalAttempts: number;
466
470
  successfulAttempts: number;
@@ -483,11 +487,11 @@ export interface SUCCESSFUL_ATTEMPT_DATA<ResponseDataType = any> {
483
487
  data: ResponseDataType;
484
488
  statusCode: number;
485
489
  }
486
- export interface SUCCESSFUL_FUNCTION_ATTEMPT_DATA<TReturn = any> {
490
+ export interface SUCCESSFUL_FUNCTION_ATTEMPT_DATA<FunctionReturnType = any> {
487
491
  attempt: string;
488
492
  timestamp: string;
489
493
  executionTime: number;
490
- data: TReturn;
494
+ data: FunctionReturnType;
491
495
  }
492
496
  export interface FUNCTION_ERROR_LOG {
493
497
  timestamp: string;
@@ -505,8 +509,8 @@ export type VALID_REQUEST_PROTOCOL_TYPES = VALID_REQUEST_PROTOCOLS.HTTP | VALID_
505
509
  export interface STABLE_WORKFLOW_PHASE<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
506
510
  id?: string;
507
511
  requests?: API_GATEWAY_REQUEST<RequestDataType, ResponseDataType>[];
508
- functions?: API_GATEWAY_FUNCTION<any[], any>[];
509
- items?: API_GATEWAY_ITEM<RequestDataType, ResponseDataType, any[], any>[];
512
+ functions?: API_GATEWAY_FUNCTION<FunctionArgsType, FunctionReturnType>[];
513
+ items?: API_GATEWAY_ITEM<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
510
514
  concurrentExecution?: boolean;
511
515
  stopOnFirstError?: boolean;
512
516
  markConcurrentPhase?: boolean;
@@ -516,35 +520,36 @@ export interface STABLE_WORKFLOW_PHASE<RequestDataType = any, ResponseDataType =
516
520
  maxReplayCount?: number;
517
521
  allowReplay?: boolean;
518
522
  allowSkip?: boolean;
519
- phaseDecisionHook?: (options: PhaseDecisionHookOptions<ResponseDataType>) => PhaseExecutionDecision | Promise<PhaseExecutionDecision>;
520
- commonConfig?: Omit<API_GATEWAY_OPTIONS<RequestDataType, ResponseDataType>, 'concurrentExecution' | 'stopOnFirstError' | 'requestGroups' | "maxConcurrentRequests" | "rateLimit" | "circuitBreaker">;
523
+ phaseDecisionHook?: (options: PhaseDecisionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => PhaseExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType> | Promise<PhaseExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
524
+ commonConfig?: Omit<API_GATEWAY_OPTIONS<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, 'concurrentExecution' | 'stopOnFirstError' | 'requestGroups' | "maxConcurrentRequests" | "rateLimit" | "circuitBreaker" | "maxTimeout" | "executionContext" | "metricsGuardrails">;
521
525
  branchId?: string;
522
526
  statePersistence?: StatePersistenceConfig;
523
527
  metricsGuardrails?: MetricsGuardrails;
528
+ maxTimeout?: number;
524
529
  }
525
- export interface STABLE_WORKFLOW_OPTIONS<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> extends Omit<API_GATEWAY_OPTIONS<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, 'concurrentExecution' | 'stopOnFirstError'> {
530
+ export interface STABLE_WORKFLOW_OPTIONS<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> extends Omit<API_GATEWAY_OPTIONS<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, 'concurrentExecution' | 'stopOnFirstError' | 'commonMaxSerializableChars'> {
526
531
  workflowId?: string;
527
532
  stopOnFirstPhaseError?: boolean;
528
533
  logPhaseResults?: boolean;
529
534
  concurrentPhaseExecution?: boolean;
530
535
  enableBranchExecution?: boolean;
531
- branches?: STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType>[];
536
+ enableBranchRacing?: boolean;
537
+ branches?: STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
532
538
  enableMixedExecution?: boolean;
533
539
  enableNonLinearExecution?: boolean;
534
540
  maxWorkflowIterations?: number;
535
541
  statePersistence?: StatePersistenceConfig;
536
- handlePhaseCompletion?: (options: HandlePhaseCompletionHookOptions<ResponseDataType>) => any | Promise<any>;
537
- handlePhaseError?: (options: HandlePhaseErrorHookOptions<ResponseDataType>) => any | Promise<any>;
538
- handlePhaseDecision?: (options: HandlePhaseDecisionHookOptions<ResponseDataType>) => any | Promise<any>;
539
- handleBranchCompletion?: (options: HandleBranchCompletionHookOptions<ResponseDataType>) => any | Promise<any>;
540
- handleBranchDecision?: (decision: BranchExecutionDecision, branchResult: BranchExecutionResult<ResponseDataType>, maxSerializableChars?: number) => any | Promise<any>;
541
- prePhaseExecutionHook?: (options: PrePhaseExecutionHookOptions<RequestDataType, ResponseDataType>) => STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType> | Promise<STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType>>;
542
- preBranchExecutionHook?: (options: PreBranchExecutionHookOptions<RequestDataType, ResponseDataType>) => STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType> | Promise<STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType>>;
542
+ handlePhaseCompletion?: (options: HandlePhaseCompletionHookOptions<ResponseDataType, FunctionReturnType>) => any | Promise<any>;
543
+ handlePhaseError?: (options: HandlePhaseErrorHookOptions<ResponseDataType, FunctionReturnType>) => any | Promise<any>;
544
+ handlePhaseDecision?: (options: HandlePhaseDecisionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => any | Promise<any>;
545
+ handleBranchCompletion?: (options: HandleBranchCompletionHookOptions<ResponseDataType, FunctionReturnType>) => any | Promise<any>;
546
+ handleBranchDecision?: (decision: BranchExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, branchResult: BranchExecutionResult<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>, maxSerializableChars?: number) => any | Promise<any>;
547
+ prePhaseExecutionHook?: (options: PrePhaseExecutionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType> | Promise<STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
548
+ preBranchExecutionHook?: (options: PreBranchExecutionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType> | Promise<STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
543
549
  maxSerializableChars?: number;
544
550
  workflowHookParams?: WorkflowHookParams;
545
- metricsGuardrails?: MetricsGuardrails;
546
551
  }
547
- export interface STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType = any> {
552
+ export interface STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType = any, FunctionReturnType = any, RequestDataType = any, FunctionArgsType extends any[] = any[]> {
548
553
  workflowId: string;
549
554
  branchId?: string;
550
555
  phaseId: string;
@@ -555,10 +560,10 @@ export interface STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType = any> {
555
560
  totalRequests: number;
556
561
  successfulRequests: number;
557
562
  failedRequests: number;
558
- responses: API_GATEWAY_RESPONSE<ResponseDataType>[];
563
+ responses: API_GATEWAY_RESPONSE<ResponseDataType, FunctionReturnType>[];
559
564
  executionNumber?: number;
560
565
  skipped?: boolean;
561
- decision?: PhaseExecutionDecision;
566
+ decision?: PhaseExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
562
567
  error?: string;
563
568
  metrics?: PhaseMetrics;
564
569
  validation?: MetricsValidationResult;
@@ -569,7 +574,7 @@ export interface STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType = any> {
569
574
  concurrencyLimiter?: ConcurrencyLimiterDashboardMetrics;
570
575
  };
571
576
  }
572
- export interface STABLE_WORKFLOW_RESULT<ResponseDataType = any> {
577
+ export interface STABLE_WORKFLOW_RESULT<ResponseDataType = any, FunctionReturnType = any, RequestDataType = any, FunctionArgsType extends any[] = any[]> {
573
578
  workflowId: string;
574
579
  success: boolean;
575
580
  executionTime: number;
@@ -579,10 +584,10 @@ export interface STABLE_WORKFLOW_RESULT<ResponseDataType = any> {
579
584
  totalRequests: number;
580
585
  successfulRequests: number;
581
586
  failedRequests: number;
582
- phases: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>[];
583
- executionHistory: PhaseExecutionRecord[];
584
- branches?: BranchExecutionResult<ResponseDataType>[];
585
- branchExecutionHistory?: BranchExecutionRecord[];
587
+ phases: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>[];
588
+ executionHistory: PhaseExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
589
+ branches?: BranchExecutionResult<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>[];
590
+ branchExecutionHistory?: BranchExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
586
591
  terminatedEarly?: boolean;
587
592
  terminationReason?: string;
588
593
  error?: string;
@@ -605,20 +610,20 @@ export interface WorkflowHookParams {
605
610
  preBranchExecutionHookParams?: any;
606
611
  statePersistence?: StatePersistenceConfig;
607
612
  }
608
- export interface HandlePhaseCompletionHookOptions<ResponseDataType = any> {
613
+ export interface HandlePhaseCompletionHookOptions<ResponseDataType = any, FunctionReturnType = any> {
609
614
  workflowId: string;
610
615
  branchId?: string;
611
- phaseResult: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>;
616
+ phaseResult: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType>;
612
617
  maxSerializableChars?: number;
613
618
  params?: any;
614
619
  sharedBuffer?: Record<string, any>;
615
620
  }
616
- export interface HandlePhaseErrorHookOptions<ResponseDataType = any> extends HandlePhaseCompletionHookOptions<ResponseDataType> {
621
+ export interface HandlePhaseErrorHookOptions<ResponseDataType = any, FunctionReturnType = any> extends HandlePhaseCompletionHookOptions<ResponseDataType, FunctionReturnType> {
617
622
  error: any;
618
623
  }
619
- export interface HandlePhaseDecisionHookOptions<ResponseDataType = any> {
620
- decision: PhaseExecutionDecision;
621
- phaseResult: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>;
624
+ export interface HandlePhaseDecisionHookOptions<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
625
+ decision: PhaseExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
626
+ phaseResult: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType>;
622
627
  maxSerializableChars?: number;
623
628
  }
624
629
  export interface RateLimitConfig {
@@ -656,53 +661,53 @@ export interface CachedResponse<T = any> {
656
661
  timestamp: number;
657
662
  expiresAt: number;
658
663
  }
659
- export interface PhaseExecutionDecision {
664
+ export interface PhaseExecutionDecision<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
660
665
  action: PHASE_DECISION_ACTIONS;
661
666
  targetPhaseId?: string;
662
667
  replayCount?: number;
663
668
  metadata?: Record<string, any>;
664
- addPhases?: STABLE_WORKFLOW_PHASE<any, any>[];
669
+ addPhases?: ReadonlyArray<STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
665
670
  }
666
- export interface PhaseDecisionHookOptions<ResponseDataType = any> {
671
+ export interface PhaseDecisionHookOptions<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
667
672
  workflowId: string;
668
673
  branchId?: string;
669
- phaseResult: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>;
674
+ phaseResult: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType>;
670
675
  phaseId: string;
671
676
  phaseIndex: number;
672
- executionHistory: PhaseExecutionRecord[];
677
+ executionHistory: PhaseExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
673
678
  sharedBuffer?: Record<string, any>;
674
679
  params?: any;
675
- concurrentPhaseResults?: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>[];
680
+ concurrentPhaseResults?: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType>[];
676
681
  }
677
- export interface PhaseExecutionRecord {
682
+ export interface PhaseExecutionRecord<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
678
683
  phaseId: string;
679
684
  phaseIndex: number;
680
685
  executionNumber: number;
681
686
  timestamp: string;
682
687
  success: boolean;
683
688
  executionTime: number;
684
- decision?: PhaseExecutionDecision;
689
+ decision?: PhaseExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
685
690
  }
686
- export interface NonLinearWorkflowContext<RequestDataType, ResponseDataType> {
687
- phases: STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType>[];
691
+ export interface NonLinearWorkflowContext<RequestDataType, ResponseDataType, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
692
+ phases: STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
688
693
  workflowId: string;
689
694
  branchId?: string;
690
695
  commonGatewayOptions: any;
691
696
  requestGroups: any[];
692
697
  logPhaseResults: boolean;
693
- handlePhaseCompletion: (options: HandlePhaseCompletionHookOptions<ResponseDataType>) => any | Promise<any>;
694
- handlePhaseError: (options: HandlePhaseErrorHookOptions<ResponseDataType>) => any | Promise<any>;
695
- handlePhaseDecision?: (options: HandlePhaseDecisionHookOptions<ResponseDataType>) => any | Promise<any>;
696
- prePhaseExecutionHook?: (options: PrePhaseExecutionHookOptions<RequestDataType, ResponseDataType>) => STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType> | Promise<STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType>>;
698
+ handlePhaseCompletion: (options: HandlePhaseCompletionHookOptions<ResponseDataType, FunctionReturnType>) => any | Promise<any>;
699
+ handlePhaseError: (options: HandlePhaseErrorHookOptions<ResponseDataType, FunctionReturnType>) => any | Promise<any>;
700
+ handlePhaseDecision?: (options: HandlePhaseDecisionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => any | Promise<any>;
701
+ prePhaseExecutionHook?: (options: PrePhaseExecutionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType> | Promise<STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
697
702
  maxSerializableChars: number;
698
703
  workflowHookParams: any;
699
704
  sharedBuffer?: Record<string, any>;
700
705
  stopOnFirstPhaseError: boolean;
701
706
  maxWorkflowIterations: number;
702
707
  }
703
- export interface EXECUTE_NON_LINEAR_WORKFLOW_RESPONSE<ResponseDataType = any> {
704
- phaseResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>[];
705
- executionHistory: PhaseExecutionRecord[];
708
+ export interface EXECUTE_NON_LINEAR_WORKFLOW_RESPONSE<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
709
+ phaseResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>[];
710
+ executionHistory: PhaseExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
706
711
  totalRequests: number;
707
712
  successfulRequests: number;
708
713
  failedRequests: number;
@@ -716,84 +721,86 @@ export interface STABLE_WORKFLOW_BRANCH<RequestDataType = any, ResponseDataType
716
721
  allowReplay?: boolean;
717
722
  maxReplayCount?: number;
718
723
  allowSkip?: boolean;
719
- branchDecisionHook?: (options: BranchDecisionHookOptions<ResponseDataType>) => BranchExecutionDecision | Promise<BranchExecutionDecision>;
724
+ branchDecisionHook?: (options: BranchDecisionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => BranchExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType> | Promise<BranchExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
720
725
  statePersistence?: StatePersistenceConfig;
721
- commonConfig?: Omit<API_GATEWAY_OPTIONS<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, 'concurrentExecution' | 'stopOnFirstError' | 'requestGroups' | 'maxConcurrentRequests' | 'rateLimit' | 'circuitBreaker'>;
726
+ commonConfig?: Omit<API_GATEWAY_OPTIONS<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, 'concurrentExecution' | 'stopOnFirstError' | 'requestGroups' | 'maxConcurrentRequests' | 'rateLimit' | 'circuitBreaker' | 'maxTimeout' | "executionContext" | "metricsGuardrails">;
722
727
  metricsGuardrails?: MetricsGuardrails;
728
+ maxTimeout?: number;
723
729
  }
724
- export interface BranchDecisionHookOptions<ResponseDataType = any> {
730
+ export interface BranchDecisionHookOptions<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
725
731
  workflowId: string;
726
- branchResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>[];
732
+ branchResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>[];
727
733
  branchId: string;
728
734
  branchIndex: number;
729
735
  executionNumber: number;
730
- executionHistory: PhaseExecutionRecord[];
731
- branchExecutionHistory: BranchExecutionRecord[];
736
+ executionHistory: PhaseExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
737
+ branchExecutionHistory: BranchExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
732
738
  sharedBuffer?: Record<string, any>;
733
739
  params?: any;
734
- concurrentBranchResults?: BranchExecutionResult<ResponseDataType>[];
740
+ concurrentBranchResults?: BranchExecutionResult<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>[];
735
741
  }
736
- export interface BranchExecutionDecision {
742
+ export interface BranchExecutionDecision<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
737
743
  action: PHASE_DECISION_ACTIONS;
738
744
  targetBranchId?: string;
739
745
  metadata?: Record<string, any>;
740
- addPhases?: STABLE_WORKFLOW_PHASE<any, any>[];
741
- addBranches?: STABLE_WORKFLOW_BRANCH<any, any>[];
746
+ addPhases?: ReadonlyArray<STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
747
+ addBranches?: ReadonlyArray<STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
742
748
  }
743
- export interface BranchExecutionResult<ResponseDataType = any> {
749
+ export interface BranchExecutionResult<ResponseDataType = any, FunctionReturnType = any, RequestDataType = any, FunctionArgsType extends any[] = any[]> {
744
750
  workflowId: string;
745
751
  branchId: string;
746
752
  branchIndex: number;
747
753
  success: boolean;
748
754
  executionTime: number;
749
755
  completedPhases: number;
750
- phaseResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>[];
751
- decision?: BranchExecutionDecision;
756
+ phaseResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>[];
757
+ decision?: BranchExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
752
758
  executionNumber: number;
753
759
  skipped?: boolean;
754
760
  error?: string;
755
761
  metrics?: BranchMetrics;
756
762
  validation?: MetricsValidationResult;
757
763
  }
758
- export interface BranchExecutionRecord {
764
+ export interface BranchExecutionRecord<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
759
765
  branchId: string;
760
766
  branchIndex: number;
761
767
  executionNumber: number;
762
768
  timestamp: string;
763
769
  success: boolean;
764
770
  executionTime: number;
765
- decision?: BranchExecutionDecision;
771
+ decision?: BranchExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
766
772
  }
767
- export interface HandleBranchCompletionHookOptions<ResponseDataType = any> {
773
+ export interface HandleBranchCompletionHookOptions<ResponseDataType = any, FunctionReturnType = any> {
768
774
  workflowId: string;
769
775
  branchId: string;
770
- branchResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>[];
776
+ branchResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, any, any[]>[];
771
777
  success: boolean;
772
778
  maxSerializableChars?: number;
773
779
  }
774
- export interface BranchWorkflowContext<RequestDataType = any, ResponseDataType = any> {
775
- branches: STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType>[];
780
+ export interface BranchWorkflowContext<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
781
+ branches: STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
776
782
  workflowId: string;
777
783
  commonGatewayOptions: any;
778
784
  requestGroups: any[];
779
785
  logPhaseResults: boolean;
780
- handlePhaseCompletion: (options: HandlePhaseCompletionHookOptions<ResponseDataType>) => any | Promise<any>;
781
- handlePhaseError: (options: HandlePhaseErrorHookOptions<ResponseDataType>) => any | Promise<any>;
782
- handleBranchCompletion?: (options: HandleBranchCompletionHookOptions<ResponseDataType>) => any | Promise<any>;
783
- handleBranchDecision?: (decision: BranchExecutionDecision, branchResult: BranchExecutionResult<ResponseDataType>, maxSerializableChars?: number) => any | Promise<any>;
784
- preBranchExecutionHook?: (options: PreBranchExecutionHookOptions<RequestDataType, ResponseDataType>) => STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType> | Promise<STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType>>;
785
- prePhaseExecutionHook?: (options: PrePhaseExecutionHookOptions<RequestDataType, ResponseDataType>) => STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType> | Promise<STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType>>;
786
+ handlePhaseCompletion: (options: HandlePhaseCompletionHookOptions<ResponseDataType, FunctionReturnType>) => any | Promise<any>;
787
+ handlePhaseError: (options: HandlePhaseErrorHookOptions<ResponseDataType, FunctionReturnType>) => any | Promise<any>;
788
+ handleBranchCompletion?: (options: HandleBranchCompletionHookOptions<ResponseDataType, FunctionReturnType>) => any | Promise<any>;
789
+ handleBranchDecision?: (decision: BranchExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, branchResult: BranchExecutionResult<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>, maxSerializableChars?: number) => any | Promise<any>;
790
+ preBranchExecutionHook?: (options: PreBranchExecutionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType> | Promise<STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
791
+ prePhaseExecutionHook?: (options: PrePhaseExecutionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType> | Promise<STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
786
792
  maxSerializableChars: number;
787
793
  workflowHookParams: any;
788
794
  sharedBuffer?: Record<string, any>;
789
795
  stopOnFirstPhaseError: boolean;
796
+ enableBranchRacing?: boolean;
790
797
  maxWorkflowIterations: number;
791
798
  }
792
- export interface EXECUTE_BRANCH_WORKFLOW_RESPONSE<ResponseDataType = any> {
793
- branchResults: BranchExecutionResult<ResponseDataType>[];
794
- allPhaseResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>[];
795
- executionHistory: PhaseExecutionRecord[];
796
- branchExecutionHistory: BranchExecutionRecord[];
799
+ export interface EXECUTE_BRANCH_WORKFLOW_RESPONSE<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
800
+ branchResults: BranchExecutionResult<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>[];
801
+ allPhaseResults: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>[];
802
+ executionHistory: PhaseExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
803
+ branchExecutionHistory: BranchExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[];
797
804
  totalRequests: number;
798
805
  successfulRequests: number;
799
806
  failedRequests: number;
@@ -985,7 +992,7 @@ export interface SystemMetrics {
985
992
  export type WorkflowNodeType = WorkflowNodeTypes.PHASE | WorkflowNodeTypes.BRANCH | WorkflowNodeTypes.CONDITIONAL | WorkflowNodeTypes.PARALLEL_GROUP | WorkflowNodeTypes.MERGE_POINT;
986
993
  export interface WorkflowGraph<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
987
994
  nodes: Map<string, WorkflowNode<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
988
- edges: Map<string, WorkflowEdge[]>;
995
+ edges: Map<string, WorkflowEdge<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>[]>;
989
996
  entryPoint: string;
990
997
  exitPoints?: string[];
991
998
  metadata?: Record<string, any>;
@@ -995,40 +1002,40 @@ export interface WorkflowNode<RequestDataType = any, ResponseDataType = any, Fun
995
1002
  type: WorkflowNodeType;
996
1003
  phase?: STABLE_WORKFLOW_PHASE<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
997
1004
  branch?: STABLE_WORKFLOW_BRANCH<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
998
- condition?: ConditionalNode<ResponseDataType>;
1005
+ condition?: ConditionalNode<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
999
1006
  parallelNodes?: string[];
1000
1007
  waitForNodes?: string[];
1001
1008
  metadata?: Record<string, any>;
1002
- phaseDecisionHook?: (context: PhaseDecisionHookOptions<ResponseDataType>) => PhaseExecutionDecision | Promise<PhaseExecutionDecision>;
1009
+ phaseDecisionHook?: (context: PhaseDecisionHookOptions<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => PhaseExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType> | Promise<PhaseExecutionDecision<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
1003
1010
  }
1004
- export interface WorkflowEdge {
1011
+ export interface WorkflowEdge<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
1005
1012
  from: string;
1006
1013
  to: string;
1007
- condition?: EdgeCondition;
1014
+ condition?: EdgeCondition<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>;
1008
1015
  weight?: number;
1009
1016
  label?: string;
1010
1017
  metadata?: Record<string, any>;
1011
1018
  }
1012
1019
  export type EdgeConditionType = WorkflowEdgeConditionTypes.SUCCESS | WorkflowEdgeConditionTypes.FAILURE | WorkflowEdgeConditionTypes.CUSTOM | WorkflowEdgeConditionTypes.ALWAYS;
1013
- export interface EdgeCondition {
1020
+ export interface EdgeCondition<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
1014
1021
  type: EdgeConditionType;
1015
- evaluate?: (context: EdgeEvaluationContext) => boolean | Promise<boolean>;
1022
+ evaluate?: (context: EdgeEvaluationContext<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => boolean | Promise<boolean>;
1016
1023
  }
1017
- export interface EdgeEvaluationContext {
1018
- results: Map<string, STABLE_WORKFLOW_PHASE_RESULT<any>>;
1024
+ export interface EdgeEvaluationContext<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
1025
+ results: Map<string, STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>>;
1019
1026
  sharedBuffer?: Record<string, any>;
1020
- executionHistory: PhaseExecutionRecord[];
1027
+ executionHistory: ReadonlyArray<PhaseExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
1021
1028
  currentNodeId: string;
1022
1029
  }
1023
- export interface ConditionalNode<ResponseDataType = any> {
1024
- evaluate: (context: ConditionalEvaluationContext<ResponseDataType>) => string | Promise<string>;
1030
+ export interface ConditionalNode<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
1031
+ evaluate: (context: ConditionalEvaluationContext<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>) => string | Promise<string>;
1025
1032
  }
1026
- export interface ConditionalEvaluationContext<ResponseDataType = any> {
1027
- results: Map<string, STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>>;
1033
+ export interface ConditionalEvaluationContext<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> {
1034
+ results: Map<string, STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>>;
1028
1035
  sharedBuffer?: Record<string, any>;
1029
- executionHistory: PhaseExecutionRecord[];
1036
+ executionHistory: ReadonlyArray<PhaseExecutionRecord<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>>;
1030
1037
  currentNodeId: string;
1031
- phaseResult?: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType>;
1038
+ phaseResult?: STABLE_WORKFLOW_PHASE_RESULT<ResponseDataType, FunctionReturnType, RequestDataType, FunctionArgsType>;
1032
1039
  }
1033
1040
  export interface WorkflowGraphOptions<RequestDataType = any, ResponseDataType = any, FunctionArgsType extends any[] = any[], FunctionReturnType = any> extends Omit<STABLE_WORKFLOW_OPTIONS<RequestDataType, ResponseDataType, FunctionArgsType, FunctionReturnType>, 'branches' | 'enableBranchExecution' | 'concurrentPhaseExecution' | 'enableMixedExecution' | 'enableNonLinearExecution'> {
1034
1041
  validateGraph?: boolean;