@8medusa/orchestration 2.7.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 (74) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +20 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/joiner/helpers.d.ts +3 -0
  6. package/dist/joiner/helpers.d.ts.map +1 -0
  7. package/dist/joiner/helpers.js +69 -0
  8. package/dist/joiner/helpers.js.map +1 -0
  9. package/dist/joiner/index.d.ts +3 -0
  10. package/dist/joiner/index.d.ts.map +1 -0
  11. package/dist/joiner/index.js +19 -0
  12. package/dist/joiner/index.js.map +1 -0
  13. package/dist/joiner/remote-joiner.d.ts +42 -0
  14. package/dist/joiner/remote-joiner.d.ts.map +1 -0
  15. package/dist/joiner/remote-joiner.js +1108 -0
  16. package/dist/joiner/remote-joiner.js.map +1 -0
  17. package/dist/transaction/datastore/abstract-storage.d.ts +42 -0
  18. package/dist/transaction/datastore/abstract-storage.d.ts.map +1 -0
  19. package/dist/transaction/datastore/abstract-storage.js +52 -0
  20. package/dist/transaction/datastore/abstract-storage.js.map +1 -0
  21. package/dist/transaction/datastore/base-in-memory-storage.d.ts +11 -0
  22. package/dist/transaction/datastore/base-in-memory-storage.d.ts.map +1 -0
  23. package/dist/transaction/datastore/base-in-memory-storage.js +33 -0
  24. package/dist/transaction/datastore/base-in-memory-storage.js.map +1 -0
  25. package/dist/transaction/distributed-transaction.d.ts +99 -0
  26. package/dist/transaction/distributed-transaction.d.ts.map +1 -0
  27. package/dist/transaction/distributed-transaction.js +258 -0
  28. package/dist/transaction/distributed-transaction.js.map +1 -0
  29. package/dist/transaction/errors.d.ts +31 -0
  30. package/dist/transaction/errors.d.ts.map +1 -0
  31. package/dist/transaction/errors.js +89 -0
  32. package/dist/transaction/errors.js.map +1 -0
  33. package/dist/transaction/index.d.ts +8 -0
  34. package/dist/transaction/index.d.ts.map +1 -0
  35. package/dist/transaction/index.js +24 -0
  36. package/dist/transaction/index.js.map +1 -0
  37. package/dist/transaction/orchestrator-builder.d.ts +36 -0
  38. package/dist/transaction/orchestrator-builder.d.ts.map +1 -0
  39. package/dist/transaction/orchestrator-builder.js +300 -0
  40. package/dist/transaction/orchestrator-builder.js.map +1 -0
  41. package/dist/transaction/transaction-orchestrator.d.ts +181 -0
  42. package/dist/transaction/transaction-orchestrator.d.ts.map +1 -0
  43. package/dist/transaction/transaction-orchestrator.js +1061 -0
  44. package/dist/transaction/transaction-orchestrator.js.map +1 -0
  45. package/dist/transaction/transaction-step.d.ts +67 -0
  46. package/dist/transaction/transaction-step.d.ts.map +1 -0
  47. package/dist/transaction/transaction-step.js +146 -0
  48. package/dist/transaction/transaction-step.js.map +1 -0
  49. package/dist/transaction/types.d.ts +236 -0
  50. package/dist/transaction/types.d.ts.map +1 -0
  51. package/dist/transaction/types.js +23 -0
  52. package/dist/transaction/types.js.map +1 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -0
  54. package/dist/workflow/global-workflow.d.ts +14 -0
  55. package/dist/workflow/global-workflow.d.ts.map +1 -0
  56. package/dist/workflow/global-workflow.js +105 -0
  57. package/dist/workflow/global-workflow.js.map +1 -0
  58. package/dist/workflow/index.d.ts +5 -0
  59. package/dist/workflow/index.d.ts.map +1 -0
  60. package/dist/workflow/index.js +21 -0
  61. package/dist/workflow/index.js.map +1 -0
  62. package/dist/workflow/local-workflow.d.ts +46 -0
  63. package/dist/workflow/local-workflow.d.ts.map +1 -0
  64. package/dist/workflow/local-workflow.js +360 -0
  65. package/dist/workflow/local-workflow.js.map +1 -0
  66. package/dist/workflow/scheduler.d.ts +12 -0
  67. package/dist/workflow/scheduler.d.ts.map +1 -0
  68. package/dist/workflow/scheduler.js +35 -0
  69. package/dist/workflow/scheduler.js.map +1 -0
  70. package/dist/workflow/workflow-manager.d.ts +38 -0
  71. package/dist/workflow/workflow-manager.d.ts.map +1 -0
  72. package/dist/workflow/workflow-manager.js +124 -0
  73. package/dist/workflow/workflow-manager.js.map +1 -0
  74. package/package.json +59 -0
@@ -0,0 +1,181 @@
1
+ import { DistributedTransactionType } from "./distributed-transaction";
2
+ import { TransactionStepHandler } from "./transaction-step";
3
+ import { TransactionFlow, TransactionModelOptions, TransactionOptions, TransactionStepsDefinition } from "./types";
4
+ import { EventEmitter } from "events";
5
+ /**
6
+ * @class TransactionOrchestrator is responsible for managing and executing distributed transactions.
7
+ * It is based on a single transaction definition, which is used to execute all the transaction steps
8
+ */
9
+ export declare class TransactionOrchestrator extends EventEmitter {
10
+ id: string;
11
+ private static ROOT_STEP;
12
+ static DEFAULT_TTL: number;
13
+ private invokeSteps;
14
+ private compensateSteps;
15
+ private definition;
16
+ private options?;
17
+ static DEFAULT_RETRIES: number;
18
+ private static workflowOptions;
19
+ static getWorkflowOptions(modelId: string): TransactionOptions;
20
+ /**
21
+ * Trace workflow transaction for instrumentation
22
+ */
23
+ static traceTransaction?: (transactionResume: (...args: any[]) => Promise<void>, metadata: {
24
+ model_id: string;
25
+ transaction_id: string;
26
+ flow_metadata: TransactionFlow["metadata"];
27
+ }) => Promise<any>;
28
+ /**
29
+ * Trace workflow steps for instrumentation
30
+ */
31
+ static traceStep?: (handler: (...args: any[]) => Promise<any>, metadata: {
32
+ action: string;
33
+ type: "invoke" | "compensate";
34
+ step_id: string;
35
+ step_uuid: string;
36
+ attempts: number;
37
+ failures: number;
38
+ async: boolean;
39
+ idempotency_key: string;
40
+ }) => Promise<any>;
41
+ constructor({ id, definition, options, isClone, }: {
42
+ id: string;
43
+ definition: TransactionStepsDefinition;
44
+ options?: TransactionModelOptions;
45
+ isClone?: boolean;
46
+ });
47
+ static clone(orchestrator: TransactionOrchestrator): TransactionOrchestrator;
48
+ private static SEPARATOR;
49
+ static getKeyName(...params: string[]): string;
50
+ private getPreviousStep;
51
+ getOptions(): TransactionModelOptions;
52
+ private getInvokeSteps;
53
+ private getCompensationSteps;
54
+ private canMoveForward;
55
+ private canMoveBackward;
56
+ private canContinue;
57
+ private hasExpired;
58
+ private checkTransactionTimeout;
59
+ private checkStepTimeout;
60
+ private checkAllSteps;
61
+ private computeCurrentTransactionState;
62
+ private flagStepsToRevert;
63
+ private static setStepSuccess;
64
+ private static skipStep;
65
+ private static setStepTimeout;
66
+ private static setStepFailure;
67
+ private executeNext;
68
+ /**
69
+ * Finalize the transaction when all steps are complete
70
+ */
71
+ private finalizeTransaction;
72
+ /**
73
+ * Prepare a step for execution by setting state and incrementing attempts
74
+ */
75
+ private prepareStepForExecution;
76
+ /**
77
+ * Create the payload for a step execution
78
+ */
79
+ private createStepPayload;
80
+ /**
81
+ * Prepare handler arguments for step execution
82
+ */
83
+ private prepareHandlerArgs;
84
+ /**
85
+ * Create the step execution promise with optional tracing
86
+ */
87
+ private createStepExecutionPromise;
88
+ /**
89
+ * Execute a synchronous step and handle its result
90
+ */
91
+ private executeSyncStep;
92
+ /**
93
+ * Execute an asynchronous step and handle its result
94
+ */
95
+ private executeAsyncStep;
96
+ /**
97
+ * Check if step or transaction has expired and handle timeouts
98
+ */
99
+ private handleStepExpiration;
100
+ /**
101
+ * Handle successful step completion
102
+ */
103
+ private handleStepSuccess;
104
+ /**
105
+ * Handle step failure
106
+ */
107
+ private handleStepFailure;
108
+ /**
109
+ * Start a new transaction or resume a transaction that has been previously started
110
+ * @param transaction - The transaction to resume
111
+ */
112
+ resume(transaction: DistributedTransactionType): Promise<void>;
113
+ /**
114
+ * Cancel and revert a transaction compensating all its executed steps. It can be an ongoing transaction or a completed one
115
+ * @param transaction - The transaction to be reverted
116
+ */
117
+ cancelTransaction(transaction: DistributedTransactionType): Promise<void>;
118
+ private parseFlowOptions;
119
+ private createTransactionFlow;
120
+ private static loadTransactionById;
121
+ private static buildSteps;
122
+ /** Create a new transaction
123
+ * @param transactionId - unique identifier of the transaction
124
+ * @param handler - function to handle action of the transaction
125
+ * @param payload - payload to be passed to all the transaction steps
126
+ * @param flowMetadata - flow metadata which can include event group id for example
127
+ */
128
+ beginTransaction({ transactionId, handler, payload, flowMetadata, onLoad, }: {
129
+ transactionId: string;
130
+ handler: TransactionStepHandler;
131
+ payload?: unknown;
132
+ flowMetadata?: TransactionFlow["metadata"];
133
+ onLoad?: (transaction: DistributedTransactionType) => Promise<void> | void;
134
+ }): Promise<DistributedTransactionType>;
135
+ /** Returns an existing transaction
136
+ * @param transactionId - unique identifier of the transaction
137
+ * @param handler - function to handle action of the transaction
138
+ */
139
+ retrieveExistingTransaction(transactionId: string, handler: TransactionStepHandler): Promise<DistributedTransactionType>;
140
+ private static getStepByAction;
141
+ private static getTransactionAndStepFromIdempotencyKey;
142
+ /** Skip the execution of a specific transaction and step
143
+ * @param responseIdempotencyKey - The idempotency key for the step
144
+ * @param handler - The handler function to execute the step
145
+ * @param transaction - The current transaction. If not provided it will be loaded based on the responseIdempotencyKey
146
+ */
147
+ skipStep({ responseIdempotencyKey, handler, transaction, }: {
148
+ responseIdempotencyKey: string;
149
+ handler?: TransactionStepHandler;
150
+ transaction?: DistributedTransactionType;
151
+ }): Promise<DistributedTransactionType>;
152
+ /** Register a step success for a specific transaction and step
153
+ * @param responseIdempotencyKey - The idempotency key for the step
154
+ * @param handler - The handler function to execute the step
155
+ * @param transaction - The current transaction. If not provided it will be loaded based on the responseIdempotencyKey
156
+ * @param response - The response of the step
157
+ */
158
+ registerStepSuccess({ responseIdempotencyKey, handler, transaction, response, onLoad, }: {
159
+ responseIdempotencyKey: string;
160
+ handler?: TransactionStepHandler;
161
+ transaction?: DistributedTransactionType;
162
+ response?: unknown;
163
+ onLoad?: (transaction: DistributedTransactionType) => Promise<void> | void;
164
+ }): Promise<DistributedTransactionType>;
165
+ /**
166
+ * Register a step failure for a specific transaction and step
167
+ * @param responseIdempotencyKey - The idempotency key for the step
168
+ * @param error - The error that caused the failure
169
+ * @param handler - The handler function to execute the step
170
+ * @param transaction - The current transaction
171
+ * @param response - The response of the step
172
+ */
173
+ registerStepFailure({ responseIdempotencyKey, error, handler, transaction, onLoad, }: {
174
+ responseIdempotencyKey: string;
175
+ error?: Error | any;
176
+ handler?: TransactionStepHandler;
177
+ transaction?: DistributedTransactionType;
178
+ onLoad?: (transaction: DistributedTransactionType) => Promise<void> | void;
179
+ }): Promise<DistributedTransactionType>;
180
+ }
181
+ //# sourceMappingURL=transaction-orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-orchestrator.d.ts","sourceRoot":"","sources":["../../src/transaction/transaction-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAG3B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAmB,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAGL,eAAe,EAEf,uBAAuB,EACvB,kBAAkB,EAElB,0BAA0B,EAE3B,MAAM,SAAS,CAAA;AAWhB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AASrC;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,YAAY;IACvD,EAAE,EAAE,MAAM,CAAA;IAEV,OAAO,CAAC,MAAM,CAAC,SAAS,CAAU;IAClC,OAAc,WAAW,SAAK;IAC9B,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,OAAO,CAAC,CAAyB;IAEzC,OAAc,eAAe,SAAI;IAEjC,OAAO,CAAC,MAAM,CAAC,eAAe,CAExB;WAEQ,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB;IAIrE;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,EAAE,CACxB,iBAAiB,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,EACpD,QAAQ,EAAE;QACR,QAAQ,EAAE,MAAM,CAAA;QAChB,cAAc,EAAE,MAAM,CAAA;QACtB,aAAa,EAAE,eAAe,CAAC,UAAU,CAAC,CAAA;KAC3C,KAC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