inngest 1.8.4 → 1.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # inngest
2
2
 
3
+ ## 1.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 48d94a2: Allow user provided logger to be used within functions (experimental)
8
+
9
+ ## 1.8.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 34f9ee8: INN-1253 Show actionable error when steps are nested
14
+
3
15
  ## 1.8.4
4
16
 
5
17
  ### Patch Changes
@@ -47,6 +47,7 @@ export declare class Inngest<Events extends Record<string, EventPayload> = Recor
47
47
  private inngestApiUrl;
48
48
  private readonly headers;
49
49
  private readonly fetch;
50
+ private readonly logger;
50
51
  /**
51
52
  * A client used to interact with the Inngest API by sending or reacting to
52
53
  * events.
@@ -70,7 +71,7 @@ export declare class Inngest<Events extends Record<string, EventPayload> = Recor
70
71
  * >({ name: "My App" });
71
72
  * ```
72
73
  */
73
- constructor({ name, eventKey, inngestBaseUrl, fetch, env, }: ClientOptions);
74
+ constructor({ name, eventKey, inngestBaseUrl, fetch, env, logger, }: ClientOptions);
74
75
  /**
75
76
  * Set the event key for this instance of Inngest. This is useful if for some
76
77
  * reason the key is not available at time of instantiation or present in the
@@ -1 +1 @@
1
- {"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAEnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,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,oBAAoB,CAC/D,MAAM,EACN,QAAQ,CACT,EAED,UAAU,EACN,MAAM,GACN,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,KAAK,GAAG,WAAW,CAAC,GAAG;QAClE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA+BG;QACH,GAAG,CAAC,EAAE,IAAI,CAAC;QAEX;;;;;;;WAOG;QACH,SAAS,CAAC,EAAE,OAAO,CACjB,MAAM,EACN,YAAY,EACZ,WAAW,EACX,gBAAgB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CACvC,CAAC;KACH,CAAC,EACN,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,GAClD,eAAe;CAYnB"}
@@ -12,6 +12,7 @@ const devserver_1 = require("../helpers/devserver");
12
12
  const env_1 = require("../helpers/env");
13
13
  const errors_1 = require("../helpers/errors");
14
14
  const InngestFunction_1 = require("./InngestFunction");
15
+ const logger_1 = require("../middleware/logger");
15
16
  /**
16
17
  * A client used to interact with the Inngest API by sending or reacting to
17
18
  * events.
@@ -61,7 +62,7 @@ class Inngest {
61
62
  * >({ name: "My App" });
62
63
  * ```
63
64
  */
64
- constructor({ name, eventKey, inngestBaseUrl = "https://inn.gs/", fetch, env, }) {
65
+ constructor({ name, eventKey, inngestBaseUrl = "https://inn.gs/", fetch, env, logger = new logger_1.DefaultLogger(), }) {
65
66
  _Inngest_instances.add(this);
66
67
  /**
67
68
  * Inngest event key, used to send events to Inngest Cloud.
@@ -92,6 +93,7 @@ class Inngest {
92
93
  inngestEnv: env,
93
94
  });
94
95
  this.fetch = (0, env_1.getFetch)(fetch);
96
+ this.logger = logger;
95
97
  }
96
98
  /**
97
99
  * Set the event key for this instance of Inngest. This is useful if for some
@@ -1 +1 @@
1
- {"version":3,"file":"Inngest.js","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";;;;;;;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AO,CAAC,CACtC,GAAG,eAAe,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;;IAElE,MAAM,CAAC,MAAM,SAAU;IACvB,MAAM,CAAC,aAAa,SAAc;IAQlC;;;;;;OAMG;gBAED,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;IAEvB;;OAEG;IACH,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,MAAM,GAAG,MAAM,CAAC;IAS5C;;OAEG;IACI,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM;IAIzB;;OAEG;IACH,IAAW,IAAI,WAEd;IAED;;OAEG;IACH,OAAO,CAAC,SAAS;IAiGjB;;;;;;;;;;;;;;;OAeG;YACW,KAAK;CAkWpB"}
@@ -28,6 +28,7 @@ const consts_1 = require("../helpers/consts");
28
28
  const errors_1 = require("../helpers/errors");
29
29
  const promises_1 = require("../helpers/promises");
30
30
  const strings_1 = require("../helpers/strings");
31
+ const logger_1 = require("../middleware/logger");
31
32
  const types_1 = require("../types");
32
33
  const InngestStepTools_1 = require("./InngestStepTools");
33
34
  const NonRetriableError_1 = require("./NonRetriableError");
@@ -199,231 +200,251 @@ class InngestFunction {
199
200
  * if an op has been submitted or not.
200
201
  */
201
202
  const [tools, state] = (0, InngestStepTools_1.createStepTools)(__classPrivateFieldGet(this, _InngestFunction_client, "f"));
202
- /**
203
- * Create args to pass in to our function. We blindly pass in the data and
204
- * add tools.
205
- */
206
- const fnArg = Object.assign(Object.assign({}, data), { tools, step: tools });
207
- let userFnToRun = __classPrivateFieldGet(this, _InngestFunction_fn, "f");
208
- /**
209
- * If the incoming event is an Inngest function failure event, we also want
210
- * to pass some extra data to the function to act as shortcuts to the event
211
- * payload.
212
- */
213
- if (isFailureHandler) {
203
+ // create new proxy logger so it doesn't share the buffer with other
204
+ // function runs
205
+ const logger = new logger_1.ProxyLogger(__classPrivateFieldGet(this, _InngestFunction_client, "f")["logger"]);
206
+ try {
214
207
  /**
215
- * The user could have created a function that intentionally listens for
216
- * these events. In this case, we may want to use the original handler.
217
- *
218
- * We only use the onFailure handler if
208
+ * Create args to pass in to our function. We blindly pass in the data and
209
+ * add tools.
219
210
  */
220
- if (!__classPrivateFieldGet(this, _InngestFunction_onFailureFn, "f")) {
221
- // TODO PrettyError
222
- throw new Error(`Function "${this.name}" received a failure event to handle, but no failure handler was defined.`);
223
- }
224
- userFnToRun = __classPrivateFieldGet(this, _InngestFunction_onFailureFn, "f");
225
- fnArg.error = (0, errors_1.deserializeError)(fnArg.event.data.error);
226
- }
227
- /**
228
- * If the user has passed functions they wish to use in their step, add them
229
- * here.
230
- *
231
- * We simply place a thin `tools.run()` wrapper around the function and
232
- * nothing else.
233
- */
234
- if (__classPrivateFieldGet(this, _InngestFunction_opts, "f").fns) {
235
- fnArg.fns = Object.entries(__classPrivateFieldGet(this, _InngestFunction_opts, "f").fns).reduce((acc, [key, fn]) => {
236
- if (typeof fn !== "function") {
237
- return acc;
211
+ const fnArg = Object.assign(Object.assign({}, data), { tools, step: tools, logger: logger });
212
+ let userFnToRun = __classPrivateFieldGet(this, _InngestFunction_fn, "f");
213
+ /**
214
+ * If the incoming event is an Inngest function failure event, we also want
215
+ * to pass some extra data to the function to act as shortcuts to the event
216
+ * payload.
217
+ */
218
+ if (isFailureHandler) {
219
+ /**
220
+ * The user could have created a function that intentionally listens for
221
+ * these events. In this case, we may want to use the original handler.
222
+ *
223
+ * We only use the onFailure handler if
224
+ */
225
+ if (!__classPrivateFieldGet(this, _InngestFunction_onFailureFn, "f")) {
226
+ // TODO PrettyError
227
+ throw new Error(`Function "${this.name}" received a failure event to handle, but no failure handler was defined.`);
238
228
  }
239
- return Object.assign(Object.assign({}, acc), {
240
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
241
- [key]: (...args) => tools.run(key, () => fn(...args)) });
242
- }, {});
243
- }
244
- // eslint-disable-next-line @typescript-eslint/no-misused-promises, no-async-promise-executor
245
- const userFnPromise = new Promise(async (resolve, reject) => {
246
- try {
247
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
248
- resolve(await userFnToRun(fnArg));
229
+ userFnToRun = __classPrivateFieldGet(this, _InngestFunction_onFailureFn, "f");
230
+ fnArg.error = (0, errors_1.deserializeError)(fnArg.event.data.error);
249
231
  }
250
- catch (err) {
251
- reject(err);
232
+ /**
233
+ * If the user has passed functions they wish to use in their step, add them
234
+ * here.
235
+ *
236
+ * We simply place a thin `tools.run()` wrapper around the function and
237
+ * nothing else.
238
+ */
239
+ if (__classPrivateFieldGet(this, _InngestFunction_opts, "f").fns) {
240
+ fnArg.fns = Object.entries(__classPrivateFieldGet(this, _InngestFunction_opts, "f").fns).reduce((acc, [key, fn]) => {
241
+ if (typeof fn !== "function") {
242
+ return acc;
243
+ }
244
+ return Object.assign(Object.assign({}, acc), {
245
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
246
+ [key]: (...args) => tools.run(key, () => fn(...args)) });
247
+ }, {});
252
248
  }
253
- });
254
- let pos = -1;
255
- do {
256
- if (pos >= 0) {
257
- state.tickOps = {};
258
- const incomingOp = opStack[pos];
259
- state.currentOp = state.allFoundOps[incomingOp.id];
260
- if (!state.currentOp) {
261
- /**
262
- * We're trying to resume the function, but we can't find where to go.
263
- *
264
- * This means that either the function has changed or there are async
265
- * actions in-between steps that we haven't noticed in previous
266
- * executions.
267
- *
268
- * Whichever the case, this is bad and we can't continue in this
269
- * undefined state.
270
- */
271
- throw new NonRetriableError_1.NonRetriableError((0, errors_1.functionStoppedRunningErr)(errors_1.ErrCode.ASYNC_DETECTED_DURING_MEMOIZATION));
249
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises, no-async-promise-executor
250
+ const userFnPromise = new Promise(async (resolve, reject) => {
251
+ if (opStack.length == 0 && !requestedRunStep) {
252
+ logger.enable();
272
253
  }
273
- state.currentOp.fulfilled = true;
274
- if (typeof incomingOp.data !== "undefined") {
275
- state.currentOp.resolve(incomingOp.data);
254
+ try {
255
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
256
+ resolve(await userFnToRun(fnArg));
276
257
  }
277
- else {
278
- state.currentOp.reject(incomingOp.error);
258
+ catch (err) {
259
+ logger.error(err);
260
+ reject(err);
279
261
  }
280
- }
281
- await timer.wrap("memoizing-ticks", promises_1.resolveAfterPending);
282
- state.reset();
283
- pos++;
284
- } while (pos < opStack.length);
285
- memoizingStop();
286
- const discoveredOps = Object.values(state.tickOps).map(tickOpToOutgoing);
287
- /**
288
- * We make an optimization here by immediately invoking an op if it's the
289
- * only one we've discovered. The alternative is to plan the step and then
290
- * complete it, so we skip at least one entire execution with this.
291
- */
292
- const runStep = requestedRunStep || getEarlyExecRunStep(discoveredOps);
293
- if (runStep) {
294
- const userFnOp = state.allFoundOps[runStep];
295
- const userFnToRun = userFnOp === null || userFnOp === void 0 ? void 0 : userFnOp.fn;
296
- if (!userFnToRun) {
297
- // TODO PrettyError
298
- throw new Error(`Bad stack; executor requesting to run unknown step "${runStep}"`);
299
- }
300
- const runningStepStop = timer.start("running-step");
301
- const result = await new Promise((resolve) => {
302
- return resolve(userFnToRun());
303
- })
304
- .then((data) => {
305
- return {
306
- data: typeof data === "undefined" ? null : data,
307
- };
308
- })
309
- .catch((err) => {
310
- /**
311
- * If the user-defined code throws an error, we should return this
312
- * to Inngest as the response for this step. The function didn't
313
- * fail, only this step, so Inngest can decide what we do next.
314
- *
315
- * Make sure to log this so the user sees what has happened in the
316
- * console.
317
- */
318
- console.error(err);
319
- try {
320
- return {
321
- error: (0, errors_1.serializeError)(err),
322
- };
262
+ logger.disable();
263
+ });
264
+ let pos = -1;
265
+ do {
266
+ if (pos >= 0) {
267
+ if (!requestedRunStep && pos == opStack.length - 1) {
268
+ logger.enable();
269
+ }
270
+ state.tickOps = {};
271
+ const incomingOp = opStack[pos];
272
+ state.currentOp = state.allFoundOps[incomingOp.id];
273
+ if (!state.currentOp) {
274
+ /**
275
+ * We're trying to resume the function, but we can't find where to go.
276
+ *
277
+ * This means that either the function has changed or there are async
278
+ * actions in-between steps that we haven't noticed in previous
279
+ * executions.
280
+ *
281
+ * Whichever the case, this is bad and we can't continue in this
282
+ * undefined state.
283
+ */
284
+ throw new NonRetriableError_1.NonRetriableError((0, errors_1.functionStoppedRunningErr)(errors_1.ErrCode.ASYNC_DETECTED_DURING_MEMOIZATION));
285
+ }
286
+ state.currentOp.fulfilled = true;
287
+ if (typeof incomingOp.data !== "undefined") {
288
+ state.currentOp.resolve(incomingOp.data);
289
+ }
290
+ else {
291
+ state.currentOp.reject(incomingOp.error);
292
+ }
293
+ }
294
+ await timer.wrap("memoizing-ticks", promises_1.resolveAfterPending);
295
+ logger.disable();
296
+ state.reset();
297
+ pos++;
298
+ } while (pos < opStack.length);
299
+ memoizingStop();
300
+ const discoveredOps = Object.values(state.tickOps).map(tickOpToOutgoing);
301
+ /**
302
+ * We make an optimization here by immediately invoking an op if it's the
303
+ * only one we've discovered. The alternative is to plan the step and then
304
+ * complete it, so we skip at least one entire execution with this.
305
+ */
306
+ const runStep = requestedRunStep || getEarlyExecRunStep(discoveredOps);
307
+ if (runStep) {
308
+ const userFnOp = state.allFoundOps[runStep];
309
+ const userFnToRun = userFnOp === null || userFnOp === void 0 ? void 0 : userFnOp.fn;
310
+ if (!userFnToRun) {
311
+ // TODO PrettyError
312
+ throw new Error(`Bad stack; executor requesting to run unknown step "${runStep}"`);
323
313
  }
324
- catch (serializationErr) {
325
- console.warn("Could not serialize error to return to Inngest; stringifying instead", serializationErr);
314
+ const runningStepStop = timer.start("running-step");
315
+ state.executingStep = true;
316
+ logger.enable();
317
+ const result = await new Promise((resolve) => {
318
+ return resolve(userFnToRun());
319
+ })
320
+ .finally(() => {
321
+ state.executingStep = false;
322
+ runningStepStop();
323
+ })
324
+ .then((data) => {
326
325
  return {
327
- error: err,
326
+ data: typeof data === "undefined" ? null : data,
328
327
  };
329
- }
330
- })
331
- .finally(() => {
332
- runningStepStop();
333
- });
334
- return [
335
- "run",
336
- Object.assign(Object.assign(Object.assign({}, tickOpToOutgoing(userFnOp)), result), { op: types_1.StepOpCode.RunStep }),
337
- ];
338
- }
339
- /**
340
- * Now we're here, we've memoised any function state and we know that this
341
- * request was a discovery call to find out next steps.
342
- *
343
- * We've already given the user's function a lot of chance to register any
344
- * more ops, so we can assume that this list of discovered ops is final.
345
- *
346
- * With that in mind, if this list is empty AND we haven't previously used
347
- * any step tools, we can assume that the user's function is not one that'll
348
- * be using step tooling, so we'll just wait for it to complete and return
349
- * the result.
350
- *
351
- * An empty list while also using step tooling is a valid state when the end
352
- * of a chain of promises is reached, so we MUST also check if step tooling
353
- * has previously been used.
354
- */
355
- if (!discoveredOps.length) {
356
- const fnRet = await Promise.race([
357
- userFnPromise.then((data) => ({ type: "complete", data })),
358
- (0, promises_1.resolveNextTick)().then(() => ({ type: "incomplete" })),
359
- ]);
360
- if (fnRet.type === "complete") {
361
- /**
362
- * The function has returned a value, so we should return this to
363
- * Inngest. Doing this will cause the function to be marked as
364
- * complete, so we should only do this if we're sure that all
365
- * registered ops have been resolved.
366
- */
367
- const allOpsFulfilled = Object.values(state.allFoundOps).every((op) => {
368
- return op.fulfilled;
328
+ })
329
+ .catch((err) => {
330
+ /**
331
+ * If the user-defined code throws an error, we should return this
332
+ * to Inngest as the response for this step. The function didn't
333
+ * fail, only this step, so Inngest can decide what we do next.
334
+ *
335
+ * Make sure to log this so the user sees what has happened.
336
+ */
337
+ logger.error(err);
338
+ try {
339
+ return {
340
+ error: (0, errors_1.serializeError)(err),
341
+ };
342
+ }
343
+ catch (serializationErr) {
344
+ logger.warn("Could not serialize error to return to Inngest; stringifying instead", serializationErr);
345
+ return {
346
+ error: err,
347
+ };
348
+ }
369
349
  });
370
- if (allOpsFulfilled) {
371
- return ["complete", fnRet.data];
372
- }
373
- /**
374
- * If we're here, it means that the user's function has returned a
375
- * value but not all ops have been resolved. This might be intentional
376
- * if they are purposefully pushing work to the background, but also
377
- * might be unintentional and a bug in the user's code where they
378
- * expected an order to be maintained.
379
- *
380
- * To be safe, we'll show a warning here to tell users that this might
381
- * be unintentional, but otherwise carry on as normal.
382
- */
383
- // TODO PrettyError
384
- console.warn(`Warning: Your "${this.name}" function has returned a value, but not all ops have been resolved, i.e. you have used step tooling without \`await\`. This may be intentional, but if you expect your ops to be resolved in order, you should \`await\` them. If you are knowingly leaving ops unresolved using \`.catch()\` or \`void\`, you can ignore this warning.`);
385
- }
386
- else if (!state.hasUsedTools) {
387
- /**
388
- * If we're here, it means that the user's function has not returned
389
- * a value, but also has not used step tooling. This is a valid
390
- * state, indicating that the function is a single-action async
391
- * function.
392
- *
393
- * We should wait for the result and return it.
394
- *
395
- * A caveat here is that the user could use step tooling later on,
396
- * resulting in a mix of step and non-step logic. This is not something
397
- * we want to support without an opt-in from the user, so we should
398
- * throw if this is the case.
399
- */
400
- state.nonStepFnDetected = true;
401
- return ["complete", await userFnPromise];
350
+ return [
351
+ "run",
352
+ Object.assign(Object.assign(Object.assign({}, tickOpToOutgoing(userFnOp)), result), { op: types_1.StepOpCode.RunStep }),
353
+ ];
402
354
  }
403
- else {
404
- /**
405
- * If we're here, the user's function has not returned a value, has not
406
- * reported any new, ops, but has also previously used step tools and
407
- * successfully memoized state.
408
- *
409
- * This indicates that the user has mixed step and non-step logic, which
410
- * is not something we want to support without an opt-in from the user.
411
- *
412
- * We should throw here to let the user know that this is not supported.
413
- *
414
- * We need to be careful, though; it's a valid state for a chain of
415
- * promises to return no further actions, so we should only throw if
416
- * this state is reached and there are no other pending steps.
417
- */
418
- const hasOpsPending = Object.values(state.allFoundOps).some((op) => {
419
- return op.fulfilled === false;
420
- });
421
- if (!hasOpsPending) {
422
- throw new NonRetriableError_1.NonRetriableError((0, errors_1.functionStoppedRunningErr)(errors_1.ErrCode.ASYNC_DETECTED_AFTER_MEMOIZATION));
355
+ /**
356
+ * Now we're here, we've memoised any function state and we know that this
357
+ * request was a discovery call to find out next steps.
358
+ *
359
+ * We've already given the user's function a lot of chance to register any
360
+ * more ops, so we can assume that this list of discovered ops is final.
361
+ *
362
+ * With that in mind, if this list is empty AND we haven't previously used
363
+ * any step tools, we can assume that the user's function is not one that'll
364
+ * be using step tooling, so we'll just wait for it to complete and return
365
+ * the result.
366
+ *
367
+ * An empty list while also using step tooling is a valid state when the end
368
+ * of a chain of promises is reached, so we MUST also check if step tooling
369
+ * has previously been used.
370
+ */
371
+ if (!discoveredOps.length) {
372
+ const fnRet = await Promise.race([
373
+ userFnPromise.then((data) => ({ type: "complete", data })),
374
+ (0, promises_1.resolveNextTick)().then(() => ({ type: "incomplete" })),
375
+ ]);
376
+ if (fnRet.type === "complete") {
377
+ /**
378
+ * The function has returned a value, so we should return this to
379
+ * Inngest. Doing this will cause the function to be marked as
380
+ * complete, so we should only do this if we're sure that all
381
+ * registered ops have been resolved.
382
+ */
383
+ const allOpsFulfilled = Object.values(state.allFoundOps).every((op) => {
384
+ return op.fulfilled;
385
+ });
386
+ if (allOpsFulfilled) {
387
+ return ["complete", fnRet.data];
388
+ }
389
+ /**
390
+ * If we're here, it means that the user's function has returned a
391
+ * value but not all ops have been resolved. This might be intentional
392
+ * if they are purposefully pushing work to the background, but also
393
+ * might be unintentional and a bug in the user's code where they
394
+ * expected an order to be maintained.
395
+ *
396
+ * To be safe, we'll show a warning here to tell users that this might
397
+ * be unintentional, but otherwise carry on as normal.
398
+ */
399
+ // TODO PrettyError
400
+ logger.warn(`Warning: Your "${this.name}" function has returned a value, but not all ops have been resolved, i.e. you have used step tooling without \`await\`. This may be intentional, but if you expect your ops to be resolved in order, you should \`await\` them. If you are knowingly leaving ops unresolved using \`.catch()\` or \`void\`, you can ignore this warning.`);
401
+ }
402
+ else if (!state.hasUsedTools) {
403
+ /**
404
+ * If we're here, it means that the user's function has not returned
405
+ * a value, but also has not used step tooling. This is a valid
406
+ * state, indicating that the function is a single-action async
407
+ * function.
408
+ *
409
+ * We should wait for the result and return it.
410
+ *
411
+ * A caveat here is that the user could use step tooling later on,
412
+ * resulting in a mix of step and non-step logic. This is not something
413
+ * we want to support without an opt-in from the user, so we should
414
+ * throw if this is the case.
415
+ */
416
+ state.nonStepFnDetected = true;
417
+ const result = await userFnPromise;
418
+ return ["complete", result];
419
+ }
420
+ else {
421
+ /**
422
+ * If we're here, the user's function has not returned a value, has not
423
+ * reported any new, ops, but has also previously used step tools and
424
+ * successfully memoized state.
425
+ *
426
+ * This indicates that the user has mixed step and non-step logic, which
427
+ * is not something we want to support without an opt-in from the user.
428
+ *
429
+ * We should throw here to let the user know that this is not supported.
430
+ *
431
+ * We need to be careful, though; it's a valid state for a chain of
432
+ * promises to return no further actions, so we should only throw if
433
+ * this state is reached and there are no other pending steps.
434
+ */
435
+ const hasOpsPending = Object.values(state.allFoundOps).some((op) => {
436
+ return op.fulfilled === false;
437
+ });
438
+ if (!hasOpsPending) {
439
+ throw new NonRetriableError_1.NonRetriableError((0, errors_1.functionStoppedRunningErr)(errors_1.ErrCode.ASYNC_DETECTED_AFTER_MEMOIZATION));
440
+ }
423
441
  }
424
442
  }
443
+ return ["discovery", discoveredOps];
444
+ }
445
+ finally {
446
+ await logger.flush();
425
447
  }
426
- return ["discovery", discoveredOps];
427
448
  }
428
449
  }
429
450
  _InngestFunction_opts = new WeakMap(), _InngestFunction_trigger = new WeakMap(), _InngestFunction_fn = new WeakMap(), _InngestFunction_onFailureFn = new WeakMap(), _InngestFunction_client = new WeakMap(), _InngestFunction_instances = new WeakSet(), _InngestFunction_generateId = function _InngestFunction_generateId(prefix) {