@8medusa/workflows-sdk 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.
- package/dist/helper/index.d.ts +3 -0
- package/dist/helper/index.d.ts.map +1 -0
- package/dist/helper/index.js +19 -0
- package/dist/helper/index.js.map +1 -0
- package/dist/helper/type.d.ts +66 -0
- package/dist/helper/type.d.ts.map +1 -0
- package/dist/helper/type.js +3 -0
- package/dist/helper/type.js.map +1 -0
- package/dist/helper/workflow-export.d.ts +6 -0
- package/dist/helper/workflow-export.d.ts.map +1 -0
- package/dist/helper/workflow-export.js +253 -0
- package/dist/helper/workflow-export.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/medusa-workflow.d.ts +3 -0
- package/dist/medusa-workflow.d.ts.map +1 -0
- package/dist/medusa-workflow.js +19 -0
- package/dist/medusa-workflow.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/_playground.d.ts +2 -0
- package/dist/utils/_playground.d.ts.map +1 -0
- package/dist/utils/_playground.js +79 -0
- package/dist/utils/_playground.js.map +1 -0
- package/dist/utils/composer/create-hook.d.ts +60 -0
- package/dist/utils/composer/create-hook.d.ts.map +1 -0
- package/dist/utils/composer/create-hook.js +93 -0
- package/dist/utils/composer/create-hook.js.map +1 -0
- package/dist/utils/composer/create-step.d.ts +134 -0
- package/dist/utils/composer/create-step.d.ts.map +1 -0
- package/dist/utils/composer/create-step.js +237 -0
- package/dist/utils/composer/create-step.js.map +1 -0
- package/dist/utils/composer/create-workflow.d.ts +71 -0
- package/dist/utils/composer/create-workflow.d.ts.map +1 -0
- package/dist/utils/composer/create-workflow.js +209 -0
- package/dist/utils/composer/create-workflow.js.map +1 -0
- package/dist/utils/composer/helpers/create-step-handler.d.ts +20 -0
- package/dist/utils/composer/helpers/create-step-handler.d.ts.map +1 -0
- package/dist/utils/composer/helpers/create-step-handler.js +70 -0
- package/dist/utils/composer/helpers/create-step-handler.js.map +1 -0
- package/dist/utils/composer/helpers/index.d.ts +3 -0
- package/dist/utils/composer/helpers/index.d.ts.map +1 -0
- package/dist/utils/composer/helpers/index.js +19 -0
- package/dist/utils/composer/helpers/index.js.map +1 -0
- package/dist/utils/composer/helpers/proxy.d.ts +3 -0
- package/dist/utils/composer/helpers/proxy.d.ts.map +1 -0
- package/dist/utils/composer/helpers/proxy.js +25 -0
- package/dist/utils/composer/helpers/proxy.js.map +1 -0
- package/dist/utils/composer/helpers/resolve-value.d.ts +5 -0
- package/dist/utils/composer/helpers/resolve-value.d.ts.map +1 -0
- package/dist/utils/composer/helpers/resolve-value.js +64 -0
- package/dist/utils/composer/helpers/resolve-value.js.map +1 -0
- package/dist/utils/composer/helpers/step-response.d.ts +126 -0
- package/dist/utils/composer/helpers/step-response.d.ts.map +1 -0
- package/dist/utils/composer/helpers/step-response.js +166 -0
- package/dist/utils/composer/helpers/step-response.js.map +1 -0
- package/dist/utils/composer/helpers/workflow-response.d.ts +20 -0
- package/dist/utils/composer/helpers/workflow-response.d.ts.map +1 -0
- package/dist/utils/composer/helpers/workflow-response.js +16 -0
- package/dist/utils/composer/helpers/workflow-response.js.map +1 -0
- package/dist/utils/composer/index.d.ts +11 -0
- package/dist/utils/composer/index.d.ts.map +1 -0
- package/dist/utils/composer/index.js +27 -0
- package/dist/utils/composer/index.js.map +1 -0
- package/dist/utils/composer/parallelize.d.ts +43 -0
- package/dist/utils/composer/parallelize.d.ts.map +1 -0
- package/dist/utils/composer/parallelize.js +57 -0
- package/dist/utils/composer/parallelize.js.map +1 -0
- package/dist/utils/composer/transform.d.ts +79 -0
- package/dist/utils/composer/transform.d.ts.map +1 -0
- package/dist/utils/composer/transform.js +40 -0
- package/dist/utils/composer/transform.js.map +1 -0
- package/dist/utils/composer/type.d.ts +227 -0
- package/dist/utils/composer/type.d.ts.map +1 -0
- package/dist/utils/composer/type.js +3 -0
- package/dist/utils/composer/type.js.map +1 -0
- package/dist/utils/composer/when.d.ts +58 -0
- package/dist/utils/composer/when.d.ts.map +1 -0
- package/dist/utils/composer/when.js +56 -0
- package/dist/utils/composer/when.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,166 @@
|
|
|
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 _StepResponse___type, _StepResponse_output, _StepResponse_compensateInput;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.StepResponse = void 0;
|
|
16
|
+
const orchestration_1 = require("@8medusa/orchestration");
|
|
17
|
+
const utils_1 = require("@8medusa/utils");
|
|
18
|
+
/**
|
|
19
|
+
* This class is used to create the response returned by a step. A step return its data by returning an instance of `StepResponse`.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam TOutput - The type of the output of the step.
|
|
22
|
+
* @typeParam TCompensateInput -
|
|
23
|
+
* The type of the compensation input. If the step doesn't specify any compensation input, then the type of `TCompensateInput` is the same
|
|
24
|
+
* as that of `TOutput`.
|
|
25
|
+
*/
|
|
26
|
+
class StepResponse {
|
|
27
|
+
/**
|
|
28
|
+
* The constructor of the StepResponse
|
|
29
|
+
*
|
|
30
|
+
* @typeParam TOutput - The type of the output of the step.
|
|
31
|
+
* @typeParam TCompensateInput -
|
|
32
|
+
* The type of the compensation input. If the step doesn't specify any compensation input, then the type of `TCompensateInput` is the same
|
|
33
|
+
* as that of `TOutput`.
|
|
34
|
+
*/
|
|
35
|
+
constructor(
|
|
36
|
+
/**
|
|
37
|
+
* The output of the step.
|
|
38
|
+
*/
|
|
39
|
+
output,
|
|
40
|
+
/**
|
|
41
|
+
* The input to be passed as a parameter to the step's compensation function. If not provided, the `output` will be provided instead.
|
|
42
|
+
*/
|
|
43
|
+
compensateInput) {
|
|
44
|
+
_StepResponse___type.set(this, utils_1.OrchestrationUtils.SymbolWorkflowStepResponse);
|
|
45
|
+
_StepResponse_output.set(this, void 0);
|
|
46
|
+
_StepResponse_compensateInput.set(this, void 0);
|
|
47
|
+
if ((0, utils_1.isDefined)(output)) {
|
|
48
|
+
__classPrivateFieldSet(this, _StepResponse_output, output, "f");
|
|
49
|
+
}
|
|
50
|
+
__classPrivateFieldSet(this, _StepResponse_compensateInput, (compensateInput ?? output), "f");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a StepResponse that indicates that the step has failed and the retry mechanism should not kick in anymore.
|
|
54
|
+
*
|
|
55
|
+
* @param message - An optional message to be logged.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* import { Product } from "@8medusa/medusa"
|
|
59
|
+
* import {
|
|
60
|
+
* createStep,
|
|
61
|
+
* StepResponse,
|
|
62
|
+
* createWorkflow
|
|
63
|
+
* } from "@8medusa/workflows-sdk"
|
|
64
|
+
*
|
|
65
|
+
* interface CreateProductInput {
|
|
66
|
+
* title: string
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* export const createProductStep = createStep(
|
|
70
|
+
* "createProductStep",
|
|
71
|
+
* async function (
|
|
72
|
+
* input: CreateProductInput,
|
|
73
|
+
* context
|
|
74
|
+
* ) {
|
|
75
|
+
* const productService = context.container.resolve(
|
|
76
|
+
* "productService"
|
|
77
|
+
* )
|
|
78
|
+
*
|
|
79
|
+
* try {
|
|
80
|
+
* const product = await productService.createProducts(input)
|
|
81
|
+
* return new StepResponse({
|
|
82
|
+
* product
|
|
83
|
+
* }, {
|
|
84
|
+
* product_id: product.id
|
|
85
|
+
* })
|
|
86
|
+
* } catch (e) {
|
|
87
|
+
* return StepResponse.permanentFailure(`Couldn't create the product: ${e}`)
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
* )
|
|
91
|
+
*
|
|
92
|
+
* interface WorkflowInput {
|
|
93
|
+
* title: string
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* const myWorkflow = createWorkflow<
|
|
97
|
+
* WorkflowInput,
|
|
98
|
+
* Product
|
|
99
|
+
* >("my-workflow", (input) => {
|
|
100
|
+
* // Everything here will be executed and resolved later
|
|
101
|
+
* // during the execution. Including the data access.
|
|
102
|
+
*
|
|
103
|
+
* const product = createProductStep(input)
|
|
104
|
+
* }
|
|
105
|
+
* )
|
|
106
|
+
*
|
|
107
|
+
* myWorkflow()
|
|
108
|
+
* .run({
|
|
109
|
+
* input: {
|
|
110
|
+
* title: "Shirt"
|
|
111
|
+
* }
|
|
112
|
+
* })
|
|
113
|
+
* .then(({ errors, result }) => {
|
|
114
|
+
* if (errors.length) {
|
|
115
|
+
* errors.forEach((err) => {
|
|
116
|
+
* if (typeof err.error === "object" && "message" in err.error) {
|
|
117
|
+
* console.error(err.error.message)
|
|
118
|
+
* } else {
|
|
119
|
+
* console.error(err.error)
|
|
120
|
+
* }
|
|
121
|
+
* })
|
|
122
|
+
* }
|
|
123
|
+
* console.log(result)
|
|
124
|
+
* })
|
|
125
|
+
*/
|
|
126
|
+
static permanentFailure(message = "Permanent failure", compensateInput) {
|
|
127
|
+
const response = (0, utils_1.isDefined)(compensateInput)
|
|
128
|
+
? new StepResponse(compensateInput)
|
|
129
|
+
: undefined;
|
|
130
|
+
throw new orchestration_1.PermanentStepFailureError(message, response);
|
|
131
|
+
}
|
|
132
|
+
static skip() {
|
|
133
|
+
return new orchestration_1.SkipStepResponse();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
get __type() {
|
|
139
|
+
return __classPrivateFieldGet(this, _StepResponse___type, "f");
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
get output() {
|
|
145
|
+
return __classPrivateFieldGet(this, _StepResponse_output, "f");
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
get compensateInput() {
|
|
151
|
+
return __classPrivateFieldGet(this, _StepResponse_compensateInput, "f");
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
toJSON() {
|
|
157
|
+
return {
|
|
158
|
+
__type: __classPrivateFieldGet(this, _StepResponse___type, "f"),
|
|
159
|
+
output: __classPrivateFieldGet(this, _StepResponse_output, "f"),
|
|
160
|
+
compensateInput: __classPrivateFieldGet(this, _StepResponse_compensateInput, "f"),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.StepResponse = StepResponse;
|
|
165
|
+
_StepResponse___type = new WeakMap(), _StepResponse_output = new WeakMap(), _StepResponse_compensateInput = new WeakMap();
|
|
166
|
+
//# sourceMappingURL=step-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-response.js","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/step-response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAG+B;AAC/B,0CAA8D;AAE9D;;;;;;;GAOG;AACH,MAAa,YAAY;IAKvB;;;;;;;OAOG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
|
|
|
1
|
+
import { OrchestrationUtils } from "@8medusa/utils";
|
|
2
|
+
import { WorkflowData, WorkflowDataProperties } from "../type";
|
|
3
|
+
/**
|
|
4
|
+
* Workflow response class encapsulates the return value of a workflow
|
|
5
|
+
*/
|
|
6
|
+
export declare class WorkflowResponse<TResult, const THooks extends readonly unknown[] = []> {
|
|
7
|
+
$result: WorkflowData<TResult> | {
|
|
8
|
+
[K in keyof TResult]: WorkflowData<TResult[K]> | WorkflowDataProperties<TResult[K]> | TResult[K];
|
|
9
|
+
};
|
|
10
|
+
options?: {
|
|
11
|
+
hooks: THooks;
|
|
12
|
+
} | undefined;
|
|
13
|
+
__type: typeof OrchestrationUtils.SymbolMedusaWorkflowResponse;
|
|
14
|
+
constructor($result: WorkflowData<TResult> | {
|
|
15
|
+
[K in keyof TResult]: WorkflowData<TResult[K]> | WorkflowDataProperties<TResult[K]> | TResult[K];
|
|
16
|
+
}, options?: {
|
|
17
|
+
hooks: THooks;
|
|
18
|
+
} | undefined);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=workflow-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-response.d.ts","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/workflow-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAE9D;;GAEG;AACH,qBAAa,gBAAgB,CAC3B,OAAO,EACP,KAAK,CAAC,MAAM,SAAS,SAAS,OAAO,EAAE,GAAG,EAAE;IAMnC,OAAO,EACV,YAAY,CAAC,OAAO,CAAC,GACrB;SACG,CAAC,IAAI,MAAM,OAAO,GACf,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACxB,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC;KACf;IACE,OAAO,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;IAZpC,MAAM,EAAE,OAAO,kBAAkB,CAAC,4BAA4B,CACb;gBAGxC,OAAO,EACV,YAAY,CAAC,OAAO,CAAC,GACrB;SACG,CAAC,IAAI,MAAM,OAAO,GACf,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACxB,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC;KACf,EACE,OAAO,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,YAAA;CAErC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowResponse = void 0;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Workflow response class encapsulates the return value of a workflow
|
|
7
|
+
*/
|
|
8
|
+
class WorkflowResponse {
|
|
9
|
+
constructor($result, options) {
|
|
10
|
+
this.$result = $result;
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.__type = utils_1.OrchestrationUtils.SymbolMedusaWorkflowResponse;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.WorkflowResponse = WorkflowResponse;
|
|
16
|
+
//# sourceMappingURL=workflow-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-response.js","sourceRoot":"","sources":["../../../../src/utils/composer/helpers/workflow-response.ts"],"names":[],"mappings":";;;AAAA,0CAAmD;AAGnD;;GAEG;AACH,MAAa,gBAAgB;IAO3B,YACS,OAOF,EACE,OAA2B;QAR3B,YAAO,GAAP,OAAO,CAOT;QACE,YAAO,GAAP,OAAO,CAAoB;QAZpC,WAAM,GACJ,0BAAkB,CAAC,4BAA4B,CAAA;IAY9C,CAAC;CACL;AAlBD,4CAkBC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./create-step";
|
|
2
|
+
export * from "./create-workflow";
|
|
3
|
+
export * from "./helpers/resolve-value";
|
|
4
|
+
export * from "./helpers/step-response";
|
|
5
|
+
export * from "./helpers/workflow-response";
|
|
6
|
+
export * from "./create-hook";
|
|
7
|
+
export * from "./parallelize";
|
|
8
|
+
export * from "./transform";
|
|
9
|
+
export * from "./type";
|
|
10
|
+
export * from "./when";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/composer/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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("./create-step"), exports);
|
|
18
|
+
__exportStar(require("./create-workflow"), exports);
|
|
19
|
+
__exportStar(require("./helpers/resolve-value"), exports);
|
|
20
|
+
__exportStar(require("./helpers/step-response"), exports);
|
|
21
|
+
__exportStar(require("./helpers/workflow-response"), exports);
|
|
22
|
+
__exportStar(require("./create-hook"), exports);
|
|
23
|
+
__exportStar(require("./parallelize"), exports);
|
|
24
|
+
__exportStar(require("./transform"), exports);
|
|
25
|
+
__exportStar(require("./type"), exports);
|
|
26
|
+
__exportStar(require("./when"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/composer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,oDAAiC;AACjC,0DAAuC;AACvC,0DAAuC;AACvC,8DAA2C;AAC3C,gDAA6B;AAC7B,gDAA6B;AAC7B,8CAA2B;AAC3B,yCAAsB;AACtB,yCAAsB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { WorkflowData } from "./type";
|
|
2
|
+
/**
|
|
3
|
+
* This function is used to run multiple steps in parallel. The result of each step will be returned as part of the result array.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam TResult - The type of the expected result.
|
|
6
|
+
*
|
|
7
|
+
* @returns The step results. The results are ordered in the array by the order they're passed in the function's parameter.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import {
|
|
11
|
+
* createWorkflow,
|
|
12
|
+
* parallelize,
|
|
13
|
+
* WorkflowResponse
|
|
14
|
+
* } from "@8medusa/framework/workflows-sdk"
|
|
15
|
+
* import {
|
|
16
|
+
* createProductStep,
|
|
17
|
+
* createPricesStep,
|
|
18
|
+
* attachProductToSalesChannelStep
|
|
19
|
+
* } from "./steps"
|
|
20
|
+
*
|
|
21
|
+
* interface WorkflowInput {
|
|
22
|
+
* title: string
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* const myWorkflow = createWorkflow(
|
|
26
|
+
* "my-workflow",
|
|
27
|
+
* (input: WorkflowInput) => {
|
|
28
|
+
* const product = createProductStep(input)
|
|
29
|
+
*
|
|
30
|
+
* const [prices, productSalesChannel] = parallelize(
|
|
31
|
+
* createPricesStep(product),
|
|
32
|
+
* attachProductToSalesChannelStep(product)
|
|
33
|
+
* )
|
|
34
|
+
*
|
|
35
|
+
* return new WorkflowResponse({
|
|
36
|
+
* prices,
|
|
37
|
+
* productSalesChannel
|
|
38
|
+
* })
|
|
39
|
+
* }
|
|
40
|
+
* )
|
|
41
|
+
*/
|
|
42
|
+
export declare function parallelize<TResult extends (WorkflowData | undefined)[]>(...steps: TResult): TResult;
|
|
43
|
+
//# sourceMappingURL=parallelize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallelize.d.ts","sourceRoot":"","sources":["../../../src/utils/composer/parallelize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,WAAW,CAAC,OAAO,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,EAAE,EACtE,GAAG,KAAK,EAAE,OAAO,GAChB,OAAO,CA0BT"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parallelize = parallelize;
|
|
4
|
+
const utils_1 = require("@8medusa/utils");
|
|
5
|
+
/**
|
|
6
|
+
* This function is used to run multiple steps in parallel. The result of each step will be returned as part of the result array.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam TResult - The type of the expected result.
|
|
9
|
+
*
|
|
10
|
+
* @returns The step results. The results are ordered in the array by the order they're passed in the function's parameter.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import {
|
|
14
|
+
* createWorkflow,
|
|
15
|
+
* parallelize,
|
|
16
|
+
* WorkflowResponse
|
|
17
|
+
* } from "@8medusa/framework/workflows-sdk"
|
|
18
|
+
* import {
|
|
19
|
+
* createProductStep,
|
|
20
|
+
* createPricesStep,
|
|
21
|
+
* attachProductToSalesChannelStep
|
|
22
|
+
* } from "./steps"
|
|
23
|
+
*
|
|
24
|
+
* interface WorkflowInput {
|
|
25
|
+
* title: string
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* const myWorkflow = createWorkflow(
|
|
29
|
+
* "my-workflow",
|
|
30
|
+
* (input: WorkflowInput) => {
|
|
31
|
+
* const product = createProductStep(input)
|
|
32
|
+
*
|
|
33
|
+
* const [prices, productSalesChannel] = parallelize(
|
|
34
|
+
* createPricesStep(product),
|
|
35
|
+
* attachProductToSalesChannelStep(product)
|
|
36
|
+
* )
|
|
37
|
+
*
|
|
38
|
+
* return new WorkflowResponse({
|
|
39
|
+
* prices,
|
|
40
|
+
* productSalesChannel
|
|
41
|
+
* })
|
|
42
|
+
* }
|
|
43
|
+
* )
|
|
44
|
+
*/
|
|
45
|
+
function parallelize(...steps) {
|
|
46
|
+
if (!global[utils_1.OrchestrationUtils.SymbolMedusaWorkflowComposerContext]) {
|
|
47
|
+
throw new Error("parallelize must be used inside a createWorkflow definition");
|
|
48
|
+
}
|
|
49
|
+
const parallelizeBinder = global[utils_1.OrchestrationUtils.SymbolMedusaWorkflowComposerContext].parallelizeBinder;
|
|
50
|
+
const resultSteps = steps.map((step) => step);
|
|
51
|
+
return parallelizeBinder(function () {
|
|
52
|
+
const stepOntoMerge = steps.shift();
|
|
53
|
+
this.flow.mergeActions(stepOntoMerge.__step__, ...steps.map((step) => step.__step__));
|
|
54
|
+
return resultSteps;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=parallelize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallelize.js","sourceRoot":"","sources":["../../../src/utils/composer/parallelize.ts"],"names":[],"mappings":";;AA2CA,kCA4BC;AAtED,0CAAmD;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,SAAgB,WAAW,CACzB,GAAG,KAAc;IAEjB,IAAI,CAAC,MAAM,CAAC,0BAAkB,CAAC,mCAAmC,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAA;IACH,CAAC;IAED,MAAM,iBAAiB,GACrB,MAAM,CACJ,0BAAkB,CAAC,mCAAmC,CAEzD,CAAC,iBAAiB,CAAA;IAEnB,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAA;IAE7C,OAAO,iBAAiB,CAAU;QAGhC,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,EAAG,CAAA;QACpC,IAAI,CAAC,IAAI,CAAC,YAAY,CACpB,aAAa,CAAC,QAAQ,EACtB,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAK,CAAC,QAAQ,CAAC,CACvC,CAAA;QAED,OAAO,WAAiC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { StepExecutionContext, WorkflowData } from "./type";
|
|
2
|
+
type Func1<T extends object | WorkflowData, U> = (input: T extends WorkflowData<infer U> ? U : T extends object ? {
|
|
3
|
+
[K in keyof T]: T[K] extends WorkflowData<infer U> ? U : T[K];
|
|
4
|
+
} : {}, context: StepExecutionContext) => U | Promise<U>;
|
|
5
|
+
type Func<T, U> = (input: T, context: StepExecutionContext) => U | Promise<U>;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* This function transforms the output of other utility functions.
|
|
9
|
+
*
|
|
10
|
+
* For example, if you're using the value(s) of some step(s) as an input to a later step. As you can't directly manipulate data in the workflow constructor function passed to {@link createWorkflow},
|
|
11
|
+
* the `transform` function provides access to the runtime value of the step(s) output so that you can manipulate them.
|
|
12
|
+
*
|
|
13
|
+
* Another example is if you're using the runtime value of some step(s) as the output of a workflow.
|
|
14
|
+
*
|
|
15
|
+
* If you're also retrieving the output of a hook and want to check if its value is set, you must use a workflow to get the runtime value of that hook.
|
|
16
|
+
*
|
|
17
|
+
* @returns There's no expected value to be returned by the `transform` function.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import {
|
|
21
|
+
* createWorkflow,
|
|
22
|
+
* transform,
|
|
23
|
+
* WorkflowResponse
|
|
24
|
+
* } from "@8medusa/framework/workflows-sdk"
|
|
25
|
+
* import { step1, step2 } from "./steps"
|
|
26
|
+
*
|
|
27
|
+
* type WorkflowInput = {
|
|
28
|
+
* name: string
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* const myWorkflow = createWorkflow(
|
|
32
|
+
* "hello-world",
|
|
33
|
+
* (input: WorkflowInput) => {
|
|
34
|
+
* const str1 = step1(input)
|
|
35
|
+
* const str2 = step2(input)
|
|
36
|
+
*
|
|
37
|
+
* const message = transform({
|
|
38
|
+
* str1,
|
|
39
|
+
* str2
|
|
40
|
+
* }, (input) => `${input.str1}${input.str2}`)
|
|
41
|
+
*
|
|
42
|
+
* return new WorkflowResponse(message)
|
|
43
|
+
* })
|
|
44
|
+
*/
|
|
45
|
+
export declare function transform<T extends object | WorkflowData, RFinal>(
|
|
46
|
+
/**
|
|
47
|
+
* The output(s) of other step functions.
|
|
48
|
+
*/
|
|
49
|
+
values: T,
|
|
50
|
+
/**
|
|
51
|
+
* The transform function used to perform action on the runtime values of the provided `values`.
|
|
52
|
+
*/
|
|
53
|
+
...func: [Func1<T, RFinal>]): WorkflowData<RFinal>;
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare function transform<T extends object | WorkflowData, RA, RFinal>(values: T, ...func: [Func1<T, RFinal>] | [Func1<T, RA>, Func<RA, RFinal>]): WorkflowData<RFinal>;
|
|
58
|
+
/**
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export declare function transform<T extends object | WorkflowData, RA, RB, RFinal>(values: T, ...func: [Func1<T, RFinal>] | [Func1<T, RA>, Func<RA, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RFinal>]): WorkflowData<RFinal>;
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export declare function transform<T extends object | WorkflowData, RA, RB, RC, RFinal>(values: T, ...func: [Func1<T, RFinal>] | [Func1<T, RA>, Func<RA, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RFinal>]): WorkflowData<RFinal>;
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export declare function transform<T extends object | WorkflowData, RA, RB, RC, RD, RFinal>(values: T, ...func: [Func1<T, RFinal>] | [Func1<T, RA>, Func<RA, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RD>, Func<RD, RFinal>]): WorkflowData<RFinal>;
|
|
70
|
+
/**
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export declare function transform<T extends object | WorkflowData, RA, RB, RC, RD, RE, RFinal>(values: T, ...func: [Func1<T, RFinal>] | [Func1<T, RA>, Func<RA, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RD>, Func<RD, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RD>, Func<RD, RE>, Func<RE, RFinal>]): WorkflowData<RFinal>;
|
|
74
|
+
/**
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export declare function transform<T extends object | WorkflowData, RA, RB, RC, RD, RE, RF, RFinal>(values: T, ...func: [Func1<T, RFinal>] | [Func1<T, RA>, Func<RA, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RD>, Func<RD, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RD>, Func<RD, RE>, Func<RE, RFinal>] | [Func1<T, RA>, Func<RA, RB>, Func<RB, RC>, Func<RC, RD>, Func<RD, RE>, Func<RE, RF>, Func<RF, RFinal>]): WorkflowData<RFinal>;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/utils/composer/transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAS3D,KAAK,KAAK,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,EAAE,CAAC,IAAI,CAC/C,KAAK,EAAE,CAAC,SAAS,YAAY,CAAC,MAAM,CAAC,CAAC,GAClC,CAAC,GACD,CAAC,SAAS,MAAM,GAChB;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GACjE,EAAE,EACN,OAAO,EAAE,oBAAoB,KAC1B,CAAC,GAAG,O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E,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,GACxF,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,GACzG,YAAY,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transform = transform;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const proxy_1 = require("./helpers/proxy");
|
|
6
|
+
const utils_1 = require("@8medusa/utils");
|
|
7
|
+
const ulid_1 = require("ulid");
|
|
8
|
+
function transform(values, ...functions) {
|
|
9
|
+
const uniqId = (0, ulid_1.ulid)();
|
|
10
|
+
const ret = {
|
|
11
|
+
__id: uniqId,
|
|
12
|
+
__type: utils_1.OrchestrationUtils.SymbolWorkflowStepTransformer,
|
|
13
|
+
};
|
|
14
|
+
const returnFn = async function (
|
|
15
|
+
// If a transformer is returned as the result of a workflow, then at this point the workflow is entirely done, in that case we have a TransactionContext
|
|
16
|
+
transactionContext) {
|
|
17
|
+
if ("transaction" in transactionContext) {
|
|
18
|
+
const temporaryDataKey = `${transactionContext.transaction.modelId}_${transactionContext.transaction.transactionId}_${uniqId}`;
|
|
19
|
+
if (transactionContext.transaction.hasTemporaryData(temporaryDataKey)) {
|
|
20
|
+
return transactionContext.transaction.getTemporaryData(temporaryDataKey);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const stepValue = await (0, helpers_1.resolveValue)(values, transactionContext);
|
|
24
|
+
let finalResult;
|
|
25
|
+
for (let i = 0; i < functions.length; i++) {
|
|
26
|
+
const fn = functions[i];
|
|
27
|
+
const arg = i === 0 ? stepValue : finalResult;
|
|
28
|
+
finalResult = await fn.apply(fn, [arg, transactionContext]);
|
|
29
|
+
}
|
|
30
|
+
if ("transaction" in transactionContext) {
|
|
31
|
+
const temporaryDataKey = `${transactionContext.transaction.modelId}_${transactionContext.transaction.transactionId}_${uniqId}`;
|
|
32
|
+
transactionContext.transaction.setTemporaryData(temporaryDataKey, finalResult);
|
|
33
|
+
}
|
|
34
|
+
return finalResult;
|
|
35
|
+
};
|
|
36
|
+
const proxyfiedRet = (0, proxy_1.proxify)(ret);
|
|
37
|
+
proxyfiedRet.__resolver = returnFn;
|
|
38
|
+
return proxyfiedRet;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/utils/composer/transform.ts"],"names":[],"mappings":";;AAiKA,8BAmDC;AApND,uCAAwC;AAExC,2CAAyC;AACzC,0CAAmD;AACnD,+BAA2B;AA6J3B,SAAgB,SAAS,CACvB,MAAmB,EACnB,GAAG,SAAqB;IAExB,MAAM,MAAM,GAAG,IAAA,WAAI,GAAE,CAAA;IAErB,MAAM,GAAG,GAAG;QACV,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,0BAAkB,CAAC,6BAA6B;KACzD,CAAA;IAED,MAAM,QAAQ,GAAG,KAAK;IACpB,wJAAwJ;IACxJ,kBAAqE;QAErE,IAAI,aAAa,IAAI,kBAAkB,EAAE,CAAC;YACxC,MAAM,gBAAgB,GAAG,GAAG,kBAAkB,CAA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