inngest 3.31.13 → 3.32.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.
- package/CHANGELOG.md +19 -0
- package/api/schema.d.ts +49 -0
- package/api/schema.d.ts.map +1 -1
- package/api/schema.js +43 -39
- package/api/schema.js.map +1 -1
- package/components/InngestCommHandler.d.ts.map +1 -1
- package/components/InngestCommHandler.js +39 -2
- package/components/InngestCommHandler.js.map +1 -1
- package/components/InngestFunction.d.ts +16 -0
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +7 -0
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestStepTools.d.ts +1 -1
- package/components/InngestStepTools.d.ts.map +1 -1
- package/components/execution/InngestExecution.d.ts +15 -1
- package/components/execution/InngestExecution.d.ts.map +1 -1
- package/components/execution/InngestExecution.js +14 -0
- package/components/execution/InngestExecution.js.map +1 -1
- package/components/execution/v1.d.ts.map +1 -1
- package/components/execution/v1.js +15 -13
- package/components/execution/v1.js.map +1 -1
- package/components/execution/v2.d.ts +114 -0
- package/components/execution/v2.d.ts.map +1 -0
- package/components/execution/v2.js +797 -0
- package/components/execution/v2.js.map +1 -0
- package/helpers/functions.d.ts +36 -0
- package/helpers/functions.d.ts.map +1 -1
- package/helpers/functions.js +28 -0
- package/helpers/functions.js.map +1 -1
- package/package.json +2 -2
- package/types.d.ts +12 -0
- package/types.d.ts.map +1 -1
- package/types.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var m = o[Symbol.asyncIterator], i;
|
|
5
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
6
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
7
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
|
+
};
|
|
9
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
10
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
13
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
14
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
15
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
16
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
17
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
18
|
+
function fulfill(value) { resume("next", value); }
|
|
19
|
+
function reject(value) { resume("throw", value); }
|
|
20
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports._internals = exports.createV2InngestExecution = void 0;
|
|
24
|
+
const hash_js_1 = require("hash.js");
|
|
25
|
+
const zod_1 = require("zod");
|
|
26
|
+
const consts_js_1 = require("../../helpers/consts.js");
|
|
27
|
+
const errors_js_1 = require("../../helpers/errors.js");
|
|
28
|
+
const functions_js_1 = require("../../helpers/functions.js");
|
|
29
|
+
const promises_js_1 = require("../../helpers/promises.js");
|
|
30
|
+
const types_js_1 = require("../../types.js");
|
|
31
|
+
const InngestMiddleware_js_1 = require("../InngestMiddleware.js");
|
|
32
|
+
const InngestStepTools_js_1 = require("../InngestStepTools.js");
|
|
33
|
+
const NonRetriableError_js_1 = require("../NonRetriableError.js");
|
|
34
|
+
const RetryAfterError_js_1 = require("../RetryAfterError.js");
|
|
35
|
+
const StepError_js_1 = require("../StepError.js");
|
|
36
|
+
const InngestExecution_js_1 = require("./InngestExecution.js");
|
|
37
|
+
const als_js_1 = require("./als.js");
|
|
38
|
+
const createV2InngestExecution = (options) => {
|
|
39
|
+
return new V2InngestExecution(options);
|
|
40
|
+
};
|
|
41
|
+
exports.createV2InngestExecution = createV2InngestExecution;
|
|
42
|
+
class V2InngestExecution extends InngestExecution_js_1.InngestExecution {
|
|
43
|
+
constructor(options) {
|
|
44
|
+
super(options);
|
|
45
|
+
this.timeoutDuration = 1000 * 10;
|
|
46
|
+
this.userFnToRun = this.getUserFnToRun();
|
|
47
|
+
this.state = this.createExecutionState();
|
|
48
|
+
this.fnArg = this.createFnArg();
|
|
49
|
+
this.checkpointHandlers = this.createCheckpointHandlers();
|
|
50
|
+
this.initializeTimer(this.state);
|
|
51
|
+
this.debug("created new V2 execution for run;", this.options.requestedRunStep
|
|
52
|
+
? `wanting to run step "${this.options.requestedRunStep}"`
|
|
53
|
+
: "discovering steps");
|
|
54
|
+
this.debug("existing state keys:", Object.keys(this.state.stepState));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Idempotently start the execution of the user's function.
|
|
58
|
+
*/
|
|
59
|
+
start() {
|
|
60
|
+
var _a;
|
|
61
|
+
this.debug("starting V2 execution");
|
|
62
|
+
return ((_a = this.execution) !== null && _a !== void 0 ? _a : (this.execution = this._start().then((result) => {
|
|
63
|
+
this.debug("result:", result);
|
|
64
|
+
return result;
|
|
65
|
+
})));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Starts execution of the user's function and the core loop.
|
|
69
|
+
*/
|
|
70
|
+
async _start() {
|
|
71
|
+
var _a, e_1, _b, _c;
|
|
72
|
+
var _d, _e;
|
|
73
|
+
try {
|
|
74
|
+
const allCheckpointHandler = this.getCheckpointHandler("");
|
|
75
|
+
this.state.hooks = await this.initializeMiddleware();
|
|
76
|
+
await this.startExecution();
|
|
77
|
+
try {
|
|
78
|
+
for (var _f = true, _g = __asyncValues(this.state.loop), _h; _h = await _g.next(), _a = _h.done, !_a; _f = true) {
|
|
79
|
+
_c = _h.value;
|
|
80
|
+
_f = false;
|
|
81
|
+
const checkpoint = _c;
|
|
82
|
+
await allCheckpointHandler(checkpoint);
|
|
83
|
+
const handler = this.getCheckpointHandler(checkpoint.type);
|
|
84
|
+
const result = await handler(checkpoint);
|
|
85
|
+
if (result) {
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
91
|
+
finally {
|
|
92
|
+
try {
|
|
93
|
+
if (!_f && !_a && (_b = _g.return)) await _b.call(_g);
|
|
94
|
+
}
|
|
95
|
+
finally { if (e_1) throw e_1.error; }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
return await this.transformOutput({ error });
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
void this.state.loop.return();
|
|
103
|
+
await ((_e = (_d = this.state.hooks) === null || _d === void 0 ? void 0 : _d.beforeResponse) === null || _e === void 0 ? void 0 : _e.call(_d));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* If we're here, the generator somehow finished without returning a value.
|
|
107
|
+
* This should never happen.
|
|
108
|
+
*/
|
|
109
|
+
throw new Error("Core loop finished without returning a value");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Creates a handler for every checkpoint type, defining what to do when we
|
|
113
|
+
* reach that checkpoint in the core loop.
|
|
114
|
+
*/
|
|
115
|
+
createCheckpointHandlers() {
|
|
116
|
+
return {
|
|
117
|
+
/**
|
|
118
|
+
* Run for all checkpoints. Best used for logging or common actions.
|
|
119
|
+
* Use other handlers to return values and interrupt the core loop.
|
|
120
|
+
*/
|
|
121
|
+
"": (checkpoint) => {
|
|
122
|
+
this.debug("checkpoint:", checkpoint);
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* The user's function has completed and returned a value.
|
|
126
|
+
*/
|
|
127
|
+
"function-resolved": async (checkpoint) => {
|
|
128
|
+
return await this.transformOutput({ data: checkpoint.data });
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* The user's function has thrown an error.
|
|
132
|
+
*/
|
|
133
|
+
"function-rejected": async (checkpoint) => {
|
|
134
|
+
return await this.transformOutput({ error: checkpoint.error });
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* We've found one or more steps. Here we may want to run a step or report
|
|
138
|
+
* them back to Inngest.
|
|
139
|
+
*/
|
|
140
|
+
"steps-found": async ({ steps }) => {
|
|
141
|
+
const stepResult = await this.tryExecuteStep(steps);
|
|
142
|
+
if (stepResult) {
|
|
143
|
+
const transformResult = await this.transformOutput(stepResult);
|
|
144
|
+
/**
|
|
145
|
+
* Transforming output will always return either function rejection or
|
|
146
|
+
* resolution. In most cases, this can be immediately returned, but in
|
|
147
|
+
* this particular case we want to handle it differently.
|
|
148
|
+
*/
|
|
149
|
+
if (transformResult.type === "function-resolved") {
|
|
150
|
+
return {
|
|
151
|
+
type: "step-ran",
|
|
152
|
+
ctx: transformResult.ctx,
|
|
153
|
+
ops: transformResult.ops,
|
|
154
|
+
step: exports._internals.hashOp(Object.assign(Object.assign({}, stepResult), { data: transformResult.data })),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
else if (transformResult.type === "function-rejected") {
|
|
158
|
+
return {
|
|
159
|
+
type: "step-ran",
|
|
160
|
+
ctx: transformResult.ctx,
|
|
161
|
+
ops: transformResult.ops,
|
|
162
|
+
step: exports._internals.hashOp(Object.assign(Object.assign({}, stepResult), { error: transformResult.error })),
|
|
163
|
+
retriable: transformResult.retriable,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return transformResult;
|
|
167
|
+
}
|
|
168
|
+
const newSteps = await this.filterNewSteps(Array.from(this.state.steps.values()));
|
|
169
|
+
if (newSteps) {
|
|
170
|
+
return {
|
|
171
|
+
type: "steps-found",
|
|
172
|
+
ctx: this.fnArg,
|
|
173
|
+
ops: this.ops,
|
|
174
|
+
steps: newSteps,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
/**
|
|
179
|
+
* While trying to find a step that Inngest has told us to run, we've
|
|
180
|
+
* timed out or have otherwise decided that it doesn't exist.
|
|
181
|
+
*/
|
|
182
|
+
"step-not-found": ({ step }) => {
|
|
183
|
+
return { type: "step-not-found", ctx: this.fnArg, ops: this.ops, step };
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
getCheckpointHandler(type) {
|
|
188
|
+
return this.checkpointHandlers[type];
|
|
189
|
+
}
|
|
190
|
+
async tryExecuteStep(steps) {
|
|
191
|
+
var _a;
|
|
192
|
+
const hashedStepIdToRun = this.options.requestedRunStep || this.getEarlyExecRunStep(steps);
|
|
193
|
+
if (!hashedStepIdToRun) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const step = steps.find((step) => step.hashedId === hashedStepIdToRun && step.fn);
|
|
197
|
+
if (step) {
|
|
198
|
+
return await this.executeStep(step);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Ensure we reset the timeout if we have a requested run step but couldn't
|
|
202
|
+
* find it, but also that we don't reset if we found and executed it.
|
|
203
|
+
*/
|
|
204
|
+
void ((_a = this.timeout) === null || _a === void 0 ? void 0 : _a.reset());
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Given a list of outgoing ops, decide if we can execute an op early and
|
|
208
|
+
* return the ID of the step to execute if we can.
|
|
209
|
+
*/
|
|
210
|
+
getEarlyExecRunStep(steps) {
|
|
211
|
+
/**
|
|
212
|
+
* We may have been disabled due to parallelism, in which case we can't
|
|
213
|
+
* immediately execute unless explicitly requested.
|
|
214
|
+
*/
|
|
215
|
+
if (this.options.disableImmediateExecution)
|
|
216
|
+
return;
|
|
217
|
+
const unfulfilledSteps = steps.filter((step) => !step.fulfilled);
|
|
218
|
+
if (unfulfilledSteps.length !== 1)
|
|
219
|
+
return;
|
|
220
|
+
const op = unfulfilledSteps[0];
|
|
221
|
+
if (op &&
|
|
222
|
+
op.op === types_js_1.StepOpCode.StepPlanned
|
|
223
|
+
// TODO We must individually check properties here that we do not want to
|
|
224
|
+
// execute on, such as retry counts. Nothing exists here that falls in to
|
|
225
|
+
// this case, but should be accounted for when we add them.
|
|
226
|
+
// && typeof op.opts === "undefined"
|
|
227
|
+
) {
|
|
228
|
+
return op.hashedId;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async filterNewSteps(foundSteps) {
|
|
232
|
+
var _a, _b, _c, _d, _e, _f;
|
|
233
|
+
if (this.options.requestedRunStep) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Gather any steps that aren't memoized and report them.
|
|
238
|
+
*/
|
|
239
|
+
const newSteps = foundSteps.filter((step) => !step.fulfilled);
|
|
240
|
+
if (!newSteps.length) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Warn if we've found new steps but haven't yet seen all previous
|
|
245
|
+
* steps. This may indicate that step presence isn't determinate.
|
|
246
|
+
*/
|
|
247
|
+
let knownSteps = 0;
|
|
248
|
+
for (const step of foundSteps) {
|
|
249
|
+
if (step.fulfilled) {
|
|
250
|
+
knownSteps++;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const foundAllCompletedSteps = this.state.stepsToFulfill === knownSteps;
|
|
254
|
+
if (!foundAllCompletedSteps) {
|
|
255
|
+
// TODO Tag
|
|
256
|
+
console.warn((0, errors_js_1.prettyError)({
|
|
257
|
+
type: "warn",
|
|
258
|
+
whatHappened: "Function may be indeterminate",
|
|
259
|
+
why: "We found new steps before seeing all previous steps, which may indicate that the function is non-deterministic.",
|
|
260
|
+
consequences: "This may cause unexpected behaviour as Inngest executes your function.",
|
|
261
|
+
reassurance: "This is expected if a function is updated in the middle of a run, but may indicate a bug if not.",
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* We're finishing up; let's trigger the last of the hooks.
|
|
266
|
+
*/
|
|
267
|
+
await ((_b = (_a = this.state.hooks) === null || _a === void 0 ? void 0 : _a.afterMemoization) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
268
|
+
await ((_d = (_c = this.state.hooks) === null || _c === void 0 ? void 0 : _c.beforeExecution) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
269
|
+
await ((_f = (_e = this.state.hooks) === null || _e === void 0 ? void 0 : _e.afterExecution) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
270
|
+
const stepList = newSteps.map((step) => ({
|
|
271
|
+
displayName: step.displayName,
|
|
272
|
+
op: step.op,
|
|
273
|
+
id: step.hashedId,
|
|
274
|
+
name: step.name,
|
|
275
|
+
opts: step.opts,
|
|
276
|
+
}));
|
|
277
|
+
/**
|
|
278
|
+
* We also run `onSendEvent` middleware hooks against `step.invoke()` steps
|
|
279
|
+
* to ensure that their `data` is transformed correctly.
|
|
280
|
+
*/
|
|
281
|
+
return await this.transformNewSteps(stepList);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Using middleware, transform any newly-found steps before returning them to
|
|
285
|
+
* an Inngest Server.
|
|
286
|
+
*/
|
|
287
|
+
async transformNewSteps(steps) {
|
|
288
|
+
return Promise.all(steps.map(async (step) => {
|
|
289
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
290
|
+
if (step.op !== types_js_1.StepOpCode.InvokeFunction) {
|
|
291
|
+
return step;
|
|
292
|
+
}
|
|
293
|
+
const onSendEventHooks = await (0, InngestMiddleware_js_1.getHookStack)(this.options.fn["middleware"], "onSendEvent", undefined, {
|
|
294
|
+
transformInput: (prev, output) => {
|
|
295
|
+
return Object.assign(Object.assign({}, prev), output);
|
|
296
|
+
},
|
|
297
|
+
transformOutput: (prev, output) => {
|
|
298
|
+
return {
|
|
299
|
+
result: Object.assign(Object.assign({}, prev.result), output === null || output === void 0 ? void 0 : output.result),
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
/**
|
|
304
|
+
* For each event being sent, create a new `onSendEvent` hook stack to
|
|
305
|
+
* process it. We do this as middleware hooks are intended to run once
|
|
306
|
+
* during each lifecycle (onFunctionRun or onSendEvent) and here, a hook
|
|
307
|
+
* is run for every single event.
|
|
308
|
+
*
|
|
309
|
+
* This is done because a developer can use this hook to filter out
|
|
310
|
+
* events entirely; if we batch all of the events together, we can't
|
|
311
|
+
* tell which ones were filtered out if we're processing >1 invocation
|
|
312
|
+
* here.
|
|
313
|
+
*/
|
|
314
|
+
const transformedPayload = await ((_a = onSendEventHooks.transformInput) === null || _a === void 0 ? void 0 : _a.call(onSendEventHooks, {
|
|
315
|
+
payloads: [
|
|
316
|
+
Object.assign(Object.assign({}, ((_c = (_b = step.opts) === null || _b === void 0 ? void 0 : _b.payload) !== null && _c !== void 0 ? _c : {})), { name: consts_js_1.internalEvents.FunctionInvoked }),
|
|
317
|
+
],
|
|
318
|
+
}));
|
|
319
|
+
const newPayload = InngestStepTools_js_1.invokePayloadSchema.parse((_e = (_d = transformedPayload === null || transformedPayload === void 0 ? void 0 : transformedPayload.payloads) === null || _d === void 0 ? void 0 : _d[0]) !== null && _e !== void 0 ? _e : {});
|
|
320
|
+
return Object.assign(Object.assign({}, step), { opts: Object.assign(Object.assign({}, step.opts), { payload: Object.assign(Object.assign({}, ((_g = (_f = step.opts) === null || _f === void 0 ? void 0 : _f.payload) !== null && _g !== void 0 ? _g : {})), newPayload) }) });
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
async executeStep({ id, name, opts, fn, displayName, }) {
|
|
324
|
+
var _a, _b, _c, _d, _e;
|
|
325
|
+
(_a = this.timeout) === null || _a === void 0 ? void 0 : _a.clear();
|
|
326
|
+
await ((_c = (_b = this.state.hooks) === null || _b === void 0 ? void 0 : _b.afterMemoization) === null || _c === void 0 ? void 0 : _c.call(_b));
|
|
327
|
+
await ((_e = (_d = this.state.hooks) === null || _d === void 0 ? void 0 : _d.beforeExecution) === null || _e === void 0 ? void 0 : _e.call(_d));
|
|
328
|
+
const outgoingOp = {
|
|
329
|
+
id,
|
|
330
|
+
op: types_js_1.StepOpCode.StepRun,
|
|
331
|
+
name,
|
|
332
|
+
opts,
|
|
333
|
+
displayName,
|
|
334
|
+
};
|
|
335
|
+
this.state.executingStep = outgoingOp;
|
|
336
|
+
this.debug(`executing step "${id}"`);
|
|
337
|
+
return ((0, promises_js_1.runAsPromise)(fn)
|
|
338
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
339
|
+
.finally(async () => {
|
|
340
|
+
var _a, _b;
|
|
341
|
+
await ((_b = (_a = this.state.hooks) === null || _a === void 0 ? void 0 : _a.afterExecution) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
342
|
+
})
|
|
343
|
+
.then((data) => {
|
|
344
|
+
return Object.assign(Object.assign({}, outgoingOp), { data });
|
|
345
|
+
})
|
|
346
|
+
.catch((error) => {
|
|
347
|
+
return Object.assign(Object.assign({}, outgoingOp), { op: types_js_1.StepOpCode.StepError,
|
|
348
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
349
|
+
error });
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Starts execution of the user's function, including triggering checkpoints
|
|
354
|
+
* and middleware hooks where appropriate.
|
|
355
|
+
*/
|
|
356
|
+
async startExecution() {
|
|
357
|
+
return (0, als_js_1.getAsyncLocalStorage)().then((als) => als.run({ ctx: this.fnArg }, async () => {
|
|
358
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
359
|
+
/**
|
|
360
|
+
* Mutate input as neccessary based on middleware.
|
|
361
|
+
*/
|
|
362
|
+
await this.transformInput();
|
|
363
|
+
/**
|
|
364
|
+
* Start the timer to time out the run if needed.
|
|
365
|
+
*/
|
|
366
|
+
void ((_a = this.timeout) === null || _a === void 0 ? void 0 : _a.start());
|
|
367
|
+
await ((_c = (_b = this.state.hooks) === null || _b === void 0 ? void 0 : _b.beforeMemoization) === null || _c === void 0 ? void 0 : _c.call(_b));
|
|
368
|
+
/**
|
|
369
|
+
* If we had no state to begin with, immediately end the memoization phase.
|
|
370
|
+
*/
|
|
371
|
+
if (this.state.allStateUsed()) {
|
|
372
|
+
await ((_e = (_d = this.state.hooks) === null || _d === void 0 ? void 0 : _d.afterMemoization) === null || _e === void 0 ? void 0 : _e.call(_d));
|
|
373
|
+
await ((_g = (_f = this.state.hooks) === null || _f === void 0 ? void 0 : _f.beforeExecution) === null || _g === void 0 ? void 0 : _g.call(_f));
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Trigger the user's function.
|
|
377
|
+
*/
|
|
378
|
+
(0, promises_js_1.runAsPromise)(() => this.userFnToRun(this.fnArg))
|
|
379
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
380
|
+
.finally(async () => {
|
|
381
|
+
var _a, _b, _c, _d, _e, _f;
|
|
382
|
+
await ((_b = (_a = this.state.hooks) === null || _a === void 0 ? void 0 : _a.afterMemoization) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
383
|
+
await ((_d = (_c = this.state.hooks) === null || _c === void 0 ? void 0 : _c.beforeExecution) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
384
|
+
await ((_f = (_e = this.state.hooks) === null || _e === void 0 ? void 0 : _e.afterExecution) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
385
|
+
})
|
|
386
|
+
.then((data) => {
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
388
|
+
this.state.setCheckpoint({ type: "function-resolved", data });
|
|
389
|
+
})
|
|
390
|
+
.catch((error) => {
|
|
391
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
392
|
+
this.state.setCheckpoint({ type: "function-rejected", error });
|
|
393
|
+
});
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Using middleware, transform input before running.
|
|
398
|
+
*/
|
|
399
|
+
async transformInput() {
|
|
400
|
+
var _a, _b;
|
|
401
|
+
const inputMutations = await ((_b = (_a = this.state.hooks) === null || _a === void 0 ? void 0 : _a.transformInput) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
402
|
+
ctx: Object.assign({}, this.fnArg),
|
|
403
|
+
steps: Object.values(this.state.stepState),
|
|
404
|
+
fn: this.options.fn,
|
|
405
|
+
reqArgs: this.options.reqArgs,
|
|
406
|
+
}));
|
|
407
|
+
if (inputMutations === null || inputMutations === void 0 ? void 0 : inputMutations.ctx) {
|
|
408
|
+
this.fnArg = inputMutations.ctx;
|
|
409
|
+
}
|
|
410
|
+
if (inputMutations === null || inputMutations === void 0 ? void 0 : inputMutations.steps) {
|
|
411
|
+
this.state.stepState = Object.fromEntries(inputMutations.steps.map((step) => [step.id, step]));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Using middleware, transform output before returning.
|
|
416
|
+
*/
|
|
417
|
+
async transformOutput(dataOrError) {
|
|
418
|
+
var _a, _b, _c, _d;
|
|
419
|
+
const output = Object.assign({}, dataOrError);
|
|
420
|
+
/**
|
|
421
|
+
* If we've been given an error and it's one that we just threw from a step,
|
|
422
|
+
* we should return a `NonRetriableError` to stop execution.
|
|
423
|
+
*/
|
|
424
|
+
if (typeof output.error !== "undefined") {
|
|
425
|
+
output.data = (0, errors_js_1.serializeError)(output.error);
|
|
426
|
+
}
|
|
427
|
+
const isStepExecution = Boolean(this.state.executingStep);
|
|
428
|
+
const transformedOutput = await ((_b = (_a = this.state.hooks) === null || _a === void 0 ? void 0 : _a.transformOutput) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
429
|
+
result: Object.assign({}, output),
|
|
430
|
+
step: this.state.executingStep,
|
|
431
|
+
}));
|
|
432
|
+
const { data, error } = Object.assign(Object.assign({}, output), transformedOutput === null || transformedOutput === void 0 ? void 0 : transformedOutput.result);
|
|
433
|
+
if (!isStepExecution) {
|
|
434
|
+
await ((_d = (_c = this.state.hooks) === null || _c === void 0 ? void 0 : _c.finished) === null || _d === void 0 ? void 0 : _d.call(_c, {
|
|
435
|
+
result: Object.assign({}, (typeof error !== "undefined" ? { error } : { data })),
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
438
|
+
if (typeof error !== "undefined") {
|
|
439
|
+
/**
|
|
440
|
+
* Ensure we give middleware the chance to decide on retriable behaviour
|
|
441
|
+
* by looking at the error returned from output transformation.
|
|
442
|
+
*/
|
|
443
|
+
let retriable = !(error instanceof NonRetriableError_js_1.NonRetriableError || error instanceof StepError_js_1.StepError);
|
|
444
|
+
if (retriable && error instanceof RetryAfterError_js_1.RetryAfterError) {
|
|
445
|
+
retriable = error.retryAfter;
|
|
446
|
+
}
|
|
447
|
+
const serializedError = (0, errors_js_1.minifyPrettyError)((0, errors_js_1.serializeError)(error));
|
|
448
|
+
return {
|
|
449
|
+
type: "function-rejected",
|
|
450
|
+
ctx: this.fnArg,
|
|
451
|
+
ops: this.ops,
|
|
452
|
+
error: serializedError,
|
|
453
|
+
retriable,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
return {
|
|
457
|
+
type: "function-resolved",
|
|
458
|
+
ctx: this.fnArg,
|
|
459
|
+
ops: this.ops,
|
|
460
|
+
data: (0, functions_js_1.undefinedToNull)(data),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
createExecutionState() {
|
|
464
|
+
const d = (0, promises_js_1.createDeferredPromiseWithStack)();
|
|
465
|
+
let checkpointResolve = d.deferred.resolve;
|
|
466
|
+
const checkpointResults = d.results;
|
|
467
|
+
const loop = (function (cleanUp) {
|
|
468
|
+
return __asyncGenerator(this, arguments, function* () {
|
|
469
|
+
try {
|
|
470
|
+
while (true) {
|
|
471
|
+
const res = (yield __await(checkpointResults.next())).value;
|
|
472
|
+
if (res) {
|
|
473
|
+
yield yield __await(res);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
finally {
|
|
478
|
+
cleanUp === null || cleanUp === void 0 ? void 0 : cleanUp();
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
})(() => {
|
|
482
|
+
var _a;
|
|
483
|
+
(_a = this.timeout) === null || _a === void 0 ? void 0 : _a.clear();
|
|
484
|
+
void checkpointResults.return();
|
|
485
|
+
});
|
|
486
|
+
const stepsToFulfill = Object.keys(this.options.stepState).length;
|
|
487
|
+
const state = {
|
|
488
|
+
stepState: this.options.stepState,
|
|
489
|
+
stepsToFulfill,
|
|
490
|
+
steps: new Map(),
|
|
491
|
+
loop,
|
|
492
|
+
hasSteps: Boolean(stepsToFulfill),
|
|
493
|
+
stepCompletionOrder: [...this.options.stepCompletionOrder],
|
|
494
|
+
remainingStepsToBeSeen: new Set(this.options.stepCompletionOrder),
|
|
495
|
+
setCheckpoint: (checkpoint) => {
|
|
496
|
+
({ resolve: checkpointResolve } = checkpointResolve(checkpoint));
|
|
497
|
+
},
|
|
498
|
+
allStateUsed: () => {
|
|
499
|
+
return this.state.remainingStepsToBeSeen.size === 0;
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
return state;
|
|
503
|
+
}
|
|
504
|
+
get ops() {
|
|
505
|
+
return Object.fromEntries(this.state.steps);
|
|
506
|
+
}
|
|
507
|
+
createFnArg() {
|
|
508
|
+
var _a, _b, _c, _d;
|
|
509
|
+
const step = this.createStepTools();
|
|
510
|
+
let fnArg = Object.assign(Object.assign({}, this.options.data), { step });
|
|
511
|
+
/**
|
|
512
|
+
* Handle use of the `onFailure` option by deserializing the error.
|
|
513
|
+
*/
|
|
514
|
+
if (this.options.isFailureHandler) {
|
|
515
|
+
const eventData = zod_1.z
|
|
516
|
+
.object({ error: types_js_1.jsonErrorSchema })
|
|
517
|
+
.parse((_a = fnArg.event) === null || _a === void 0 ? void 0 : _a.data);
|
|
518
|
+
fnArg = Object.assign(Object.assign({}, fnArg), { error: (0, errors_js_1.deserializeError)(eventData.error) });
|
|
519
|
+
}
|
|
520
|
+
return (_d = (_c = (_b = this.options).transformCtx) === null || _c === void 0 ? void 0 : _c.call(_b, fnArg)) !== null && _d !== void 0 ? _d : fnArg;
|
|
521
|
+
}
|
|
522
|
+
createStepTools() {
|
|
523
|
+
/**
|
|
524
|
+
* A list of steps that have been found and are being rolled up before being
|
|
525
|
+
* reported to the core loop.
|
|
526
|
+
*/
|
|
527
|
+
const foundStepsToReport = new Map();
|
|
528
|
+
/**
|
|
529
|
+
* A map of the subset of found steps to report that have not yet been
|
|
530
|
+
* handled. Used for fast access to steps that need to be handled in order.
|
|
531
|
+
*/
|
|
532
|
+
const unhandledFoundStepsToReport = new Map();
|
|
533
|
+
/**
|
|
534
|
+
* A map of the latest sequential step indexes found for each step ID. Used
|
|
535
|
+
* to ensure that we don't index steps in parallel.
|
|
536
|
+
*
|
|
537
|
+
* Note that these must be sequential; if we've seen or assigned `a:1`,
|
|
538
|
+
* `a:2` and `a:4`, the latest sequential step index is `2`.
|
|
539
|
+
*
|
|
540
|
+
*/
|
|
541
|
+
const expectedNextStepIndexes = new Map();
|
|
542
|
+
/**
|
|
543
|
+
* A promise that's used to ensure that step reporting cannot be run more than
|
|
544
|
+
* once in a given asynchronous time span.
|
|
545
|
+
*/
|
|
546
|
+
let foundStepsReportPromise;
|
|
547
|
+
/**
|
|
548
|
+
* A promise that's used to represent middleware hooks running before
|
|
549
|
+
* execution.
|
|
550
|
+
*/
|
|
551
|
+
let beforeExecHooksPromise;
|
|
552
|
+
/**
|
|
553
|
+
* A helper used to report steps to the core loop. Used after adding an item
|
|
554
|
+
* to `foundStepsToReport`.
|
|
555
|
+
*/
|
|
556
|
+
const reportNextTick = () => {
|
|
557
|
+
// Being explicit instead of using `??=` to appease TypeScript.
|
|
558
|
+
if (foundStepsReportPromise) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
foundStepsReportPromise = new Promise((resolve) => setImmediate(resolve))
|
|
562
|
+
/**
|
|
563
|
+
* Ensure that we wait for this promise to resolve before continuing.
|
|
564
|
+
*
|
|
565
|
+
* The groups in which steps are reported can affect how we detect some
|
|
566
|
+
* more complex determinism issues like parallel indexing. This promise
|
|
567
|
+
* can represent middleware hooks being run early, in the middle of
|
|
568
|
+
* ingesting steps to report.
|
|
569
|
+
*
|
|
570
|
+
* Because of this, it's important we wait for this middleware to resolve
|
|
571
|
+
* before continuing to report steps to ensure that all steps have a
|
|
572
|
+
* chance to be reported throughout this asynchronous action.
|
|
573
|
+
*/
|
|
574
|
+
.then(() => beforeExecHooksPromise)
|
|
575
|
+
.then(() => {
|
|
576
|
+
foundStepsReportPromise = undefined;
|
|
577
|
+
for (const [hashedId, step] of unhandledFoundStepsToReport) {
|
|
578
|
+
if (step.handle()) {
|
|
579
|
+
unhandledFoundStepsToReport.delete(hashedId);
|
|
580
|
+
if (step.fulfilled) {
|
|
581
|
+
foundStepsToReport.delete(step.id);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (foundStepsToReport.size) {
|
|
586
|
+
const steps = [...foundStepsToReport.values()];
|
|
587
|
+
foundStepsToReport.clear();
|
|
588
|
+
return void this.state.setCheckpoint({
|
|
589
|
+
type: "steps-found",
|
|
590
|
+
steps: steps,
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* A helper used to push a step to the list of steps to report.
|
|
597
|
+
*/
|
|
598
|
+
const pushStepToReport = (step) => {
|
|
599
|
+
foundStepsToReport.set(step.id, step);
|
|
600
|
+
unhandledFoundStepsToReport.set(step.hashedId, step);
|
|
601
|
+
reportNextTick();
|
|
602
|
+
};
|
|
603
|
+
const stepHandler = async ({ args, matchOp, opts, }) => {
|
|
604
|
+
var _a, _b, _c, _d;
|
|
605
|
+
await beforeExecHooksPromise;
|
|
606
|
+
const stepOptions = (0, InngestStepTools_js_1.getStepOptions)(args[0]);
|
|
607
|
+
const opId = matchOp(stepOptions, ...args.slice(1));
|
|
608
|
+
if (this.state.executingStep) {
|
|
609
|
+
/**
|
|
610
|
+
* If a step is found after asynchronous actions during another step's
|
|
611
|
+
* execution, everything is fine. The problem here is if we've found
|
|
612
|
+
* that a step nested inside another a step, which is something we don't
|
|
613
|
+
* support at the time of writing.
|
|
614
|
+
*
|
|
615
|
+
* In this case, we could use something like Async Hooks to understand
|
|
616
|
+
* how the step is being triggered, though this isn't available in all
|
|
617
|
+
* environments.
|
|
618
|
+
*
|
|
619
|
+
* Therefore, we'll only show a warning here to indicate that this is
|
|
620
|
+
* potentially an issue.
|
|
621
|
+
*/
|
|
622
|
+
console.warn((0, errors_js_1.prettyError)({
|
|
623
|
+
whatHappened: `We detected that you have nested \`step.*\` tooling in \`${(_a = opId.displayName) !== null && _a !== void 0 ? _a : opId.id}\``,
|
|
624
|
+
consequences: "Nesting `step.*` tooling is not supported.",
|
|
625
|
+
type: "warn",
|
|
626
|
+
reassurance: "It's possible to see this warning if steps are separated by regular asynchronous calls, which is fine.",
|
|
627
|
+
stack: true,
|
|
628
|
+
toFixNow: "Make sure you're not using `step.*` tooling inside of other `step.*` tooling. If you need to compose steps together, you can create a new async function and call it from within your step function, or use promise chaining.",
|
|
629
|
+
code: errors_js_1.ErrCode.NESTING_STEPS,
|
|
630
|
+
}));
|
|
631
|
+
}
|
|
632
|
+
if (this.state.steps.has(opId.id)) {
|
|
633
|
+
const originalId = opId.id;
|
|
634
|
+
const expectedNextIndex = (_b = expectedNextStepIndexes.get(originalId)) !== null && _b !== void 0 ? _b : 1;
|
|
635
|
+
for (let i = expectedNextIndex;; i++) {
|
|
636
|
+
const newId = originalId + InngestStepTools_js_1.STEP_INDEXING_SUFFIX + i;
|
|
637
|
+
if (!this.state.steps.has(newId)) {
|
|
638
|
+
expectedNextStepIndexes.set(originalId, i + 1);
|
|
639
|
+
opId.id = newId;
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
const { promise, resolve, reject } = (0, promises_js_1.createDeferredPromise)();
|
|
645
|
+
const hashedId = exports._internals.hashId(opId.id);
|
|
646
|
+
const stepState = this.state.stepState[hashedId];
|
|
647
|
+
let isFulfilled = false;
|
|
648
|
+
if (stepState) {
|
|
649
|
+
stepState.seen = true;
|
|
650
|
+
this.state.remainingStepsToBeSeen.delete(hashedId);
|
|
651
|
+
if (typeof stepState.input === "undefined") {
|
|
652
|
+
isFulfilled = true;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
let extraOpts;
|
|
656
|
+
let fnArgs = [...args];
|
|
657
|
+
if (typeof (stepState === null || stepState === void 0 ? void 0 : stepState.input) !== "undefined" &&
|
|
658
|
+
Array.isArray(stepState.input)) {
|
|
659
|
+
switch (opId.op) {
|
|
660
|
+
// `step.run()` has its function input affected
|
|
661
|
+
case types_js_1.StepOpCode.StepPlanned: {
|
|
662
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
663
|
+
fnArgs = [...args.slice(0, 2), ...stepState.input];
|
|
664
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
665
|
+
extraOpts = { input: [...stepState.input] };
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
// `step.ai.infer()` has its body affected
|
|
669
|
+
case types_js_1.StepOpCode.AiGateway: {
|
|
670
|
+
extraOpts = {
|
|
671
|
+
body: Object.assign(Object.assign({}, (typeof ((_c = opId.opts) === null || _c === void 0 ? void 0 : _c.body) === "object"
|
|
672
|
+
? Object.assign({}, opId.opts.body) : {})), stepState.input[0]),
|
|
673
|
+
};
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const step = Object.assign(Object.assign({}, opId), { opts: Object.assign(Object.assign({}, opId.opts), extraOpts), rawArgs: fnArgs, // TODO What is the right value here? Should this be raw args without affected input?
|
|
679
|
+
hashedId, input: stepState === null || stepState === void 0 ? void 0 : stepState.input,
|
|
680
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
681
|
+
fn: (opts === null || opts === void 0 ? void 0 : opts.fn) ? () => { var _a; return (_a = opts.fn) === null || _a === void 0 ? void 0 : _a.call(opts, ...fnArgs); } : undefined, promise, fulfilled: isFulfilled, hasStepState: Boolean(stepState), displayName: (_d = opId.displayName) !== null && _d !== void 0 ? _d : opId.id, handled: false, handle: () => {
|
|
682
|
+
if (step.handled) {
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
step.handled = true;
|
|
686
|
+
if (isFulfilled && stepState) {
|
|
687
|
+
stepState.fulfilled = true;
|
|
688
|
+
// For some execution scenarios such as testing, `data`, `error`,
|
|
689
|
+
// and `input` may be `Promises`. This could also be the case for
|
|
690
|
+
// future middleware applications. For this reason, we'll make sure
|
|
691
|
+
// the values are fully resolved before continuing.
|
|
692
|
+
void Promise.all([
|
|
693
|
+
stepState.data,
|
|
694
|
+
stepState.error,
|
|
695
|
+
stepState.input,
|
|
696
|
+
]).then(() => {
|
|
697
|
+
if (typeof stepState.data !== "undefined") {
|
|
698
|
+
resolve(stepState.data);
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
this.state.recentlyRejectedStepError = new StepError_js_1.StepError(opId.id, stepState.error);
|
|
702
|
+
reject(this.state.recentlyRejectedStepError);
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
return true;
|
|
707
|
+
} });
|
|
708
|
+
this.state.steps.set(opId.id, step);
|
|
709
|
+
this.state.hasSteps = true;
|
|
710
|
+
pushStepToReport(step);
|
|
711
|
+
/**
|
|
712
|
+
* If this is the last piece of state we had, we've now finished
|
|
713
|
+
* memoizing.
|
|
714
|
+
*/
|
|
715
|
+
if (!beforeExecHooksPromise && this.state.allStateUsed()) {
|
|
716
|
+
await (beforeExecHooksPromise = (async () => {
|
|
717
|
+
var _a, _b, _c, _d;
|
|
718
|
+
await ((_b = (_a = this.state.hooks) === null || _a === void 0 ? void 0 : _a.afterMemoization) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
719
|
+
await ((_d = (_c = this.state.hooks) === null || _c === void 0 ? void 0 : _c.beforeExecution) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
720
|
+
})());
|
|
721
|
+
}
|
|
722
|
+
return promise;
|
|
723
|
+
};
|
|
724
|
+
return (0, InngestStepTools_js_1.createStepTools)(this.options.client, this, stepHandler);
|
|
725
|
+
}
|
|
726
|
+
getUserFnToRun() {
|
|
727
|
+
if (!this.options.isFailureHandler) {
|
|
728
|
+
return this.options.fn["fn"];
|
|
729
|
+
}
|
|
730
|
+
if (!this.options.fn["onFailureFn"]) {
|
|
731
|
+
/**
|
|
732
|
+
* Somehow, we've ended up detecting that this is a failure handler but
|
|
733
|
+
* doesn't have an `onFailure` function. This should never happen.
|
|
734
|
+
*/
|
|
735
|
+
throw new Error("Cannot find function `onFailure` handler");
|
|
736
|
+
}
|
|
737
|
+
return this.options.fn["onFailureFn"];
|
|
738
|
+
}
|
|
739
|
+
initializeTimer(state) {
|
|
740
|
+
if (!this.options.requestedRunStep) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
this.timeout = (0, promises_js_1.createTimeoutPromise)(this.timeoutDuration);
|
|
744
|
+
void this.timeout.then(async () => {
|
|
745
|
+
var _a, _b, _c, _d, _e, _f;
|
|
746
|
+
await ((_b = (_a = this.state.hooks) === null || _a === void 0 ? void 0 : _a.afterMemoization) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
747
|
+
await ((_d = (_c = this.state.hooks) === null || _c === void 0 ? void 0 : _c.beforeExecution) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
748
|
+
await ((_f = (_e = this.state.hooks) === null || _e === void 0 ? void 0 : _e.afterExecution) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
749
|
+
state.setCheckpoint({
|
|
750
|
+
type: "step-not-found",
|
|
751
|
+
step: {
|
|
752
|
+
id: this.options.requestedRunStep,
|
|
753
|
+
op: types_js_1.StepOpCode.StepNotFound,
|
|
754
|
+
},
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
async initializeMiddleware() {
|
|
759
|
+
const ctx = this.options.data;
|
|
760
|
+
const hooks = await (0, InngestMiddleware_js_1.getHookStack)(this.options.fn["middleware"], "onFunctionRun", {
|
|
761
|
+
ctx,
|
|
762
|
+
fn: this.options.fn,
|
|
763
|
+
steps: Object.values(this.options.stepState),
|
|
764
|
+
reqArgs: this.options.reqArgs,
|
|
765
|
+
}, {
|
|
766
|
+
transformInput: (prev, output) => {
|
|
767
|
+
return {
|
|
768
|
+
ctx: Object.assign(Object.assign({}, prev.ctx), output === null || output === void 0 ? void 0 : output.ctx),
|
|
769
|
+
fn: this.options.fn,
|
|
770
|
+
steps: prev.steps.map((step, i) => {
|
|
771
|
+
var _a;
|
|
772
|
+
return (Object.assign(Object.assign({}, step), (_a = output === null || output === void 0 ? void 0 : output.steps) === null || _a === void 0 ? void 0 : _a[i]));
|
|
773
|
+
}),
|
|
774
|
+
reqArgs: prev.reqArgs,
|
|
775
|
+
};
|
|
776
|
+
},
|
|
777
|
+
transformOutput: (prev, output) => {
|
|
778
|
+
return {
|
|
779
|
+
result: Object.assign(Object.assign({}, prev.result), output === null || output === void 0 ? void 0 : output.result),
|
|
780
|
+
step: prev.step,
|
|
781
|
+
};
|
|
782
|
+
},
|
|
783
|
+
});
|
|
784
|
+
return hooks;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const hashId = (id) => {
|
|
788
|
+
return (0, hash_js_1.sha1)().update(id).digest("hex");
|
|
789
|
+
};
|
|
790
|
+
const hashOp = (op) => {
|
|
791
|
+
return Object.assign(Object.assign({}, op), { id: hashId(op.id) });
|
|
792
|
+
};
|
|
793
|
+
/**
|
|
794
|
+
* Exported for testing.
|
|
795
|
+
*/
|
|
796
|
+
exports._internals = { hashOp, hashId };
|
|
797
|
+
//# sourceMappingURL=v2.js.map
|