nestjs-serverless-workflow 0.0.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 (127) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +396 -0
  3. package/dist/adapter/index.d.ts +2 -0
  4. package/dist/adapter/index.d.ts.map +1 -0
  5. package/dist/adapter/index.js +2 -0
  6. package/dist/adapter/index.js.map +1 -0
  7. package/dist/adapter/lambda.adapater.d.ts +4 -0
  8. package/dist/adapter/lambda.adapater.d.ts.map +1 -0
  9. package/dist/adapter/lambda.adapater.js +63 -0
  10. package/dist/adapter/lambda.adapater.js.map +1 -0
  11. package/dist/event-bus/index.d.ts +3 -0
  12. package/dist/event-bus/index.d.ts.map +1 -0
  13. package/dist/event-bus/index.js +3 -0
  14. package/dist/event-bus/index.js.map +1 -0
  15. package/dist/event-bus/sqs/sqs.emitter.d.ts +6 -0
  16. package/dist/event-bus/sqs/sqs.emitter.d.ts.map +1 -0
  17. package/dist/event-bus/sqs/sqs.emitter.js +4 -0
  18. package/dist/event-bus/sqs/sqs.emitter.js.map +1 -0
  19. package/dist/event-bus/types/broker-publisher.interface.d.ts +5 -0
  20. package/dist/event-bus/types/broker-publisher.interface.d.ts.map +1 -0
  21. package/dist/event-bus/types/broker-publisher.interface.js +2 -0
  22. package/dist/event-bus/types/broker-publisher.interface.js.map +1 -0
  23. package/dist/event-bus/types/index.d.ts +3 -0
  24. package/dist/event-bus/types/index.d.ts.map +1 -0
  25. package/dist/event-bus/types/index.js +3 -0
  26. package/dist/event-bus/types/index.js.map +1 -0
  27. package/dist/event-bus/types/workflow-event.interface.d.ts +7 -0
  28. package/dist/event-bus/types/workflow-event.interface.d.ts.map +1 -0
  29. package/dist/event-bus/types/workflow-event.interface.js +2 -0
  30. package/dist/event-bus/types/workflow-event.interface.js.map +1 -0
  31. package/dist/exception/index.d.ts +2 -0
  32. package/dist/exception/index.d.ts.map +1 -0
  33. package/dist/exception/index.js +2 -0
  34. package/dist/exception/index.js.map +1 -0
  35. package/dist/exception/unretriable.exception.d.ts +4 -0
  36. package/dist/exception/unretriable.exception.d.ts.map +1 -0
  37. package/dist/exception/unretriable.exception.js +7 -0
  38. package/dist/exception/unretriable.exception.js.map +1 -0
  39. package/dist/workflow/decorators/default.decorator.d.ts +3 -0
  40. package/dist/workflow/decorators/default.decorator.d.ts.map +1 -0
  41. package/dist/workflow/decorators/default.decorator.js +9 -0
  42. package/dist/workflow/decorators/default.decorator.js.map +1 -0
  43. package/dist/workflow/decorators/event.decorator.d.ts +5 -0
  44. package/dist/workflow/decorators/event.decorator.d.ts.map +1 -0
  45. package/dist/workflow/decorators/event.decorator.js +20 -0
  46. package/dist/workflow/decorators/event.decorator.js.map +1 -0
  47. package/dist/workflow/decorators/index.d.ts +6 -0
  48. package/dist/workflow/decorators/index.d.ts.map +1 -0
  49. package/dist/workflow/decorators/index.js +6 -0
  50. package/dist/workflow/decorators/index.js.map +1 -0
  51. package/dist/workflow/decorators/params.decorator.d.ts +3 -0
  52. package/dist/workflow/decorators/params.decorator.d.ts.map +1 -0
  53. package/dist/workflow/decorators/params.decorator.js +19 -0
  54. package/dist/workflow/decorators/params.decorator.js.map +1 -0
  55. package/dist/workflow/decorators/with-retry.decorator.d.ts +4 -0
  56. package/dist/workflow/decorators/with-retry.decorator.d.ts.map +1 -0
  57. package/dist/workflow/decorators/with-retry.decorator.js +9 -0
  58. package/dist/workflow/decorators/with-retry.decorator.js.map +1 -0
  59. package/dist/workflow/decorators/workflow.decorator.d.ts +6 -0
  60. package/dist/workflow/decorators/workflow.decorator.d.ts.map +1 -0
  61. package/dist/workflow/decorators/workflow.decorator.js +8 -0
  62. package/dist/workflow/decorators/workflow.decorator.js.map +1 -0
  63. package/dist/workflow/index.d.ts +7 -0
  64. package/dist/workflow/index.d.ts.map +1 -0
  65. package/dist/workflow/index.js +7 -0
  66. package/dist/workflow/index.js.map +1 -0
  67. package/dist/workflow/providers/index.d.ts +4 -0
  68. package/dist/workflow/providers/index.d.ts.map +1 -0
  69. package/dist/workflow/providers/index.js +4 -0
  70. package/dist/workflow/providers/index.js.map +1 -0
  71. package/dist/workflow/providers/ochestrator.service.d.ts +32 -0
  72. package/dist/workflow/providers/ochestrator.service.d.ts.map +1 -0
  73. package/dist/workflow/providers/ochestrator.service.js +183 -0
  74. package/dist/workflow/providers/ochestrator.service.js.map +1 -0
  75. package/dist/workflow/providers/router.factory.d.ts +7 -0
  76. package/dist/workflow/providers/router.factory.d.ts.map +1 -0
  77. package/dist/workflow/providers/router.factory.js +18 -0
  78. package/dist/workflow/providers/router.factory.js.map +1 -0
  79. package/dist/workflow/providers/router.service.d.ts +16 -0
  80. package/dist/workflow/providers/router.service.d.ts.map +1 -0
  81. package/dist/workflow/providers/router.service.js +79 -0
  82. package/dist/workflow/providers/router.service.js.map +1 -0
  83. package/dist/workflow/providers/saga.service.d.ts +34 -0
  84. package/dist/workflow/providers/saga.service.d.ts.map +1 -0
  85. package/dist/workflow/providers/saga.service.js +159 -0
  86. package/dist/workflow/providers/saga.service.js.map +1 -0
  87. package/dist/workflow/types/entity.interface.d.ts +33 -0
  88. package/dist/workflow/types/entity.interface.d.ts.map +1 -0
  89. package/dist/workflow/types/entity.interface.js +2 -0
  90. package/dist/workflow/types/entity.interface.js.map +1 -0
  91. package/dist/workflow/types/index.d.ts +7 -0
  92. package/dist/workflow/types/index.d.ts.map +1 -0
  93. package/dist/workflow/types/index.js +9 -0
  94. package/dist/workflow/types/index.js.map +1 -0
  95. package/dist/workflow/types/retry.interface.d.ts +24 -0
  96. package/dist/workflow/types/retry.interface.d.ts.map +1 -0
  97. package/dist/workflow/types/retry.interface.js +10 -0
  98. package/dist/workflow/types/retry.interface.js.map +1 -0
  99. package/dist/workflow/types/saga.interface.d.ts +144 -0
  100. package/dist/workflow/types/saga.interface.d.ts.map +1 -0
  101. package/dist/workflow/types/saga.interface.js +24 -0
  102. package/dist/workflow/types/saga.interface.js.map +1 -0
  103. package/dist/workflow/types/shared.type.d.ts +5 -0
  104. package/dist/workflow/types/shared.type.d.ts.map +1 -0
  105. package/dist/workflow/types/shared.type.js +2 -0
  106. package/dist/workflow/types/shared.type.js.map +1 -0
  107. package/dist/workflow/types/transition-event.interface.d.ts +16 -0
  108. package/dist/workflow/types/transition-event.interface.d.ts.map +1 -0
  109. package/dist/workflow/types/transition-event.interface.js +2 -0
  110. package/dist/workflow/types/transition-event.interface.js.map +1 -0
  111. package/dist/workflow/types/workflow-definition.interface.d.ts +60 -0
  112. package/dist/workflow/types/workflow-definition.interface.d.ts.map +1 -0
  113. package/dist/workflow/types/workflow-definition.interface.js +2 -0
  114. package/dist/workflow/types/workflow-definition.interface.js.map +1 -0
  115. package/dist/workflow/utils/index.d.ts +2 -0
  116. package/dist/workflow/utils/index.d.ts.map +1 -0
  117. package/dist/workflow/utils/index.js +2 -0
  118. package/dist/workflow/utils/index.js.map +1 -0
  119. package/dist/workflow/utils/retry-backoff.d.ts +35 -0
  120. package/dist/workflow/utils/retry-backoff.d.ts.map +1 -0
  121. package/dist/workflow/utils/retry-backoff.js +68 -0
  122. package/dist/workflow/utils/retry-backoff.js.map +1 -0
  123. package/dist/workflow/workflow.module.d.ts +13 -0
  124. package/dist/workflow/workflow.module.d.ts.map +1 -0
  125. package/dist/workflow/workflow.module.js +27 -0
  126. package/dist/workflow/workflow.module.js.map +1 -0
  127. package/package.json +154 -0
@@ -0,0 +1,34 @@
1
+ import type { IBrokerPublisher } from '@/event-bus';
2
+ import type { SagaContext, ISagaConfig, IWorkflowDefinition, ISagaHistoryStore } from '@/workflow';
3
+ export declare class SagaService {
4
+ private readonly logger;
5
+ /**
6
+ * Initialize a new SAGA context when workflow starts
7
+ */
8
+ initializeSaga<T>(entity: T, definition: IWorkflowDefinition<T, any, any>, historyService: ISagaHistoryStore<T>): Promise<SagaContext<T>>;
9
+ /**
10
+ * Record a successful step execution
11
+ */
12
+ recordStep<T, P>(context: SagaContext<T>, event: string, beforeState: T, afterState: T, payload: P, historyService: ISagaHistoryStore<T>): Promise<void>;
13
+ /**
14
+ * Mark SAGA as failed and prepare for compensation
15
+ */
16
+ markSagaFailed<T>(context: SagaContext<T>, error: Error, historyService: ISagaHistoryStore<T>): Promise<void>;
17
+ /**
18
+ * Execute compensations based on the rollback strategy
19
+ */
20
+ executeCompensations<T>(context: SagaContext<T>, sagaConfig: ISagaConfig, compensationHandlers: Map<string, Function>, instance: any, brokerPublisher: IBrokerPublisher, historyService: ISagaHistoryStore<T>): Promise<void>;
21
+ /**
22
+ * Execute compensations in order (reversed or in-order)
23
+ */
24
+ private executeReversedCompensations;
25
+ /**
26
+ * Execute all compensations in parallel
27
+ */
28
+ private executeParallelCompensations;
29
+ /**
30
+ * Resume a SAGA from a checkpoint (for replay scenarios)
31
+ */
32
+ resumeSaga<T>(sagaId: string, historyService: ISagaHistoryStore<T>): Promise<SagaContext<T> | null>;
33
+ }
34
+ //# sourceMappingURL=saga.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saga.service.d.ts","sourceRoot":"","sources":["../../../src/workflow/providers/saga.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAa,WAAW,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG9G,qBACa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IAEvD;;OAEG;IACG,cAAc,CAAC,CAAC,EACpB,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAC5C,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACnC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAqB1B;;OAEG;IACG,UAAU,CAAC,CAAC,EAAE,CAAC,EACnB,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,CAAC,EACd,UAAU,EAAE,CAAC,EACb,OAAO,EAAE,CAAC,EACV,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC;IAehB;;OAEG;IACG,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnH;;OAEG;IACG,oBAAoB,CAAC,CAAC,EAC1B,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,UAAU,EAAE,WAAW,EACvB,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAC3C,QAAQ,EAAE,GAAG,EACb,eAAe,EAAE,gBAAgB,EACjC,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC;IAoDhB;;OAEG;YACW,4BAA4B;IAoC1C;;OAEG;YACW,4BAA4B;IA4B1C;;OAEG;IACG,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAU1G"}
@@ -0,0 +1,159 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var SagaService_1;
8
+ import { Injectable, Logger } from '@nestjs/common';
9
+ import { RollbackStrategy, SagaStatus } from '@/workflow';
10
+ let SagaService = SagaService_1 = class SagaService {
11
+ constructor() {
12
+ this.logger = new Logger(SagaService_1.name);
13
+ }
14
+ /**
15
+ * Initialize a new SAGA context when workflow starts
16
+ */
17
+ async initializeSaga(entity, definition, historyService) {
18
+ const sagaId = definition.saga?.sagaIdGenerator
19
+ ? definition.saga.sagaIdGenerator()
20
+ : `saga-${Date.now()}-${Math.random()}`;
21
+ const context = {
22
+ sagaId,
23
+ entity,
24
+ executedSteps: [],
25
+ status: SagaStatus.RUNNING,
26
+ startedAt: new Date(),
27
+ metadata: {
28
+ workflowName: definition.name,
29
+ },
30
+ };
31
+ await historyService.saveSagaContext(context);
32
+ this.logger.log(`SAGA initialized: ${sagaId}`);
33
+ return context;
34
+ }
35
+ /**
36
+ * Record a successful step execution
37
+ */
38
+ async recordStep(context, event, beforeState, afterState, payload, historyService) {
39
+ const step = {
40
+ event,
41
+ executedAt: new Date(),
42
+ beforeState,
43
+ afterState,
44
+ payload,
45
+ compensated: false,
46
+ };
47
+ context.executedSteps.push(step);
48
+ await historyService.saveSagaContext(context);
49
+ this.logger.log(`SAGA step recorded: ${event} (${context.sagaId})`);
50
+ }
51
+ /**
52
+ * Mark SAGA as failed and prepare for compensation
53
+ */
54
+ async markSagaFailed(context, error, historyService) {
55
+ context.status = SagaStatus.COMPENSATING;
56
+ context.error = error;
57
+ await historyService.saveSagaContext(context);
58
+ this.logger.error(`SAGA failed: ${context.sagaId}. Error: ${error.message}`);
59
+ }
60
+ /**
61
+ * Execute compensations based on the rollback strategy
62
+ */
63
+ async executeCompensations(context, sagaConfig, compensationHandlers, instance, brokerPublisher, historyService) {
64
+ this.logger.log(`Starting compensations for SAGA: ${context.sagaId}`);
65
+ const stepsToCompensate = context.executedSteps.filter((step) => !step.compensated);
66
+ try {
67
+ switch (sagaConfig.rollbackStrategy) {
68
+ case RollbackStrategy.REVERSE_ORDER:
69
+ await this.executeReversedCompensations(stepsToCompensate.reverse(), compensationHandlers, instance, context, sagaConfig.failFast ?? false, historyService);
70
+ break;
71
+ case RollbackStrategy.IN_ORDER:
72
+ await this.executeReversedCompensations(stepsToCompensate, compensationHandlers, instance, context, sagaConfig.failFast ?? false, historyService);
73
+ break;
74
+ case RollbackStrategy.PARALLEL:
75
+ await this.executeParallelCompensations(stepsToCompensate, compensationHandlers, instance, context, historyService);
76
+ break;
77
+ }
78
+ context.status = SagaStatus.COMPENSATED;
79
+ context.completedAt = new Date();
80
+ await historyService.saveSagaContext(context);
81
+ this.logger.log(`SAGA compensations completed: ${context.sagaId}`);
82
+ }
83
+ catch (error) {
84
+ context.status = SagaStatus.FAILED;
85
+ await historyService.saveSagaContext(context);
86
+ this.logger.error(`SAGA compensation failed: ${context.sagaId}`, error);
87
+ throw error;
88
+ }
89
+ }
90
+ /**
91
+ * Execute compensations in order (reversed or in-order)
92
+ */
93
+ async executeReversedCompensations(steps, compensationHandlers, instance, context, failFast, historyService) {
94
+ const errors = [];
95
+ for (const step of steps) {
96
+ const compensationHandler = compensationHandlers.get(step.event);
97
+ if (!compensationHandler) {
98
+ this.logger.warn(`No compensation handler found for event: ${step.event}`);
99
+ continue;
100
+ }
101
+ try {
102
+ this.logger.log(`Executing compensation for: ${step.event}`);
103
+ await compensationHandler.apply(instance, [step.beforeState, step.payload]);
104
+ step.compensated = true;
105
+ await historyService.saveSagaContext(context);
106
+ }
107
+ catch (error) {
108
+ this.logger.error(`Compensation failed for ${step.event}:`, error);
109
+ errors.push(error);
110
+ if (failFast) {
111
+ throw error;
112
+ }
113
+ }
114
+ }
115
+ if (errors.length > 0 && !failFast) {
116
+ throw new Error(`${errors.length} compensation(s) failed`);
117
+ }
118
+ }
119
+ /**
120
+ * Execute all compensations in parallel
121
+ */
122
+ async executeParallelCompensations(steps, compensationHandlers, instance, context, historyService) {
123
+ const compensationPromises = steps.map(async (step) => {
124
+ const compensationHandler = compensationHandlers.get(step.event);
125
+ if (!compensationHandler) {
126
+ this.logger.warn(`No compensation handler found for event: ${step.event}`);
127
+ return;
128
+ }
129
+ try {
130
+ this.logger.log(`Executing compensation for: ${step.event}`);
131
+ await compensationHandler.apply(instance, [step.beforeState, step.payload]);
132
+ step.compensated = true;
133
+ }
134
+ catch (error) {
135
+ this.logger.error(`Compensation failed for ${step.event}:`, error);
136
+ throw error;
137
+ }
138
+ });
139
+ await Promise.all(compensationPromises);
140
+ await historyService.saveSagaContext(context);
141
+ }
142
+ /**
143
+ * Resume a SAGA from a checkpoint (for replay scenarios)
144
+ */
145
+ async resumeSaga(sagaId, historyService) {
146
+ const context = await historyService.getSagaContext(sagaId);
147
+ if (!context) {
148
+ this.logger.warn(`No SAGA context found for: ${sagaId}`);
149
+ return null;
150
+ }
151
+ this.logger.log(`Resuming SAGA: ${sagaId}, status: ${context.status}`);
152
+ return context;
153
+ }
154
+ };
155
+ SagaService = SagaService_1 = __decorate([
156
+ Injectable()
157
+ ], SagaService);
158
+ export { SagaService };
159
+ //# sourceMappingURL=saga.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saga.service.js","sourceRoot":"","sources":["../../../src/workflow/providers/saga.service.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnD,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAAjB;QACY,WAAM,GAAG,IAAI,MAAM,CAAC,aAAW,CAAC,IAAI,CAAC,CAAC;IAkNzD,CAAC;IAhNC;;OAEG;IACH,KAAK,CAAC,cAAc,CAClB,MAAS,EACT,UAA4C,EAC5C,cAAoC;QAEpC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,EAAE,eAAe;YAC7C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,EAAE;YACnC,CAAC,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAA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AAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAI,MAAc,EAAE,cAAoC;QACtE,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC;YACzD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,MAAM,aAAa,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACvE,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAnNY,WAAW;IADvB,UAAU,EAAE;GACA,WAAW,CAmNvB"}
@@ -0,0 +1,33 @@
1
+ export interface IWorkflowEntity<T = any, State = string | number> {
2
+ /**
3
+ * Creates a new instance of the entity
4
+ * @returns A new entity instance
5
+ */
6
+ create(): Promise<T>;
7
+ /**
8
+ * Updates the status of an entity
9
+ * @param entity The entity to update
10
+ * @param status The new status
11
+ * @returns The updated entity
12
+ */
13
+ update(entity: T, status: State): Promise<T>;
14
+ /**
15
+ * Loads an entity by its URN
16
+ * @param urn The unique resource name of the entity
17
+ * @returns The loaded entity
18
+ */
19
+ load(urn: string | number): Promise<T | null>;
20
+ /**
21
+ * Gets the current status of an entity
22
+ * @param entity The entity
23
+ * @returns The current status
24
+ */
25
+ status(entity: T): State;
26
+ /**
27
+ * Gets the URN of an entity
28
+ * @param entity The entity
29
+ * @returns The entity's URN
30
+ */
31
+ urn(entity: T): string | number;
32
+ }
33
+ //# sourceMappingURL=entity.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.interface.d.ts","sourceRoot":"","sources":["../../../src/workflow/types/entity.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM;IAC/D;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAErB;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7C;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAE9C;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC;IAEzB;;;;OAIG;IACH,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC;CACjC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=entity.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.interface.js","sourceRoot":"","sources":["../../../src/workflow/types/entity.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export * from './retry.interface';
2
+ export * from './saga.interface';
3
+ export * from './entity.interface';
4
+ export * from './shared.type';
5
+ export * from './transition-event.interface';
6
+ export * from './workflow-definition.interface';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/workflow/types/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,9 @@
1
+ // Files with enums (runtime values)
2
+ export * from './retry.interface';
3
+ export * from './saga.interface';
4
+ // Files with only types
5
+ export * from './entity.interface';
6
+ export * from './shared.type';
7
+ export * from './transition-event.interface';
8
+ export * from './workflow-definition.interface';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/workflow/types/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,wBAAwB;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Retry strategy types
3
+ */
4
+ export declare enum RetryStrategy {
5
+ FIXED = "fixed",
6
+ EXPONENTIAL = "exponential",
7
+ EXPONENTIAL_JITTER = "exponential_jitter"
8
+ }
9
+ /**
10
+ * Retry configuration for workflow steps
11
+ */
12
+ export interface IBackoffRetryConfig {
13
+ handler: string;
14
+ maxAttempts: number;
15
+ strategy?: RetryStrategy;
16
+ initialDelay?: number;
17
+ backoffMultiplier?: number;
18
+ maxDelay?: number;
19
+ jitter?: boolean | number;
20
+ }
21
+ export interface IRetryHandler {
22
+ execute: () => Promise<void>;
23
+ }
24
+ //# sourceMappingURL=retry.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.interface.d.ts","sourceRoot":"","sources":["../../../src/workflow/types/retry.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,aAAa;IACvB,KAAK,UAAU;IACf,WAAW,gBAAgB;IAC3B,kBAAkB,uBAAuB;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Retry strategy types
3
+ */
4
+ export var RetryStrategy;
5
+ (function (RetryStrategy) {
6
+ RetryStrategy["FIXED"] = "fixed";
7
+ RetryStrategy["EXPONENTIAL"] = "exponential";
8
+ RetryStrategy["EXPONENTIAL_JITTER"] = "exponential_jitter";
9
+ })(RetryStrategy || (RetryStrategy = {}));
10
+ //# sourceMappingURL=retry.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.interface.js","sourceRoot":"","sources":["../../../src/workflow/types/retry.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,gCAAe,CAAA;IACf,4CAA2B,CAAA;IAC3B,0DAAyC,CAAA;AAC3C,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB"}
@@ -0,0 +1,144 @@
1
+ export interface ISagaStep<T = any, P = any> {
2
+ /**
3
+ * The original event that triggered this step
4
+ */
5
+ event: string;
6
+ /**
7
+ * Timestamp when step was executed
8
+ */
9
+ executedAt: Date;
10
+ /**
11
+ * The entity state before this step
12
+ */
13
+ beforeState: T;
14
+ /**
15
+ * The entity state after this step
16
+ */
17
+ afterState: T;
18
+ /**
19
+ * Payload used for this step
20
+ */
21
+ payload?: P;
22
+ /**
23
+ * Whether this step has been compensated
24
+ */
25
+ compensated: boolean;
26
+ }
27
+ export interface SagaContext<T = any> {
28
+ /**
29
+ * Unique identifier for the SAGA transaction
30
+ */
31
+ sagaId: string;
32
+ /**
33
+ * The entity being processed
34
+ */
35
+ entity: T;
36
+ /**
37
+ * List of executed steps in chronological order
38
+ */
39
+ executedSteps: ISagaStep<T>[];
40
+ /**
41
+ * Current SAGA status
42
+ */
43
+ status: SagaStatus;
44
+ /**
45
+ * Timestamp when SAGA started
46
+ */
47
+ startedAt: Date;
48
+ /**
49
+ * Timestamp when SAGA completed/failed
50
+ */
51
+ completedAt?: Date;
52
+ /**
53
+ * Error that caused the SAGA to fail (if any)
54
+ */
55
+ error?: Error;
56
+ /**
57
+ * Additional metadata for the SAGA
58
+ */
59
+ metadata?: Record<string, any>;
60
+ }
61
+ export declare enum SagaStatus {
62
+ RUNNING = "running",
63
+ COMPLETED = "completed",
64
+ COMPENSATING = "compensating",
65
+ COMPENSATED = "compensated",
66
+ FAILED = "failed"
67
+ }
68
+ /**
69
+ * NOTE: used in decorator
70
+ */
71
+ export interface ISagaRollbackRule<T = any> {
72
+ /**
73
+ * Condition that triggers this rollback rule
74
+ */
75
+ condition?: (error: Error, context: SagaContext<T>) => boolean;
76
+ /**
77
+ * Whether to stop on first compensation failure
78
+ */
79
+ failFast?: boolean;
80
+ /**
81
+ * Maximum time to wait for all compensations to complete
82
+ */
83
+ timeout?: number;
84
+ }
85
+ export declare enum RollbackStrategy {
86
+ /**
87
+ * Execute compensations in reverse order of execution
88
+ */
89
+ REVERSE_ORDER = "reverse_order",
90
+ /**
91
+ * Execute all compensations in parallel
92
+ */
93
+ PARALLEL = "parallel",
94
+ IN_ORDER = "in_order"
95
+ }
96
+ /**
97
+ * SAGA configuration that can be added to workflow definitions
98
+ */
99
+ export interface ISagaConfig {
100
+ /**
101
+ * Enable SAGA pattern for this workflow
102
+ */
103
+ enabled: boolean;
104
+ /**
105
+ * Selective mode, for type-safe purposes
106
+ */
107
+ mode: 'saga';
108
+ /**
109
+ * Rollback strategy if no specific rules match
110
+ */
111
+ rollbackStrategy: RollbackStrategy;
112
+ /**
113
+ * Maximum time to wait for SAGA completion
114
+ * DEFAULT: 30000 ms
115
+ */
116
+ timeout?: number;
117
+ /**
118
+ *
119
+ */
120
+ failFast?: boolean;
121
+ /**
122
+ * Injection token refer to saga history service that implements ISagaHistoryStore<T>
123
+ */
124
+ historyService: string;
125
+ /**
126
+ * Custom SAGA ID generator
127
+ */
128
+ sagaIdGenerator?: () => string;
129
+ }
130
+ export interface ISagaHistoryStore<T = any> {
131
+ /**
132
+ * Save the current SAGA context state
133
+ */
134
+ saveSagaContext: (context: SagaContext<T>) => Promise<void>;
135
+ /**
136
+ * Retrieve a SAGA context by its ID
137
+ */
138
+ getSagaContext: (sagaId: string) => Promise<SagaContext<T> | null>;
139
+ /**
140
+ * Delete a SAGA context by its ID
141
+ */
142
+ deleteSagaContext: (sagaId: string) => Promise<void>;
143
+ }
144
+ //# sourceMappingURL=saga.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saga.interface.d.ts","sourceRoot":"","sources":["../../../src/workflow/types/saga.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IACzC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,EAAE,IAAI,CAAC;IAEjB;;OAEG;IACH,WAAW,EAAE,CAAC,CAAC;IAEf;;OAEG;IACH,UAAU,EAAE,CAAC,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC;IAEZ;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,CAAC,CAAC;IAEV;;OAEG;IACH,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IAE9B;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC;IAEnB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;IAEhB;;OAEG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,oBAAY,UAAU;IACp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AI,CAAC,CAAC;CACtD"}
@@ -0,0 +1,24 @@
1
+ export var SagaStatus;
2
+ (function (SagaStatus) {
3
+ SagaStatus["RUNNING"] = "running";
4
+ SagaStatus["COMPLETED"] = "completed";
5
+ SagaStatus["COMPENSATING"] = "compensating";
6
+ SagaStatus["COMPENSATED"] = "compensated";
7
+ SagaStatus["FAILED"] = "failed";
8
+ })(SagaStatus || (SagaStatus = {}));
9
+ export var RollbackStrategy;
10
+ (function (RollbackStrategy) {
11
+ /**
12
+ * Execute compensations in reverse order of execution
13
+ */
14
+ RollbackStrategy["REVERSE_ORDER"] = "reverse_order";
15
+ /**
16
+ * Execute all compensations in parallel
17
+ */
18
+ RollbackStrategy["PARALLEL"] = "parallel";
19
+ /* *
20
+ * Exucute compensations in the order of execution
21
+ */
22
+ RollbackStrategy["IN_ORDER"] = "in_order";
23
+ })(RollbackStrategy || (RollbackStrategy = {}));
24
+ //# sourceMappingURL=saga.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saga.interface.js","sourceRoot":"","sources":["../../../src/workflow/types/saga.interface.ts"],"names":[],"mappings":"AA0EA,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,qCAAuB,CAAA;IACvB,2CAA6B,CAAA;IAC7B,yCAA2B,CAAA;IAC3B,+BAAiB,CAAA;AACnB,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB;AAsBD,MAAM,CAAN,IAAY,gBAeX;AAfD,WAAY,gBAAgB;IAC1B;;OAEG;IACH,mDAA+B,CAAA;IAE/B;;OAEG;IACH,yCAAqB,CAAA;IAErB;;OAEG;IACH,yCAAqB,CAAA;AACvB,CAAC,EAfW,gBAAgB,KAAhB,gBAAgB,QAe3B"}
@@ -0,0 +1,5 @@
1
+ export type TWithout<T, U> = {
2
+ [P in Exclude<keyof T, keyof U>]?: never;
3
+ };
4
+ export type TEither<T, U> = T extends object ? (U extends object ? (TWithout<T, U> & U) | (TWithout<U, T> & T) : U) : T;
5
+ //# sourceMappingURL=shared.type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.type.d.ts","sourceRoot":"","sources":["../../../src/workflow/types/shared.type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI;KAAG,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK;CAAE,CAAC;AAG1E,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=shared.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.type.js","sourceRoot":"","sources":["../../../src/workflow/types/shared.type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Defines the structure of a transition event in a workflow definition. This includes the following properties:
3
+ * - `event`: The event that triggers the transition.
4
+ * - `from`: The state that the workflow is transitioning from.
5
+ * - `to`: The state that the workflow is transitioning to.
6
+ * - `conditions`: An optional array of conditions to be checked during the transition.
7
+ * Actions and conditions can be defined as functions that take an entity and an optional payload as arguments or
8
+ * as workflow actions classes that are decorated with the `@OnEvent` and/or `@OnStatusChanged` decorator.
9
+ */
10
+ export interface ITransitionEvent<T, Event, State = string, P = unknown> {
11
+ event: Event;
12
+ from: State[];
13
+ to: State;
14
+ conditions?: ((entity: T, payload?: P) => boolean)[];
15
+ }
16
+ //# sourceMappingURL=transition-event.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transition-event.interface.d.ts","sourceRoot":"","sources":["../../../src/workflow/types/transition-event.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO;IACrE,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,KAAK,EAAE,CAAC;IACd,EAAE,EAAE,KAAK,CAAC;IACV,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,EAAE,CAAC;CACtD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transition-event.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transition-event.interface.js","sourceRoot":"","sources":["../../../src/workflow/types/transition-event.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,60 @@
1
+ import type { IBrokerPublisher } from '@/event-bus';
2
+ import type { IBackoffRetryConfig, ISagaConfig, ISagaHistoryStore, ISagaRollbackRule, ITransitionEvent, IWorkflowEntity } from '@/workflow';
3
+ /**
4
+ * Defines the structure of a workflow definition, which includes the following properties:
5
+ * - `FinalStates`: An array of states that represent the final states of the workflow.
6
+ * - `IdleStates`: An array of states that represent the idle states of the workflow.
7
+ * - `FailedState`: The state that represents a failed state in the workflow.
8
+ * - `Transitions`: An array of transition events that define the allowed transitions between states.
9
+ * - `Fallback`: An optional function that can be used as a fallback when a transition event is not defined.
10
+ * - `Conditions`: An optional array of condition functions.
11
+ * - `Entity`: An optional entity service or configuration for loading/updating entities.
12
+ */
13
+ export interface IWorkflowDefinition<T, Event, State> {
14
+ name: string;
15
+ states: {
16
+ finals: State[];
17
+ idles: State[];
18
+ failed: State;
19
+ };
20
+ transitions: ITransitionEvent<T, Event, State, any>[];
21
+ conditions?: (<P>(entity: T, payload?: P | T | object | string) => boolean)[];
22
+ /**
23
+ * TODO: When serverless function about to timeout, register thsis callback to checkpoint current entity state
24
+ */
25
+ onTimeout?: (<P>(entity: T, event: Event, payload?: P | T | object | string) => Promise<any>)[];
26
+ /**
27
+ * Injection token refer to entity services that implements IWorkflowEntity<T>
28
+ */
29
+ entityService: string;
30
+ /**
31
+ * Injection token refer to broker publisher that implements IBrokerPublisher
32
+ */
33
+ brokerPublisher: string;
34
+ /**
35
+ * Workflow saga configuration
36
+ */
37
+ saga?: ISagaConfig;
38
+ }
39
+ export interface IWorkflowDefaultRoute {
40
+ instance: any;
41
+ definition: IWorkflowDefinition<any, string, string>;
42
+ handlerName: string;
43
+ handler: (...payload: any[]) => Promise<any>;
44
+ defaultHandler?: TDefaultHandler<any>;
45
+ entityService: IWorkflowEntity;
46
+ brokerPublisher: IBrokerPublisher;
47
+ retryConfig?: IBackoffRetryConfig;
48
+ }
49
+ export interface IWorkflowRouteWithSaga extends IWorkflowDefaultRoute {
50
+ sagaConfig?: ISagaRollbackRule;
51
+ historyService?: ISagaHistoryStore;
52
+ }
53
+ export interface IWorkflowHandler {
54
+ event: string;
55
+ name: string;
56
+ handler: (...payload: any[]) => Promise<any>;
57
+ sagaConfig?: ISagaRollbackRule;
58
+ }
59
+ export type TDefaultHandler<T, Event = string> = <P>(entity: T, event: Event, payload?: P | T | object | string) => Promise<T>;
60
+ //# sourceMappingURL=workflow-definition.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-definition.interface.d.ts","sourceRoot":"","sources":["../../../src/workflow/types/workflow-definition.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK;IAClD,IAAI,EAAE,MAAM,CAAC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C;IAC/B,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7C,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,IAAI,CAAC,CAAC,EACjD,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,MAAM,KAC9B,OAAO,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=workflow-definition.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-definition.interface.js","sourceRoot":"","sources":["../../../src/workflow/types/workflow-definition.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './retry-backoff';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/workflow/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './retry-backoff';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/workflow/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}