@etohq/orchestration 1.0.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 +39 -0
  14. package/dist/joiner/remote-joiner.d.ts.map +1 -0
  15. package/dist/joiner/remote-joiner.js +872 -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 +260 -0
  28. package/dist/transaction/distributed-transaction.js.map +1 -0
  29. package/dist/transaction/errors.d.ts +27 -0
  30. package/dist/transaction/errors.d.ts.map +1 -0
  31. package/dist/transaction/errors.js +78 -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 +118 -0
  42. package/dist/transaction/transaction-orchestrator.d.ts.map +1 -0
  43. package/dist/transaction/transaction-orchestrator.js +924 -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 +223 -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 +93 -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 +44 -0
  63. package/dist/workflow/local-workflow.d.ts.map +1 -0
  64. package/dist/workflow/local-workflow.js +327 -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 +36 -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 +52 -0
@@ -0,0 +1,27 @@
1
+ declare class BaseStepErrror extends Error {
2
+ #private;
3
+ constructor(name: any, message?: string, stepResponse?: unknown);
4
+ getStepResponse(): unknown;
5
+ }
6
+ export declare class PermanentStepFailureError extends BaseStepErrror {
7
+ static isPermanentStepFailureError(error: Error): error is PermanentStepFailureError;
8
+ constructor(message?: string, stepResponse?: unknown);
9
+ }
10
+ export declare class SkipStepResponse extends BaseStepErrror {
11
+ static isSkipStepResponse(error: Error): error is SkipStepResponse;
12
+ constructor(message?: string, stepResponse?: unknown);
13
+ }
14
+ export declare class TransactionStepTimeoutError extends BaseStepErrror {
15
+ static isTransactionStepTimeoutError(error: Error): error is TransactionStepTimeoutError;
16
+ constructor(message?: string, stepResponse?: unknown);
17
+ }
18
+ export declare class TransactionTimeoutError extends BaseStepErrror {
19
+ static isTransactionTimeoutError(error: Error): error is TransactionTimeoutError;
20
+ constructor(message?: string, stepResponse?: unknown);
21
+ }
22
+ export declare class NonSerializableCheckPointError extends Error {
23
+ static isNonSerializableCheckPointError(error: Error): error is NonSerializableCheckPointError;
24
+ constructor(message?: string);
25
+ }
26
+ export {};
27
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/transaction/errors.ts"],"names":[],"mappings":"AAAA,cAAM,cAAe,SAAQ,KAAK;;gBAGpB,IAAI,KAAA,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO;IAM1D,eAAe,IAAI,OAAO;CAG3B;AAED,qBAAa,yBAA0B,SAAQ,cAAc;IAC3D,MAAM,CAAC,2BAA2B,CAChC,KAAK,EAAE,KAAK,GACX,KAAK,IAAI,yBAAyB;gBAOzB,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO;CAGrD;AAED,qBAAa,gBAAiB,SAAQ,cAAc;IAClD,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,gBAAgB;gBAMtD,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO;CAGrD;AAED,qBAAa,2BAA4B,SAAQ,cAAc;IAC7D,MAAM,CAAC,6BAA6B,CAClC,KAAK,EAAE,KAAK,GACX,KAAK,IAAI,2BAA2B;gBAO3B,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO;CAGrD;AAED,qBAAa,uBAAwB,SAAQ,cAAc;IACzD,MAAM,CAAC,yBAAyB,CAC9B,KAAK,EAAE,KAAK,GACX,KAAK,IAAI,uBAAuB;gBAOvB,OAAO,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO;CAGrD;AAED,qBAAa,8BAA+B,SAAQ,KAAK;IACvD,MAAM,CAAC,gCAAgC,CACrC,KAAK,EAAE,KAAK,GACX,KAAK,IAAI,8BAA8B;gBAO9B,OAAO,CAAC,EAAE,MAAM;CAI7B"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _BaseStepErrror_stepResponse;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.NonSerializableCheckPointError = exports.TransactionTimeoutError = exports.TransactionStepTimeoutError = exports.SkipStepResponse = exports.PermanentStepFailureError = void 0;
16
+ class BaseStepErrror extends Error {
17
+ constructor(name, message, stepResponse) {
18
+ super(message);
19
+ _BaseStepErrror_stepResponse.set(this, void 0);
20
+ this.name = name;
21
+ __classPrivateFieldSet(this, _BaseStepErrror_stepResponse, stepResponse, "f");
22
+ }
23
+ getStepResponse() {
24
+ return __classPrivateFieldGet(this, _BaseStepErrror_stepResponse, "f");
25
+ }
26
+ }
27
+ _BaseStepErrror_stepResponse = new WeakMap();
28
+ class PermanentStepFailureError extends BaseStepErrror {
29
+ static isPermanentStepFailureError(error) {
30
+ return (error instanceof PermanentStepFailureError ||
31
+ error?.name === "PermanentStepFailure");
32
+ }
33
+ constructor(message, stepResponse) {
34
+ super("PermanentStepFailure", message, stepResponse);
35
+ }
36
+ }
37
+ exports.PermanentStepFailureError = PermanentStepFailureError;
38
+ class SkipStepResponse extends BaseStepErrror {
39
+ static isSkipStepResponse(error) {
40
+ return (error instanceof SkipStepResponse || error?.name === "SkipStepResponse");
41
+ }
42
+ constructor(message, stepResponse) {
43
+ super("SkipStepResponse", message, stepResponse);
44
+ }
45
+ }
46
+ exports.SkipStepResponse = SkipStepResponse;
47
+ class TransactionStepTimeoutError extends BaseStepErrror {
48
+ static isTransactionStepTimeoutError(error) {
49
+ return (error instanceof TransactionStepTimeoutError ||
50
+ error?.name === "TransactionStepTimeoutError");
51
+ }
52
+ constructor(message, stepResponse) {
53
+ super("TransactionStepTimeoutError", message, stepResponse);
54
+ }
55
+ }
56
+ exports.TransactionStepTimeoutError = TransactionStepTimeoutError;
57
+ class TransactionTimeoutError extends BaseStepErrror {
58
+ static isTransactionTimeoutError(error) {
59
+ return (error instanceof TransactionTimeoutError ||
60
+ error?.name === "TransactionTimeoutError");
61
+ }
62
+ constructor(message, stepResponse) {
63
+ super("TransactionTimeoutError", message, stepResponse);
64
+ }
65
+ }
66
+ exports.TransactionTimeoutError = TransactionTimeoutError;
67
+ class NonSerializableCheckPointError extends Error {
68
+ static isNonSerializableCheckPointError(error) {
69
+ return (error instanceof NonSerializableCheckPointError ||
70
+ error?.name === "NonSerializableCheckPointError");
71
+ }
72
+ constructor(message) {
73
+ super(message);
74
+ this.name = "NonSerializableCheckPointError";
75
+ }
76
+ }
77
+ exports.NonSerializableCheckPointError = NonSerializableCheckPointError;
78
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/transaction/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,MAAM,cAAe,SAAQ,KAAK;IAGhC,YAAY,IAAI,EAAE,OAAgB,EAAE,YAAsB;QACxD,KAAK,CAAC,OAAO,CAAC,CAAA;QAHhB,+CAAsB;QAIpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,uBAAA,IAAI,gCAAiB,YAAY,MAAA,CAAA;IACnC,CAAC;IAED,eAAe;QACb,OAAO,uBAAA,IAAI,oCAAc,CAAA;IAC3B,CAAC;CACF;;AAED,MAAa,yBAA0B,SAAQ,cAAc;IAC3D,MAAM,CAAC,2BAA2B,CAChC,KAAY;QAEZ,OAAO,CACL,KAAK,YAAY,yBAAyB;YAC1C,KAAK,EAAE,IAAI,KAAK,sBAAsB,CACvC,CAAA;IACH,CAAC;IAED,YAAY,OAAgB,EAAE,YAAsB;QAClD,KAAK,CAAC,sBAAsB,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;IACtD,CAAC;CACF;AAbD,8DAaC;AAED,MAAa,gBAAiB,SAAQ,cAAc;IAClD,MAAM,CAAC,kBAAkB,CAAC,KAAY;QACpC,OAAO,CACL,KAAK,YAAY,gBAAgB,IAAI,KAAK,EAAE,IAAI,KAAK,kBAAkB,CACxE,CAAA;IACH,CAAC;IAED,YAAY,OAAgB,EAAE,YAAsB;QAClD,KAAK,CAAC,kBAAkB,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;IAClD,CAAC;CACF;AAVD,4CAUC;AAED,MAAa,2BAA4B,SAAQ,cAAc;IAC7D,MAAM,CAAC,6BAA6B,CAClC,KAAY;QAEZ,OAAO,CACL,KAAK,YAAY,2BAA2B;YAC5C,KAAK,EAAE,IAAI,KAAK,6BAA6B,CAC9C,CAAA;IACH,CAAC;IAED,YAAY,OAAgB,EAAE,YAAsB;QAClD,KAAK,CAAC,6BAA6B,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;IAC7D,CAAC;CACF;AAbD,kEAaC;AAED,MAAa,uBAAwB,SAAQ,cAAc;IACzD,MAAM,CAAC,yBAAyB,CAC9B,KAAY;QAEZ,OAAO,CACL,KAAK,YAAY,uBAAuB;YACxC,KAAK,EAAE,IAAI,KAAK,yBAAyB,CAC1C,CAAA;IACH,CAAC;IAED,YAAY,OAAgB,EAAE,YAAsB;QAClD,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;IACzD,CAAC;CACF;AAbD,0DAaC;AAED,MAAa,8BAA+B,SAAQ,KAAK;IACvD,MAAM,CAAC,gCAAgC,CACrC,KAAY;QAEZ,OAAO,CACL,KAAK,YAAY,8BAA8B;YAC/C,KAAK,EAAE,IAAI,KAAK,gCAAgC,CACjD,CAAA;IACH,CAAC;IAED,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAA;IAC9C,CAAC;CACF;AAdD,wEAcC"}
@@ -0,0 +1,8 @@
1
+ export * from "./datastore/abstract-storage";
2
+ export * from "./distributed-transaction";
3
+ export * from "./errors";
4
+ export * from "./orchestrator-builder";
5
+ export * from "./transaction-orchestrator";
6
+ export * from "./transaction-step";
7
+ export * from "./types";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transaction/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,SAAS,CAAA"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./datastore/abstract-storage"), exports);
18
+ __exportStar(require("./distributed-transaction"), exports);
19
+ __exportStar(require("./errors"), exports);
20
+ __exportStar(require("./orchestrator-builder"), exports);
21
+ __exportStar(require("./transaction-orchestrator"), exports);
22
+ __exportStar(require("./transaction-step"), exports);
23
+ __exportStar(require("./types"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transaction/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA4C;AAC5C,4DAAyC;AACzC,2CAAwB;AACxB,yDAAsC;AACtC,6DAA0C;AAC1C,qDAAkC;AAClC,0CAAuB"}
@@ -0,0 +1,36 @@
1
+ import { TransactionStepsDefinition } from "./types";
2
+ interface InternalStep extends TransactionStepsDefinition {
3
+ next?: InternalStep | InternalStep[];
4
+ depth: number;
5
+ parent?: InternalStep | null;
6
+ }
7
+ export declare class OrchestratorBuilder {
8
+ protected steps: InternalStep;
9
+ protected hasChanges_: boolean;
10
+ get hasChanges(): boolean;
11
+ constructor(steps?: TransactionStepsDefinition);
12
+ load(steps?: TransactionStepsDefinition): this;
13
+ addAction(action: string, options?: Partial<TransactionStepsDefinition>): this;
14
+ replaceAction(existingAction: string, action: string, options?: Partial<TransactionStepsDefinition>): this;
15
+ insertActionBefore(existingAction: string, action: string, options?: Partial<TransactionStepsDefinition>): this;
16
+ insertActionAfter(existingAction: string, action: string, options?: Partial<TransactionStepsDefinition>): this;
17
+ protected appendTo(step: InternalStep | string, newStep: InternalStep): this;
18
+ appendAction(action: string, to: string, options?: Partial<TransactionStepsDefinition>): this;
19
+ protected move(actionToMove: string, targetAction: string, { runInParallel, mergeNext, }?: {
20
+ runInParallel?: boolean;
21
+ mergeNext?: boolean;
22
+ }): OrchestratorBuilder;
23
+ moveAction(actionToMove: string, targetAction: string): OrchestratorBuilder;
24
+ moveAndMergeNextAction(actionToMove: string, targetAction: string): OrchestratorBuilder;
25
+ mergeActions(where: string, ...actions: string[]): this;
26
+ deleteAction(action: string, steps?: InternalStep): this;
27
+ pruneAction(action: string): this;
28
+ protected findStepByAction(action: string, step?: InternalStep): InternalStep | undefined;
29
+ protected findOrThrowStepByAction(action: string, steps?: InternalStep): InternalStep;
30
+ protected findParentStepByAction(action: string, step?: InternalStep): InternalStep | undefined;
31
+ protected findLastStep(steps?: InternalStep): InternalStep;
32
+ protected updateDepths(startingStep: InternalStep, parent: any, incr?: number, beginFrom?: number): void;
33
+ build(): TransactionStepsDefinition;
34
+ }
35
+ export {};
36
+ //# sourceMappingURL=orchestrator-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator-builder.d.ts","sourceRoot":"","sources":["../../src/transaction/orchestrator-builder.ts"],"names":[],"mappings":"AAAA,OAAO,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AAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,mBAAmB;IAI3E,sBAAsB,CACpB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,mBAAmB;IAItB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE;IAgBhD,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,YAAyB;IA6B7D,WAAW,CAAC,MAAM,EAAE,MAAM;IAgB1B,SAAS,CAAC,gBAAgB,CACxB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,YAAyB,GAC9B,YAAY,GAAG,SAAS;IAmB3B,SAAS,CAAC,uBAAuB,CAC/B,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,YAAyB,GAC/B,YAAY;IASf,SAAS,CAAC,sBAAsB,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,YAAyB,GAC9B,YAAY,GAAG,SAAS;IAyB3B,SAAS,CAAC,YAAY,CAAC,KAAK,GAAE,YAAyB,GAAG,YAAY;IAWtE,SAAS,CAAC,YAAY,CACpB,YAAY,EAAE,YAAY,EAC1B,MAAM,KAAA,EACN,IAAI,SAAI,EACR,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI;IAiBP,KAAK,IAAI,0BAA0B;CAuBpC"}
@@ -0,0 +1,300 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrchestratorBuilder = void 0;
4
+ class OrchestratorBuilder {
5
+ get hasChanges() {
6
+ return this.hasChanges_;
7
+ }
8
+ constructor(steps) {
9
+ this.hasChanges_ = false;
10
+ this.load(steps);
11
+ }
12
+ load(steps) {
13
+ this.steps = {
14
+ depth: -1,
15
+ parent: null,
16
+ next: Object.keys(steps ?? {}).length
17
+ ? JSON.parse(JSON.stringify((steps.action ? steps : steps.next)))
18
+ : undefined,
19
+ };
20
+ this.updateDepths(this.steps, {}, 1, -1);
21
+ return this;
22
+ }
23
+ addAction(action, options = {}) {
24
+ const step = this.findLastStep();
25
+ const newAction = {
26
+ action,
27
+ depth: step.depth + 1,
28
+ parent: step.action,
29
+ ...options,
30
+ };
31
+ step.next = newAction;
32
+ this.hasChanges_ = true;
33
+ return this;
34
+ }
35
+ replaceAction(existingAction, action, options = {}) {
36
+ const step = this.findOrThrowStepByAction(existingAction);
37
+ step.action = action;
38
+ Object.assign(step, options);
39
+ this.hasChanges_ = true;
40
+ return this;
41
+ }
42
+ insertActionBefore(existingAction, action, options = {}) {
43
+ const parentStep = this.findParentStepByAction(existingAction);
44
+ if (parentStep) {
45
+ const oldNext = parentStep.next;
46
+ const newDepth = parentStep.depth + 1;
47
+ if (Array.isArray(parentStep.next)) {
48
+ const index = parentStep.next.findIndex((step) => step.action === existingAction);
49
+ if (index > -1) {
50
+ parentStep.next[index] = {
51
+ action,
52
+ ...options,
53
+ next: oldNext[index],
54
+ depth: newDepth,
55
+ };
56
+ }
57
+ }
58
+ else {
59
+ parentStep.next = {
60
+ action,
61
+ ...options,
62
+ next: oldNext,
63
+ depth: newDepth,
64
+ };
65
+ }
66
+ this.updateDepths(oldNext, parentStep);
67
+ }
68
+ this.hasChanges_ = true;
69
+ return this;
70
+ }
71
+ insertActionAfter(existingAction, action, options = {}) {
72
+ const step = this.findOrThrowStepByAction(existingAction);
73
+ const oldNext = step.next;
74
+ const newDepth = step.depth + 1;
75
+ step.next = {
76
+ action,
77
+ ...options,
78
+ next: oldNext,
79
+ depth: newDepth,
80
+ parent: step.action,
81
+ };
82
+ this.updateDepths(oldNext, step.next);
83
+ this.hasChanges_ = true;
84
+ return this;
85
+ }
86
+ appendTo(step, newStep) {
87
+ if (typeof step === "string") {
88
+ step = this.findOrThrowStepByAction(step);
89
+ }
90
+ step.next = {
91
+ ...newStep,
92
+ depth: step.depth + 1,
93
+ parent: step.action,
94
+ };
95
+ this.hasChanges_ = true;
96
+ return this;
97
+ }
98
+ appendAction(action, to, options = {}) {
99
+ const newAction = {
100
+ action,
101
+ ...options,
102
+ };
103
+ const branch = this.findLastStep(this.findStepByAction(to));
104
+ this.appendTo(branch, newAction);
105
+ return this;
106
+ }
107
+ move(actionToMove, targetAction, { runInParallel, mergeNext, } = {
108
+ runInParallel: false,
109
+ mergeNext: false,
110
+ }) {
111
+ const parentActionToMoveStep = this.findParentStepByAction(actionToMove);
112
+ const parentTargetActionStep = this.findParentStepByAction(targetAction);
113
+ const actionToMoveStep = this.findStepByAction(actionToMove, parentTargetActionStep);
114
+ if (!actionToMoveStep) {
115
+ throw new Error(`Action "${actionToMove}" could not be found in the following steps of "${targetAction}"`);
116
+ }
117
+ if (Array.isArray(parentActionToMoveStep.next)) {
118
+ const index = parentActionToMoveStep.next.findIndex((step) => step.action === actionToMove);
119
+ if (index > -1) {
120
+ parentActionToMoveStep.next.splice(index, 1);
121
+ }
122
+ }
123
+ else {
124
+ delete parentActionToMoveStep.next;
125
+ }
126
+ if (runInParallel) {
127
+ if (Array.isArray(parentTargetActionStep.next)) {
128
+ parentTargetActionStep.next.push(actionToMoveStep);
129
+ }
130
+ else if (parentTargetActionStep.next) {
131
+ parentTargetActionStep.next = [
132
+ parentTargetActionStep.next,
133
+ actionToMoveStep,
134
+ ];
135
+ }
136
+ }
137
+ else {
138
+ if (actionToMoveStep.next) {
139
+ if (mergeNext) {
140
+ if (Array.isArray(actionToMoveStep.next)) {
141
+ actionToMoveStep.next.push(parentTargetActionStep.next);
142
+ }
143
+ else {
144
+ actionToMoveStep.next = [
145
+ actionToMoveStep.next,
146
+ parentTargetActionStep.next,
147
+ ];
148
+ }
149
+ }
150
+ else {
151
+ this.appendTo(this.findLastStep(actionToMoveStep), parentTargetActionStep.next);
152
+ }
153
+ }
154
+ else {
155
+ actionToMoveStep.next = parentTargetActionStep.next;
156
+ }
157
+ parentTargetActionStep.next = actionToMoveStep;
158
+ }
159
+ this.updateDepths(actionToMoveStep, parentTargetActionStep, 1, parentTargetActionStep.depth);
160
+ this.hasChanges_ = true;
161
+ return this;
162
+ }
163
+ moveAction(actionToMove, targetAction) {
164
+ return this.move(actionToMove, targetAction);
165
+ }
166
+ moveAndMergeNextAction(actionToMove, targetAction) {
167
+ return this.move(actionToMove, targetAction, { mergeNext: true });
168
+ }
169
+ mergeActions(where, ...actions) {
170
+ actions.unshift(where);
171
+ if (actions.length < 2) {
172
+ throw new Error("Cannot merge less than two actions");
173
+ }
174
+ for (const action of actions) {
175
+ if (action !== where) {
176
+ this.move(action, where, { runInParallel: true });
177
+ }
178
+ }
179
+ return this;
180
+ }
181
+ deleteAction(action, steps = this.steps) {
182
+ const actionStep = this.findOrThrowStepByAction(action);
183
+ const parentStep = this.findParentStepByAction(action, steps);
184
+ if (Array.isArray(parentStep.next)) {
185
+ const index = parentStep.next.findIndex((step) => step.action === action);
186
+ if (index > -1 && actionStep.next) {
187
+ if (actionStep.next) {
188
+ parentStep.next[index] = actionStep.next;
189
+ }
190
+ else {
191
+ parentStep.next.splice(index, 1);
192
+ }
193
+ }
194
+ }
195
+ else {
196
+ parentStep.next = actionStep.next;
197
+ }
198
+ this.updateDepths(actionStep.next, parentStep, 1, parentStep.depth);
199
+ this.hasChanges_ = true;
200
+ return this;
201
+ }
202
+ pruneAction(action) {
203
+ const parentStep = this.findParentStepByAction(action, this.steps);
204
+ if (Array.isArray(parentStep.next)) {
205
+ const index = parentStep.next.findIndex((step) => step.action === action);
206
+ if (index > -1) {
207
+ parentStep.next.splice(index, 1);
208
+ }
209
+ }
210
+ else {
211
+ delete parentStep.next;
212
+ }
213
+ this.hasChanges_ = true;
214
+ return this;
215
+ }
216
+ findStepByAction(action, step = this.steps) {
217
+ if (step.uuid === action || step.action === action) {
218
+ return step;
219
+ }
220
+ if (Array.isArray(step.next)) {
221
+ for (const subStep of step.next) {
222
+ const found = this.findStepByAction(action, subStep);
223
+ if (found) {
224
+ return found;
225
+ }
226
+ }
227
+ }
228
+ else if (step.next && typeof step.next === "object") {
229
+ return this.findStepByAction(action, step.next);
230
+ }
231
+ return;
232
+ }
233
+ findOrThrowStepByAction(action, steps = this.steps) {
234
+ const step = this.findStepByAction(action, steps);
235
+ if (!step) {
236
+ throw new Error(`Action "${action}" could not be found`);
237
+ }
238
+ return step;
239
+ }
240
+ findParentStepByAction(action, step = this.steps) {
241
+ if (!step.next) {
242
+ return;
243
+ }
244
+ const nextSteps = Array.isArray(step.next) ? step.next : [step.next];
245
+ for (const nextStep of nextSteps) {
246
+ if (!nextStep) {
247
+ continue;
248
+ }
249
+ if (nextStep.uuid === action || nextStep.action === action) {
250
+ return step;
251
+ }
252
+ const foundStep = this.findParentStepByAction(action, nextStep);
253
+ if (foundStep) {
254
+ return foundStep;
255
+ }
256
+ }
257
+ return;
258
+ }
259
+ findLastStep(steps = this.steps) {
260
+ let step = steps;
261
+ while (step.next) {
262
+ step = Array.isArray(step.next)
263
+ ? step.next[step.next.length - 1]
264
+ : step.next;
265
+ }
266
+ return step;
267
+ }
268
+ updateDepths(startingStep, parent, incr = 1, beginFrom) {
269
+ if (!startingStep) {
270
+ return;
271
+ }
272
+ const update = (step, parent, beginFrom) => {
273
+ step.depth = beginFrom + incr;
274
+ step.parent = parent.action;
275
+ if (Array.isArray(step.next)) {
276
+ step.next.forEach((nextAction) => update(nextAction, step, step.depth));
277
+ }
278
+ else if (step.next) {
279
+ update(step.next, step, step.depth);
280
+ }
281
+ };
282
+ update(startingStep, parent, beginFrom ?? startingStep.depth);
283
+ }
284
+ build() {
285
+ if (!this.steps.next) {
286
+ return {};
287
+ }
288
+ const ignore = ["depth", "parent"];
289
+ const result = JSON.parse(JSON.stringify(Array.isArray(this.steps.next) ? this.steps : this.steps.next, null), (key, value) => {
290
+ if (ignore.includes(key)) {
291
+ return;
292
+ }
293
+ return value;
294
+ });
295
+ this.hasChanges_ = false;
296
+ return result;
297
+ }
298
+ }
299
+ exports.OrchestratorBuilder = OrchestratorBuilder;
300
+ //# sourceMappingURL=orchestrator-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator-builder.js","sourceRoot":"","sources":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AAC,CAAA;QAClC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CACvB,IAAI,CAAC,SAAS,CACZ,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAC7D,IAAI,CACL,EACD,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACb,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,OAAM;YACR,CAAC;YAED,OAAO,KAAK,CAAA;QACd,CAAC,CACF,CAAA;QAED,IAAI,CAAC,WAAW,GAAG,KAAK,CAAA;QACxB,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAvaD,kDAuaC"}
@@ -0,0 +1,118 @@
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 flagStepsToRevert;
62
+ private static setStepSuccess;
63
+ private static skipStep;
64
+ private static setStepTimeout;
65
+ private static setStepFailure;
66
+ private executeNext;
67
+ /**
68
+ * Start a new transaction or resume a transaction that has been previously started
69
+ * @param transaction - The transaction to resume
70
+ */
71
+ resume(transaction: DistributedTransactionType): Promise<void>;
72
+ /**
73
+ * Cancel and revert a transaction compensating all its executed steps. It can be an ongoing transaction or a completed one
74
+ * @param transaction - The transaction to be reverted
75
+ */
76
+ cancelTransaction(transaction: DistributedTransactionType): Promise<void>;
77
+ private parseFlowOptions;
78
+ private createTransactionFlow;
79
+ private static loadTransactionById;
80
+ private static buildSteps;
81
+ /** Create a new transaction
82
+ * @param transactionId - unique identifier of the transaction
83
+ * @param handler - function to handle action of the transaction
84
+ * @param payload - payload to be passed to all the transaction steps
85
+ * @param flowMetadata - flow metadata which can include event group id for example
86
+ */
87
+ beginTransaction(transactionId: string, handler: TransactionStepHandler, payload?: unknown, flowMetadata?: TransactionFlow["metadata"]): Promise<DistributedTransactionType>;
88
+ /** Returns an existing transaction
89
+ * @param transactionId - unique identifier of the transaction
90
+ * @param handler - function to handle action of the transaction
91
+ */
92
+ retrieveExistingTransaction(transactionId: string, handler: TransactionStepHandler): Promise<DistributedTransactionType>;
93
+ private static getStepByAction;
94
+ private static getTransactionAndStepFromIdempotencyKey;
95
+ /** Skip the execution of a specific transaction and step
96
+ * @param responseIdempotencyKey - The idempotency key for the step
97
+ * @param handler - The handler function to execute the step
98
+ * @param transaction - The current transaction. If not provided it will be loaded based on the responseIdempotencyKey
99
+ */
100
+ skipStep(responseIdempotencyKey: string, handler?: TransactionStepHandler, transaction?: DistributedTransactionType): Promise<DistributedTransactionType>;
101
+ /** Register a step success for a specific transaction and step
102
+ * @param responseIdempotencyKey - The idempotency key for the step
103
+ * @param handler - The handler function to execute the step
104
+ * @param transaction - The current transaction. If not provided it will be loaded based on the responseIdempotencyKey
105
+ * @param response - The response of the step
106
+ */
107
+ registerStepSuccess(responseIdempotencyKey: string, handler?: TransactionStepHandler, transaction?: DistributedTransactionType, response?: unknown): Promise<DistributedTransactionType>;
108
+ /**
109
+ * Register a step failure for a specific transaction and step
110
+ * @param responseIdempotencyKey - The idempotency key for the step
111
+ * @param error - The error that caused the failure
112
+ * @param handler - The handler function to execute the step
113
+ * @param transaction - The current transaction
114
+ * @param response - The response of the step
115
+ */
116
+ registerStepFailure(responseIdempotencyKey: string, error?: Error | any, handler?: TransactionStepHandler, transaction?: DistributedTransactionType): Promise<DistributedTransactionType>;
117
+ }
118
+ //# 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;AAUhB,OAAO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