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