@etohq/workflows-sdk 1.5.1-alpha.3 → 1.5.1-alpha.5
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/eto-workflow.d.ts.map +1 -1
- package/dist/eto-workflow.js +3 -0
- package/dist/eto-workflow.js.map +1 -1
- package/dist/framework/src/deps/awilix.d.ts +2 -0
- package/dist/framework/src/deps/awilix.d.ts.map +1 -0
- package/dist/framework/src/deps/awilix.js +18 -0
- package/dist/framework/src/deps/awilix.js.map +1 -0
- package/dist/framework/src/types/container.d.ts +46 -0
- package/dist/framework/src/types/container.d.ts.map +1 -0
- package/dist/framework/src/types/container.js +3 -0
- package/dist/framework/src/types/container.js.map +1 -0
- package/dist/framework/src/utils/index.d.ts +3 -0
- package/dist/framework/src/utils/index.d.ts.map +1 -0
- package/dist/framework/src/utils/index.js +19 -0
- package/dist/framework/src/utils/index.js.map +1 -0
- package/dist/framework/src/zod/index.d.ts +3 -0
- package/dist/framework/src/zod/index.d.ts.map +1 -0
- package/dist/framework/src/zod/index.js +19 -0
- package/dist/framework/src/zod/index.js.map +1 -0
- package/dist/framework/src/zod/zod-helpers.d.ts +3 -0
- package/dist/framework/src/zod/zod-helpers.d.ts.map +1 -0
- package/dist/framework/src/zod/zod-helpers.js +95 -0
- package/dist/framework/src/zod/zod-helpers.js.map +1 -0
- package/dist/helper/type.d.ts +6 -1
- package/dist/helper/type.d.ts.map +1 -1
- package/dist/helper/workflow-export.d.ts.map +1 -1
- package/dist/helper/workflow-export.js +61 -24
- package/dist/helper/workflow-export.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/composer/create-hook.d.ts +2 -2
- package/dist/utils/composer/create-hook.d.ts.map +1 -1
- package/dist/utils/composer/create-hook.js +2 -2
- package/dist/utils/composer/create-hook.js.map +1 -1
- package/dist/utils/composer/create-step.d.ts +0 -12
- package/dist/utils/composer/create-step.d.ts.map +1 -1
- package/dist/utils/composer/create-step.js +27 -14
- package/dist/utils/composer/create-step.js.map +1 -1
- package/dist/utils/composer/create-workflow.d.ts +1 -2
- package/dist/utils/composer/create-workflow.d.ts.map +1 -1
- package/dist/utils/composer/create-workflow.js +23 -11
- package/dist/utils/composer/create-workflow.js.map +1 -1
- package/dist/utils/composer/helpers/create-step-handler.d.ts.map +1 -1
- package/dist/utils/composer/helpers/create-step-handler.js +27 -5
- package/dist/utils/composer/helpers/create-step-handler.js.map +1 -1
- package/dist/utils/composer/helpers/proxy.d.ts.map +1 -1
- package/dist/utils/composer/helpers/proxy.js +3 -10
- package/dist/utils/composer/helpers/proxy.js.map +1 -1
- package/dist/utils/composer/helpers/resolve-value.d.ts +7 -4
- package/dist/utils/composer/helpers/resolve-value.d.ts.map +1 -1
- package/dist/utils/composer/helpers/resolve-value.js +176 -32
- package/dist/utils/composer/helpers/resolve-value.js.map +1 -1
- package/dist/utils/composer/transform.d.ts.map +1 -1
- package/dist/utils/composer/transform.js +15 -8
- package/dist/utils/composer/transform.js.map +1 -1
- package/dist/utils/composer/type.d.ts +7 -3
- package/dist/utils/composer/type.d.ts.map +1 -1
- package/dist/utils/composer/when.d.ts +1 -1
- package/dist/workflows-sdk/src/eto-workflow.d.ts +3 -0
- package/dist/workflows-sdk/src/eto-workflow.d.ts.map +1 -0
- package/dist/workflows-sdk/src/eto-workflow.js +22 -0
- package/dist/workflows-sdk/src/eto-workflow.js.map +1 -0
- package/dist/workflows-sdk/src/helper/index.d.ts +3 -0
- package/dist/workflows-sdk/src/helper/index.d.ts.map +1 -0
- package/dist/workflows-sdk/src/helper/index.js +19 -0
- package/dist/workflows-sdk/src/helper/index.js.map +1 -0
- package/dist/workflows-sdk/src/helper/type.d.ts +71 -0
- package/dist/workflows-sdk/src/helper/type.d.ts.map +1 -0
- package/dist/workflows-sdk/src/helper/type.js +3 -0
- package/dist/workflows-sdk/src/helper/type.js.map +1 -0
- package/dist/workflows-sdk/src/helper/workflow-export.d.ts +6 -0
- package/dist/workflows-sdk/src/helper/workflow-export.d.ts.map +1 -0
- package/dist/workflows-sdk/src/helper/workflow-export.js +291 -0
- package/dist/workflows-sdk/src/helper/workflow-export.js.map +1 -0
- package/dist/workflows-sdk/src/index.d.ts +5 -0
- package/dist/workflows-sdk/src/index.d.ts.map +1 -0
- package/dist/workflows-sdk/src/index.js +44 -0
- package/dist/workflows-sdk/src/index.js.map +1 -0
- package/dist/workflows-sdk/src/utils/_playground.d.ts +2 -0
- package/dist/workflows-sdk/src/utils/_playground.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/_playground.js +40 -0
- package/dist/workflows-sdk/src/utils/_playground.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/create-hook.d.ts +60 -0
- package/dist/workflows-sdk/src/utils/composer/create-hook.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/create-hook.js +97 -0
- package/dist/workflows-sdk/src/utils/composer/create-hook.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/create-step.d.ts +134 -0
- package/dist/workflows-sdk/src/utils/composer/create-step.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/create-step.js +262 -0
- package/dist/workflows-sdk/src/utils/composer/create-step.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/create-workflow.d.ts +71 -0
- package/dist/workflows-sdk/src/utils/composer/create-workflow.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/create-workflow.js +230 -0
- package/dist/workflows-sdk/src/utils/composer/create-workflow.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/create-step-handler.d.ts +20 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/create-step-handler.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/create-step-handler.js +95 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/create-step-handler.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/index.d.ts +3 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/index.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/index.js +19 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/index.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/proxy.d.ts +3 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/proxy.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/proxy.js +18 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/proxy.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/resolve-value.d.ts +8 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/resolve-value.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/resolve-value.js +211 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/resolve-value.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/step-response.d.ts +126 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/step-response.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/step-response.js +166 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/step-response.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/workflow-response.d.ts +20 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/workflow-response.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/workflow-response.js +16 -0
- package/dist/workflows-sdk/src/utils/composer/helpers/workflow-response.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/index.d.ts +11 -0
- package/dist/workflows-sdk/src/utils/composer/index.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/index.js +27 -0
- package/dist/workflows-sdk/src/utils/composer/index.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/parallelize.d.ts +43 -0
- package/dist/workflows-sdk/src/utils/composer/parallelize.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/parallelize.js +57 -0
- package/dist/workflows-sdk/src/utils/composer/parallelize.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/transform.d.ts +79 -0
- package/dist/workflows-sdk/src/utils/composer/transform.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/transform.js +47 -0
- package/dist/workflows-sdk/src/utils/composer/transform.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/type.d.ts +243 -0
- package/dist/workflows-sdk/src/utils/composer/type.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/type.js +3 -0
- package/dist/workflows-sdk/src/utils/composer/type.js.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/when.d.ts +58 -0
- package/dist/workflows-sdk/src/utils/composer/when.d.ts.map +1 -0
- package/dist/workflows-sdk/src/utils/composer/when.js +67 -0
- package/dist/workflows-sdk/src/utils/composer/when.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkflow = createWorkflow;
|
|
4
|
+
const orchestration_1 = require("@etohq/orchestration");
|
|
5
|
+
const utils_1 = require("@etohq/utils");
|
|
6
|
+
const ulid_1 = require("ulid");
|
|
7
|
+
const helper_1 = require("../../helper");
|
|
8
|
+
const create_step_1 = require("./create-step");
|
|
9
|
+
const proxy_1 = require("./helpers/proxy");
|
|
10
|
+
const step_response_1 = require("./helpers/step-response");
|
|
11
|
+
global[utils_1.OrchestrationUtils.SymbolEtoWorkflowComposerContext] = null;
|
|
12
|
+
const buildTransactionId = (step, stepContext) => {
|
|
13
|
+
return (step.__step__ +
|
|
14
|
+
"-" +
|
|
15
|
+
(stepContext.transactionId ?? (0, ulid_1.ulid)()) +
|
|
16
|
+
(stepContext.attempt > 1 ? `-attempt-${stepContext.attempt}` : ""));
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* This function creates a workflow with the provided name and a constructor function.
|
|
20
|
+
* The constructor function builds the workflow from steps created by the {@link createStep} function.
|
|
21
|
+
* The returned workflow is an exported workflow of type {@link ReturnWorkflow}, meaning it's not executed right away. To execute it,
|
|
22
|
+
* invoke the exported workflow, then run its `run` method.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam TData - The type of the input passed to the composer function.
|
|
25
|
+
* @typeParam TResult - The type of the output returned by the composer function.
|
|
26
|
+
* @typeParam THooks - The type of hooks defined in the workflow.
|
|
27
|
+
*
|
|
28
|
+
* @returns The created workflow. You can later execute the workflow by invoking it, then using its `run` method.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* import {
|
|
32
|
+
* createWorkflow,
|
|
33
|
+
* WorkflowResponse
|
|
34
|
+
* } from "@etohq/framework/workflows-sdk"
|
|
35
|
+
* import { EtoRequest, EtoResponse } from "@etohq/framework/http"
|
|
36
|
+
* import {
|
|
37
|
+
* createProductStep,
|
|
38
|
+
* getProductStep,
|
|
39
|
+
* } from "./steps"
|
|
40
|
+
*
|
|
41
|
+
* interface WorkflowInput {
|
|
42
|
+
* title: string
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* const myWorkflow = createWorkflow(
|
|
46
|
+
* "my-workflow",
|
|
47
|
+
* (input: WorkflowInput) => {
|
|
48
|
+
* // Everything here will be executed and resolved later
|
|
49
|
+
* // during the execution. Including the data access.
|
|
50
|
+
*
|
|
51
|
+
* const product = createProductStep(input)
|
|
52
|
+
* return new WorkflowResponse(getProductStep(product.id))
|
|
53
|
+
* }
|
|
54
|
+
* )
|
|
55
|
+
*
|
|
56
|
+
* export async function GET(
|
|
57
|
+
* req: EtoRequest,
|
|
58
|
+
* res: EtoResponse
|
|
59
|
+
* ) {
|
|
60
|
+
* const { result: product } = await myWorkflow(req.scope)
|
|
61
|
+
* .run({
|
|
62
|
+
* input: {
|
|
63
|
+
* title: "Shirt"
|
|
64
|
+
* }
|
|
65
|
+
* })
|
|
66
|
+
*
|
|
67
|
+
* res.json({
|
|
68
|
+
* product
|
|
69
|
+
* })
|
|
70
|
+
* }
|
|
71
|
+
*/
|
|
72
|
+
function createWorkflow(
|
|
73
|
+
/**
|
|
74
|
+
* The name of the workflow or its configuration.
|
|
75
|
+
*/
|
|
76
|
+
nameOrConfig,
|
|
77
|
+
/**
|
|
78
|
+
* The constructor function that is executed when the `run` method in {@link ReturnWorkflow} is used.
|
|
79
|
+
* The function can't be an arrow function or an asynchronus function. It also can't directly manipulate data.
|
|
80
|
+
* You'll have to use the {@link transform} function if you need to directly manipulate data.
|
|
81
|
+
*/
|
|
82
|
+
composer) {
|
|
83
|
+
const fileSourcePath = (0, utils_1.getCallerFilePath)();
|
|
84
|
+
const name = (0, utils_1.isString)(nameOrConfig) ? nameOrConfig : nameOrConfig.name;
|
|
85
|
+
const options = (0, utils_1.isString)(nameOrConfig) ? {} : nameOrConfig;
|
|
86
|
+
(0, utils_1.registerDevServerResource)({
|
|
87
|
+
sourcePath: fileSourcePath,
|
|
88
|
+
id: name,
|
|
89
|
+
type: "workflow",
|
|
90
|
+
});
|
|
91
|
+
const handlers = new Map();
|
|
92
|
+
let newWorkflow = false;
|
|
93
|
+
if (!orchestration_1.WorkflowManager.getWorkflow(name)) {
|
|
94
|
+
newWorkflow = true;
|
|
95
|
+
orchestration_1.WorkflowManager.register(name, undefined, handlers, options);
|
|
96
|
+
}
|
|
97
|
+
const context = {
|
|
98
|
+
__type: utils_1.OrchestrationUtils.SymbolEtoWorkflowComposerContext,
|
|
99
|
+
workflowId: name,
|
|
100
|
+
flow: orchestration_1.WorkflowManager.getEmptyTransactionDefinition(),
|
|
101
|
+
isAsync: false,
|
|
102
|
+
handlers,
|
|
103
|
+
overriddenHandler: new Map(),
|
|
104
|
+
hooks_: {
|
|
105
|
+
declared: [],
|
|
106
|
+
registered: [],
|
|
107
|
+
},
|
|
108
|
+
hooksCallback_: {},
|
|
109
|
+
stepConditions_: {},
|
|
110
|
+
hookBinder: (name, fn) => {
|
|
111
|
+
context.hooks_.declared.push(name);
|
|
112
|
+
context.hooksCallback_[name] = fn.bind(context)();
|
|
113
|
+
},
|
|
114
|
+
stepBinder: (fn) => {
|
|
115
|
+
return fn.bind(context)();
|
|
116
|
+
},
|
|
117
|
+
parallelizeBinder: (fn) => {
|
|
118
|
+
return fn.bind(context)();
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
global[utils_1.OrchestrationUtils.SymbolEtoWorkflowComposerContext] = context;
|
|
122
|
+
const inputPlaceHolder = (0, proxy_1.proxify)({
|
|
123
|
+
__type: utils_1.OrchestrationUtils.SymbolInputReference,
|
|
124
|
+
__step__: "",
|
|
125
|
+
config: () => {
|
|
126
|
+
// TODO: config default value?
|
|
127
|
+
throw new Error("Config is not available for the input object.");
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
const returnedStep = composer.apply(context, [inputPlaceHolder]);
|
|
131
|
+
delete global[utils_1.OrchestrationUtils.SymbolEtoWorkflowComposerContext];
|
|
132
|
+
if (newWorkflow) {
|
|
133
|
+
orchestration_1.WorkflowManager.update(name, context.flow, handlers, options);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
orchestration_1.WorkflowManager.register(name, context.flow, handlers, options);
|
|
137
|
+
}
|
|
138
|
+
const workflow = (0, helper_1.exportWorkflow)(name, returnedStep, {
|
|
139
|
+
wrappedInput: true,
|
|
140
|
+
sourcePath: fileSourcePath,
|
|
141
|
+
});
|
|
142
|
+
const mainFlow = (container) => {
|
|
143
|
+
const workflow_ = workflow(container);
|
|
144
|
+
const expandedFlow = workflow_;
|
|
145
|
+
expandedFlow.config = (config) => {
|
|
146
|
+
workflow_.setOptions(config);
|
|
147
|
+
};
|
|
148
|
+
return expandedFlow;
|
|
149
|
+
};
|
|
150
|
+
mainFlow.hooks = {};
|
|
151
|
+
for (const hook of context.hooks_.declared) {
|
|
152
|
+
mainFlow.hooks[hook] = context.hooksCallback_[hook].bind(context);
|
|
153
|
+
}
|
|
154
|
+
mainFlow.getName = () => name;
|
|
155
|
+
mainFlow.run = mainFlow().run;
|
|
156
|
+
mainFlow.runAsStep = ({ input, }) => {
|
|
157
|
+
// Get current workflow composition context
|
|
158
|
+
const workflowCompositionContext = global[utils_1.OrchestrationUtils.SymbolEtoWorkflowComposerContext];
|
|
159
|
+
const runAsAsync = workflowCompositionContext.isAsync || context.isAsync;
|
|
160
|
+
const step = (0, create_step_1.createStep)({
|
|
161
|
+
name: `${name}-as-step`,
|
|
162
|
+
async: runAsAsync,
|
|
163
|
+
nested: runAsAsync, // if async we flag this is a nested transaction
|
|
164
|
+
}, async (stepInput, stepContext) => {
|
|
165
|
+
const { container, ...sharedContext } = stepContext;
|
|
166
|
+
const isAsync = stepContext[" stepDefinition"]?.async;
|
|
167
|
+
const workflowEngine = container.resolve(utils_1.Modules.WORKFLOW_ENGINE, {
|
|
168
|
+
allowUnregistered: true,
|
|
169
|
+
});
|
|
170
|
+
const executionContext = {
|
|
171
|
+
...(sharedContext?.context ?? {}),
|
|
172
|
+
transactionId: buildTransactionId(step, stepContext),
|
|
173
|
+
parentStepIdempotencyKey: stepContext.idempotencyKey,
|
|
174
|
+
preventReleaseEvents: true,
|
|
175
|
+
runId: stepContext.runId,
|
|
176
|
+
};
|
|
177
|
+
let transaction;
|
|
178
|
+
if (workflowEngine && isAsync) {
|
|
179
|
+
transaction = await workflowEngine.run(name, {
|
|
180
|
+
input: stepInput,
|
|
181
|
+
transactionId: executionContext.transactionId,
|
|
182
|
+
context: executionContext,
|
|
183
|
+
throwOnError: false,
|
|
184
|
+
logOnError: true,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
transaction = await workflow.run({
|
|
189
|
+
input: stepInput,
|
|
190
|
+
container,
|
|
191
|
+
context: executionContext,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return new step_response_1.StepResponse(transaction.result, isAsync ? stepContext.transactionId : transaction);
|
|
195
|
+
}, async (transaction, stepContext) => {
|
|
196
|
+
// The step itself has failed, there is nothing to revert
|
|
197
|
+
const { container, ...sharedContext } = stepContext;
|
|
198
|
+
const isAsync = stepContext[" stepDefinition"]?.async;
|
|
199
|
+
const workflowEngine = container.resolve(utils_1.Modules.WORKFLOW_ENGINE, {
|
|
200
|
+
allowUnregistered: true,
|
|
201
|
+
});
|
|
202
|
+
const executionContext = {
|
|
203
|
+
...(sharedContext?.context ?? {}),
|
|
204
|
+
transactionId: buildTransactionId(step, stepContext),
|
|
205
|
+
parentStepIdempotencyKey: stepContext.idempotencyKey,
|
|
206
|
+
preventReleaseEvents: true,
|
|
207
|
+
cancelingFromParentStep: true,
|
|
208
|
+
};
|
|
209
|
+
if (workflowEngine && isAsync) {
|
|
210
|
+
await workflowEngine.cancel(name, {
|
|
211
|
+
transactionId: executionContext.transactionId,
|
|
212
|
+
context: executionContext,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
await workflow(container).cancel({
|
|
217
|
+
transaction: (transaction ?? {})
|
|
218
|
+
?.transaction,
|
|
219
|
+
transactionId: executionContext.transactionId,
|
|
220
|
+
container,
|
|
221
|
+
context: executionContext,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
})(input);
|
|
226
|
+
return step;
|
|
227
|
+
};
|
|
228
|
+
return mainFlow;
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=create-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-workflow.js","sourceRoot":"","sources":["../../../../../src/utils/composer/create-workflow.ts"],"names":[],"mappings":";;AAqGA,wCAqMC;AA1SD,wDAI6B;AAM7B,wCAMqB;AACrB,+BAA2B;AAC3B,yCAA6D;AAC7D,+CAA0C;AAC1C,2CAAyC;AACzC,2DAAsD;AAWtD,MAAM,CAAC,0BAAkB,CAAC,gCAAgC,CAAC,GAAG,IAAI,CAAA;AAElE,MAAM,kBAAkB,GAAG,CACzB,IAA0B,EAC1B,WAAiC,EACjC,EAAE;IACF,OAAO,CACL,IAAI,CAAC,QAAQ;QACb,GAAG;QACH,CAAC,WAAW,CAAC,aAAa,IAAI,IAAA,WAAI,GAA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import { CreateWorkflowComposerContext, WorkflowData } from "../type";
|
|
4
|
+
import { StepResponse } from "./step-response";
|
|
5
|
+
export declare function createStepHandler<TInvokeInput, TStepInput extends {
|
|
6
|
+
[K in keyof TInvokeInput]: WorkflowData<TInvokeInput[K]>;
|
|
7
|
+
}, TInvokeResultOutput, TInvokeResultCompensateInput>(this: CreateWorkflowComposerContext, { stepName, input, invokeFn, compensateFn, }: ApplyStepOptions<TStepInput, TInvokeInput, TInvokeResultOutput, TInvokeResultCompensateInput>): {
|
|
8
|
+
invoke: (stepArguments: WorkflowStepHandlerArguments) => Promise<{
|
|
9
|
+
__type: string;
|
|
10
|
+
output: StepResponse<any, any> | {
|
|
11
|
+
__type: string;
|
|
12
|
+
output: any;
|
|
13
|
+
compensateInput: any;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
compensate: ((stepArguments: WorkflowStepHandlerArguments) => Promise<{
|
|
17
|
+
output: any;
|
|
18
|
+
}>) | undefined;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=create-step-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-step-handler.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/composer/helpers/create-step-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EACL,6BAA6B,EAE7B,YAAY,EACb,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AA6C9C,wBAAgB,iBAAiB,CAC/B,YAAY,EACZ,UAAU,SAAS;KAChB,CAAC,IAAI,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CACzD,EACD,mBAAmB,EACnB,4BAA4B,EAE5B,IAAI,EAAE,6BAA6B,EACnC,EACE,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,YAAY,GACb,EAAE,gBAAgB,CACjB,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,4BAA4B,CAC7B;4BAG+B,4BAA4B;;;;;;;;iCAqChC,4BAA4B;;;EAiCzD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStepHandler = createStepHandler;
|
|
4
|
+
const utils_1 = require("@etohq/utils");
|
|
5
|
+
const resolve_value_1 = require("./resolve-value");
|
|
6
|
+
function buildStepContext({ action, stepArguments, }) {
|
|
7
|
+
const metadata = stepArguments.metadata;
|
|
8
|
+
const idempotencyKey = metadata.idempotency_key;
|
|
9
|
+
stepArguments.context.idempotencyKey = idempotencyKey;
|
|
10
|
+
const flow = stepArguments.transaction.getFlow();
|
|
11
|
+
const flowMetadata = flow?.metadata;
|
|
12
|
+
const stepDefinition = stepArguments.step.definition;
|
|
13
|
+
const executionContext = {
|
|
14
|
+
workflowId: metadata.model_id,
|
|
15
|
+
stepName: metadata.action,
|
|
16
|
+
action,
|
|
17
|
+
idempotencyKey,
|
|
18
|
+
attempt: metadata.attempt,
|
|
19
|
+
container: stepArguments.container,
|
|
20
|
+
metadata,
|
|
21
|
+
eventGroupId: flowMetadata?.eventGroupId ?? stepArguments.context.eventGroupId,
|
|
22
|
+
parentStepIdempotencyKey: flowMetadata?.parentStepIdempotencyKey,
|
|
23
|
+
preventReleaseEvents: flowMetadata?.preventReleaseEvents ?? false,
|
|
24
|
+
transactionId: stepArguments.context.transactionId,
|
|
25
|
+
runId: flow.runId,
|
|
26
|
+
context: stepArguments.context,
|
|
27
|
+
" stepDefinition": stepDefinition,
|
|
28
|
+
" getStepResult"(stepId, action = "invoke") {
|
|
29
|
+
return stepArguments[action][stepId]?.output?.output;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
return executionContext;
|
|
33
|
+
}
|
|
34
|
+
function createStepHandler({ stepName, input, invokeFn, compensateFn, }) {
|
|
35
|
+
const handler = {
|
|
36
|
+
invoke: async (stepArguments) => {
|
|
37
|
+
const executionContext = buildStepContext({
|
|
38
|
+
action: "invoke",
|
|
39
|
+
stepArguments,
|
|
40
|
+
});
|
|
41
|
+
let argInput = {};
|
|
42
|
+
if (input) {
|
|
43
|
+
argInput = (0, resolve_value_1.resolveValue)(input, stepArguments);
|
|
44
|
+
if (argInput instanceof Promise) {
|
|
45
|
+
argInput = await argInput;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const stepResponse = await invokeFn.apply(this, [
|
|
49
|
+
argInput,
|
|
50
|
+
executionContext,
|
|
51
|
+
]);
|
|
52
|
+
if (!stepResponse || typeof stepResponse !== "object") {
|
|
53
|
+
return {
|
|
54
|
+
__type: utils_1.OrchestrationUtils.SymbolWorkflowWorkflowData,
|
|
55
|
+
output: stepResponse,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const stepResponseJSON = stepResponse.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepResponse
|
|
59
|
+
? stepResponse.toJSON()
|
|
60
|
+
: stepResponse;
|
|
61
|
+
return {
|
|
62
|
+
__type: utils_1.OrchestrationUtils.SymbolWorkflowWorkflowData,
|
|
63
|
+
output: stepResponseJSON,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
compensate: compensateFn
|
|
67
|
+
? async (stepArguments) => {
|
|
68
|
+
const executionContext = buildStepContext({
|
|
69
|
+
action: "compensate",
|
|
70
|
+
stepArguments,
|
|
71
|
+
});
|
|
72
|
+
const stepOutput = stepArguments.invoke[stepName]?.output;
|
|
73
|
+
if (!stepOutput) {
|
|
74
|
+
const output = await compensateFn.apply(this, [
|
|
75
|
+
stepOutput,
|
|
76
|
+
executionContext,
|
|
77
|
+
]);
|
|
78
|
+
return { output };
|
|
79
|
+
}
|
|
80
|
+
const invokeResult = stepOutput.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepResponse
|
|
81
|
+
? stepOutput.compensateInput
|
|
82
|
+
: stepOutput;
|
|
83
|
+
const output = await compensateFn.apply(this, [
|
|
84
|
+
invokeResult,
|
|
85
|
+
executionContext,
|
|
86
|
+
]);
|
|
87
|
+
return {
|
|
88
|
+
output,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
: undefined,
|
|
92
|
+
};
|
|
93
|
+
return handler;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=create-step-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-step-handler.js","sourceRoot":"","sources":["../../../../../../src/utils/composer/helpers/create-step-handler.ts"],"names":[],"mappings":";;AAsDA,8CA4FC;AAjJD,wCAAiD;AAOjD,mDAA8C;AAG9C,SAAS,gBAAgB,CAAC,EACxB,MAAM,EACN,aAAa,GAId;IACC,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAA;IACvC,MAAM,cAAc,GAAG,QAAQ,CAAC,eAAe,CAAA;IAE/C,aAAa,CAAC,OAAQ,CAAC,cAAc,GAAG,cAAc,CAAA;IAEtD,MAAM,IAAI,GAAG,aAAa,CAAC,WAAW,CAAC,OAAO,EAAE,CAAA;IAChD,MAAM,YAAY,GAAG,IAAI,EAAE,QAAQ,CAAA;IACnC,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,UAAU,CAAA;IAEpD,MAAM,gBAAgB,GAAyB;QAC7C,UAAU,EAAE,QAAQ,CAAC,QAAQ;QAC7B,QAAQ,EAAE,QAAQ,CAAC,MAAM;QACzB,MAAM;QACN,cAAc;QACd,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,SAAS,EAAE,aAAa,CAAC,SAAS;QAClC,QAAQ;QACR,YAAY,EACV,YAAY,EAAE,YAAY,IAAI,aAAa,CAAC,OAAQ,CAAC,YAAY;QACnE,wBAAwB,EAAE,YAAY,EAAE,wBAAkC;QAC1E,oBAAoB,EAAE,YAAY,EAAE,oBAAoB,IAAI,KAAK;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,EAAE;gBACvB,CAAC,CAAC,YAAY,CAAA;YAElB,OAAO;gBACL,MAAM,EAAE,0BAAkB,CAAC,0BAA0B;gBACrD,MAAM,EAAE,gBAAgB;aACzB,CAAA;QACH,CAAC;QACD,UAAU,EAAE,YAAY;YACtB,CAAC,CAAC,KAAK,EAAE,aAA2C,EAAE,EAAE;gBACpD,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;oBACxC,MAAM,EAAE,YAAY;oBACpB,aAAa;iBACd,CAAC,CAAA;gBAEF,MAAM,UAAU,GAAI,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAS,EAAE,MAAM,CAAA;gBAElE,IAAI,CAAC,UAAU,EAAE,CAAC;oBAChB,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE;wBAC5C,UAAU;wBACV,gBAAgB;qBACjB,CAAC,CAAA;oBACF,OAAO,EAAE,MAAM,EAAE,CAAA;gBACnB,CAAC;gBAED,MAAM,YAAY,GAChB,UAAU,CAAC,MAAM,KAAK,0BAAkB,CAAC,0BAA0B;oBACjE,CAAC,CAAC,UAAU,CAAC,eAAe;oBAC5B,CAAC,CAAC,UAAU,CAAA;gBAEhB,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE;oBAC5C,YAAY;oBACZ,gBAAgB;iBACjB,CAAC,CAAA;gBACF,OAAO;oBACL,MAAM;iBACP,CAAA;YACH,CAAC;YACH,CAAC,CAAC,SAAS;KACd,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/composer/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./step-response"), exports);
|
|
18
|
+
__exportStar(require("./resolve-value"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/utils/composer/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,kDAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/composer/helpers/proxy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAcpD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proxify = proxify;
|
|
4
|
+
const transform_1 = require("../transform");
|
|
5
|
+
function proxify(obj) {
|
|
6
|
+
return new Proxy(obj, {
|
|
7
|
+
get(target, prop) {
|
|
8
|
+
if (prop in target) {
|
|
9
|
+
return target[prop];
|
|
10
|
+
}
|
|
11
|
+
const transformer = (0, transform_1.transform)({ target }, function (data) {
|
|
12
|
+
return data.target?.[prop];
|
|
13
|
+
});
|
|
14
|
+
return transformer;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../../../../src/utils/composer/helpers/proxy.ts"],"names":[],"mappings":";;AAGA,0BAcC;AAjBD,4CAAwC;AAGxC,SAAgB,OAAO,CAAI,GAAsB;IAC/C,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE;QACpB,GAAG,CAAC,MAAW,EAAE,IAAqB;YACpC,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACnB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAA;YACrB,CAAC;YAED,MAAM,WAAW,GAAG,IAAA,qBAAS,EAAC,EAAE,MAAM,EAAE,EAAE,UAAU,IAAI;gBACtD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAA;YAC5B,CAAC,CAAC,CAAA;YAEF,OAAO,WAAW,CAAA;QACpB,CAAC;KACF,CAAiB,CAAA;AACpB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type InputPrimitive = string | Symbol;
|
|
2
|
+
type InputObject = object & {
|
|
3
|
+
__type?: string | Symbol;
|
|
4
|
+
output?: any;
|
|
5
|
+
};
|
|
6
|
+
export declare function resolveValue(input: InputPrimitive | InputObject | unknown | undefined, transactionContext: any): Promise<any> | any;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=resolve-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-value.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/composer/helpers/resolve-value.ts"],"names":[],"mappings":"AAQA,KAAK,cAAc,GAAG,MAAM,GAAG,MAAM,CAAA;AACrC,KAAK,WAAW,GAAG,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,CAAA;AA8KtE,wBAAgB,YAAY,CAC1B,KAAK,EAAE,cAAc,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,EACzD,kBAAkB,EAAE,GAAG,GACtB,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CA8BpB"}
|
|
@@ -0,0 +1,211 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveValue = resolveValue;
|
|
37
|
+
const utils_1 = require("@etohq/utils");
|
|
38
|
+
const util = __importStar(require("node:util"));
|
|
39
|
+
function resolveProperty(property, transactionContext) {
|
|
40
|
+
const { invoke: invokeRes } = transactionContext;
|
|
41
|
+
let res;
|
|
42
|
+
if (property.__type === utils_1.OrchestrationUtils.SymbolInputReference) {
|
|
43
|
+
res = transactionContext.payload;
|
|
44
|
+
}
|
|
45
|
+
else if (property.__type === utils_1.OrchestrationUtils.SymbolEtoWorkflowResponse) {
|
|
46
|
+
res = resolveValue(property.$result, transactionContext);
|
|
47
|
+
}
|
|
48
|
+
else if (property.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepTransformer) {
|
|
49
|
+
res = property.__resolver(transactionContext);
|
|
50
|
+
}
|
|
51
|
+
else if (property.__type === utils_1.OrchestrationUtils.SymbolWorkflowStep) {
|
|
52
|
+
const output = invokeRes[property.__step__]?.output ?? invokeRes[property.__step__];
|
|
53
|
+
if (output?.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepResponse) {
|
|
54
|
+
res = output.output;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
res = output;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (property.__type === utils_1.OrchestrationUtils.SymbolWorkflowStepResponse) {
|
|
61
|
+
res = property.output;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
res = property;
|
|
65
|
+
}
|
|
66
|
+
return res;
|
|
67
|
+
}
|
|
68
|
+
function unwrapInput({ inputTOUnwrap, parentRef, transactionContext, }) {
|
|
69
|
+
if (inputTOUnwrap == null) {
|
|
70
|
+
return inputTOUnwrap;
|
|
71
|
+
}
|
|
72
|
+
if (Array.isArray(inputTOUnwrap)) {
|
|
73
|
+
const promises = [];
|
|
74
|
+
const resolvedItems = new Array(inputTOUnwrap.length);
|
|
75
|
+
for (let i = 0; i < inputTOUnwrap.length; i++) {
|
|
76
|
+
const item = inputTOUnwrap[i];
|
|
77
|
+
if (item == null || typeof item !== "object") {
|
|
78
|
+
resolvedItems[i] = item;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const resolved = resolveValue(item, transactionContext);
|
|
82
|
+
if (resolved instanceof Promise) {
|
|
83
|
+
promises.push({ promise: resolved, index: i });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
resolvedItems[i] = resolved;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (promises.length > 0) {
|
|
91
|
+
return (0, utils_1.promiseAll)(promises.map((p) => p.promise)).then((resolvedPromises) => {
|
|
92
|
+
for (let i = 0; i < promises.length; i++) {
|
|
93
|
+
resolvedItems[promises[i].index] = resolvedPromises[i];
|
|
94
|
+
}
|
|
95
|
+
return resolvedItems;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return resolvedItems;
|
|
99
|
+
}
|
|
100
|
+
if (util.types.isProxy(inputTOUnwrap)) {
|
|
101
|
+
const resolved = resolveProperty(inputTOUnwrap, transactionContext);
|
|
102
|
+
if (resolved instanceof Promise) {
|
|
103
|
+
return resolved.then((r) => {
|
|
104
|
+
inputTOUnwrap = r;
|
|
105
|
+
if (!(0, utils_1.isObject)(inputTOUnwrap)) {
|
|
106
|
+
return inputTOUnwrap;
|
|
107
|
+
}
|
|
108
|
+
return unwrapInput({
|
|
109
|
+
inputTOUnwrap,
|
|
110
|
+
parentRef: {},
|
|
111
|
+
transactionContext,
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
inputTOUnwrap = resolved;
|
|
116
|
+
}
|
|
117
|
+
if (!(0, utils_1.isObject)(inputTOUnwrap)) {
|
|
118
|
+
return inputTOUnwrap;
|
|
119
|
+
}
|
|
120
|
+
const keys = Object.keys(inputTOUnwrap);
|
|
121
|
+
const promises = [];
|
|
122
|
+
for (let i = 0; i < keys.length; i++) {
|
|
123
|
+
const key = keys[i];
|
|
124
|
+
if (inputTOUnwrap[key] == null || typeof inputTOUnwrap[key] !== "object") {
|
|
125
|
+
parentRef[key] = inputTOUnwrap[key];
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const result = resolveProperty(inputTOUnwrap[key], transactionContext);
|
|
129
|
+
if (result instanceof Promise) {
|
|
130
|
+
promises.push({ promise: result, keyIndex: i });
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
parentRef[key] = result;
|
|
134
|
+
if (result != null && typeof result === "object") {
|
|
135
|
+
const unwrapped = unwrapInput({
|
|
136
|
+
inputTOUnwrap: result,
|
|
137
|
+
parentRef: {},
|
|
138
|
+
transactionContext,
|
|
139
|
+
});
|
|
140
|
+
if (unwrapped instanceof Promise) {
|
|
141
|
+
promises.push({
|
|
142
|
+
promise: unwrapped.then((r) => ({ key, value: r })),
|
|
143
|
+
keyIndex: i,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
parentRef[key] = unwrapped;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (promises.length > 0) {
|
|
153
|
+
return (0, utils_1.promiseAll)(promises.map((p) => p.promise)).then((resolvedPromises) => {
|
|
154
|
+
for (let i = 0; i < promises.length; i++) {
|
|
155
|
+
const resolved = resolvedPromises[i];
|
|
156
|
+
if (resolved && typeof resolved === "object" && "key" in resolved) {
|
|
157
|
+
parentRef[resolved.key] = resolved.value;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const key = keys[promises[i].keyIndex];
|
|
161
|
+
parentRef[key] = resolved;
|
|
162
|
+
if (resolved != null && typeof resolved === "object") {
|
|
163
|
+
const unwrapped = unwrapInput({
|
|
164
|
+
inputTOUnwrap: resolved,
|
|
165
|
+
parentRef: {},
|
|
166
|
+
transactionContext,
|
|
167
|
+
});
|
|
168
|
+
if (unwrapped instanceof Promise) {
|
|
169
|
+
return unwrapped.then((r) => {
|
|
170
|
+
parentRef[key] = r;
|
|
171
|
+
return parentRef;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
parentRef[key] = unwrapped;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return parentRef;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return parentRef;
|
|
182
|
+
}
|
|
183
|
+
function resolveValue(input, transactionContext) {
|
|
184
|
+
if (input == null || typeof input !== "object") {
|
|
185
|
+
return input;
|
|
186
|
+
}
|
|
187
|
+
const input_ = input?.__type ===
|
|
188
|
+
utils_1.OrchestrationUtils.SymbolWorkflowWorkflowData
|
|
189
|
+
? input.output
|
|
190
|
+
: input;
|
|
191
|
+
let result;
|
|
192
|
+
if (input_?.__type) {
|
|
193
|
+
result = resolveProperty(input_, transactionContext);
|
|
194
|
+
if (result instanceof Promise) {
|
|
195
|
+
return result.then((r) => (0, utils_1.parseStringifyIfNecessary)(r));
|
|
196
|
+
}
|
|
197
|
+
return (0, utils_1.parseStringifyIfNecessary)(result);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
result = unwrapInput({
|
|
201
|
+
inputTOUnwrap: input_,
|
|
202
|
+
parentRef: {},
|
|
203
|
+
transactionContext,
|
|
204
|
+
});
|
|
205
|
+
if (result instanceof Promise) {
|
|
206
|
+
return result.then((r) => (0, utils_1.parseStringifyIfNecessary)(r));
|
|
207
|
+
}
|
|
208
|
+
return (0, utils_1.parseStringifyIfNecessary)(result);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=resolve-value.js.map
|