inngest 4.3.0 → 4.4.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 +14 -0
- package/api/schema.d.cts +2 -2
- package/api/schema.d.cts.map +1 -1
- package/api/schema.d.ts +2 -2
- package/api/schema.d.ts.map +1 -1
- package/components/DeferredFunction.cjs +66 -0
- package/components/DeferredFunction.cjs.map +1 -0
- package/components/DeferredFunction.d.cts +99 -0
- package/components/DeferredFunction.d.cts.map +1 -0
- package/components/DeferredFunction.d.ts +99 -0
- package/components/DeferredFunction.d.ts.map +1 -0
- package/components/DeferredFunction.js +65 -0
- package/components/DeferredFunction.js.map +1 -0
- package/components/Inngest.cjs +5 -2
- package/components/Inngest.cjs.map +1 -1
- package/components/Inngest.d.cts +4 -3
- package/components/Inngest.d.cts.map +1 -1
- package/components/Inngest.d.ts +4 -3
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +5 -2
- package/components/Inngest.js.map +1 -1
- package/components/InngestCommHandler.cjs +28 -23
- package/components/InngestCommHandler.cjs.map +1 -1
- package/components/InngestCommHandler.d.cts +9 -4
- package/components/InngestCommHandler.d.cts.map +1 -1
- package/components/InngestCommHandler.d.ts +9 -4
- package/components/InngestCommHandler.d.ts.map +1 -1
- package/components/InngestCommHandler.js +28 -23
- package/components/InngestCommHandler.js.map +1 -1
- package/components/InngestFunction.cjs +27 -19
- package/components/InngestFunction.cjs.map +1 -1
- package/components/InngestFunction.d.cts +6 -1
- package/components/InngestFunction.d.cts.map +1 -1
- package/components/InngestFunction.d.ts +6 -1
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +27 -19
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestGroupTools.cjs +1 -1
- package/components/InngestGroupTools.cjs.map +1 -1
- package/components/InngestGroupTools.js +1 -1
- package/components/InngestGroupTools.js.map +1 -1
- package/components/connect/config.cjs +2 -0
- package/components/connect/config.cjs.map +1 -1
- package/components/connect/config.js +2 -0
- package/components/connect/config.js.map +1 -1
- package/components/execution/InngestExecution.cjs.map +1 -1
- package/components/execution/InngestExecution.d.cts +19 -2
- package/components/execution/InngestExecution.d.cts.map +1 -1
- package/components/execution/InngestExecution.d.ts +19 -2
- package/components/execution/InngestExecution.d.ts.map +1 -1
- package/components/execution/InngestExecution.js.map +1 -1
- package/components/execution/engine.cjs +232 -27
- package/components/execution/engine.cjs.map +1 -1
- package/components/execution/engine.d.cts +14 -0
- package/components/execution/engine.d.cts.map +1 -1
- package/components/execution/engine.d.ts +14 -0
- package/components/execution/engine.d.ts.map +1 -1
- package/components/execution/engine.js +232 -27
- package/components/execution/engine.js.map +1 -1
- package/components/execution/lazyOps.cjs +64 -0
- package/components/execution/lazyOps.cjs.map +1 -0
- package/components/execution/lazyOps.d.cts +42 -0
- package/components/execution/lazyOps.d.cts.map +1 -0
- package/components/execution/lazyOps.d.ts +42 -0
- package/components/execution/lazyOps.d.ts.map +1 -0
- package/components/execution/lazyOps.js +63 -0
- package/components/execution/lazyOps.js.map +1 -0
- package/components/execution/otel/middleware.d.cts +6 -3
- package/components/execution/otel/middleware.d.cts.map +1 -1
- package/components/execution/otel/middleware.d.ts +6 -3
- package/components/execution/otel/middleware.d.ts.map +1 -1
- package/components/middleware/middleware.cjs.map +1 -1
- package/components/middleware/middleware.d.cts +1 -1
- package/components/middleware/middleware.d.cts.map +1 -1
- package/components/middleware/middleware.d.ts +1 -1
- package/components/middleware/middleware.d.ts.map +1 -1
- package/components/middleware/middleware.js.map +1 -1
- package/components/middleware/utils.cjs +1 -0
- package/components/middleware/utils.cjs.map +1 -1
- package/components/middleware/utils.js +1 -0
- package/components/middleware/utils.js.map +1 -1
- package/components/realtime/types.d.cts +4 -4
- package/components/realtime/types.d.cts.map +1 -1
- package/components/realtime/types.d.ts +4 -4
- package/components/realtime/types.d.ts.map +1 -1
- package/components/triggers/typeHelpers.cjs.map +1 -1
- package/components/triggers/typeHelpers.d.cts +11 -0
- package/components/triggers/typeHelpers.d.cts.map +1 -1
- package/components/triggers/typeHelpers.d.ts +11 -0
- package/components/triggers/typeHelpers.d.ts.map +1 -1
- package/components/triggers/typeHelpers.js.map +1 -1
- package/experimental.cjs +3 -0
- package/experimental.d.cts +2 -1
- package/experimental.d.ts +2 -1
- package/experimental.js +2 -1
- package/helpers/consts.cjs +6 -0
- package/helpers/consts.cjs.map +1 -1
- package/helpers/consts.d.cts +6 -0
- package/helpers/consts.d.cts.map +1 -1
- package/helpers/consts.d.ts +6 -0
- package/helpers/consts.d.ts.map +1 -1
- package/helpers/consts.js +6 -0
- package/helpers/consts.js.map +1 -1
- package/helpers/functions.cjs +1 -0
- package/helpers/functions.cjs.map +1 -1
- package/helpers/functions.js +1 -0
- package/helpers/functions.js.map +1 -1
- package/helpers/marker.cjs +21 -0
- package/helpers/marker.cjs.map +1 -0
- package/helpers/marker.d.cts +12 -0
- package/helpers/marker.d.cts.map +1 -0
- package/helpers/marker.d.ts +12 -0
- package/helpers/marker.d.ts.map +1 -0
- package/helpers/marker.js +19 -0
- package/helpers/marker.js.map +1 -0
- package/package.json +2 -2
- package/proto/src/components/connect/protobuf/connect.cjs +11 -2
- package/proto/src/components/connect/protobuf/connect.cjs.map +1 -1
- package/proto/src/components/connect/protobuf/connect.js +11 -2
- package/proto/src/components/connect/protobuf/connect.js.map +1 -1
- package/types.cjs +2 -0
- package/types.cjs.map +1 -1
- package/types.d.cts +52 -18
- package/types.d.cts.map +1 -1
- package/types.d.ts +52 -18
- package/types.d.ts.map +1 -1
- package/types.js +2 -0
- package/types.js.map +1 -1
- package/version.cjs +1 -1
- package/version.cjs.map +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -7,6 +7,7 @@ const require_types = require('../../types.cjs');
|
|
|
7
7
|
const require_InngestExecution = require('./InngestExecution.cjs');
|
|
8
8
|
const require_types$1 = require('../../helpers/types.cjs');
|
|
9
9
|
const require_functions = require('../../helpers/functions.cjs');
|
|
10
|
+
const require_marker = require('../../helpers/marker.cjs');
|
|
10
11
|
const require_temporal = require('../../helpers/temporal.cjs');
|
|
11
12
|
const require_promises = require('../../helpers/promises.cjs');
|
|
12
13
|
const require_als = require('./als.cjs');
|
|
@@ -20,6 +21,7 @@ const require_StepError = require('../StepError.cjs');
|
|
|
20
21
|
const require_streaming = require('./streaming.cjs');
|
|
21
22
|
const require_StreamTools = require('../StreamTools.cjs');
|
|
22
23
|
const require_utils$1 = require('../triggers/utils.cjs');
|
|
24
|
+
const require_lazyOps = require('./lazyOps.cjs');
|
|
23
25
|
const require_access = require('./otel/access.cjs');
|
|
24
26
|
let zod_v3 = require("zod/v3");
|
|
25
27
|
let hash_js = require("hash.js");
|
|
@@ -260,6 +262,8 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
260
262
|
throw new Error("Core loop finished without returning a value");
|
|
261
263
|
}
|
|
262
264
|
async checkpoint(steps) {
|
|
265
|
+
const lazyOps = this.state.lazyOps.drain();
|
|
266
|
+
if (lazyOps.length > 0) steps = [...steps, ...lazyOps];
|
|
263
267
|
if (this.options.stepMode === require_types.StepMode.Sync) if (!this.state.checkpointedRun) {
|
|
264
268
|
const res = await require_promises.retryWithBackoff(() => this.options.client["inngestApi"].checkpointNewRun({
|
|
265
269
|
runId: this.fnArg.runId,
|
|
@@ -517,12 +521,13 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
517
521
|
return transformResult;
|
|
518
522
|
};
|
|
519
523
|
const maybeReturnNewSteps = async () => {
|
|
520
|
-
const
|
|
521
|
-
if (
|
|
524
|
+
const allSteps = [...await this.filterNewSteps(Array.from(this.state.steps.values())) ?? [], ...this.state.lazyOps.drain()];
|
|
525
|
+
if (allSteps.length === 0) return;
|
|
526
|
+
return {
|
|
522
527
|
type: "steps-found",
|
|
523
528
|
ctx: this.fnArg,
|
|
524
529
|
ops: this.ops,
|
|
525
|
-
steps:
|
|
530
|
+
steps: allSteps
|
|
526
531
|
};
|
|
527
532
|
};
|
|
528
533
|
const attemptCheckpointAndResume = async (stepResult, resume = true, force = false) => {
|
|
@@ -668,23 +673,36 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
668
673
|
sseResponse = extractSseResponse(data, body);
|
|
669
674
|
resultData = body;
|
|
670
675
|
} else sseResponse = defaultSseResponse(resultData);
|
|
671
|
-
const
|
|
672
|
-
if (
|
|
676
|
+
const newSteps = await this.filterNewSteps(Array.from(this.state.steps.values()));
|
|
677
|
+
if (newSteps?.length) return this.attachLazyOps({
|
|
678
|
+
type: "steps-found",
|
|
679
|
+
ctx: this.fnArg,
|
|
680
|
+
ops: this.ops,
|
|
681
|
+
steps: newSteps
|
|
682
|
+
});
|
|
673
683
|
await this.streamCloseSucceeded(sseResponse);
|
|
674
684
|
if (!this.streamTools.activated) this.postCheckpointStream();
|
|
675
685
|
if (this.options.createResponse) data = await this.options.createResponse(jsonResponse(resultData));
|
|
676
|
-
return this.transformOutput({ data });
|
|
686
|
+
return this.attachLazyOps(this.transformOutput({ data }));
|
|
677
687
|
},
|
|
678
688
|
"function-rejected": async (checkpoint) => {
|
|
679
689
|
if (!this.retriability(checkpoint.error)) await this.streamCloseFailed(errorMessage(checkpoint.error));
|
|
680
690
|
else await this.streamEnd();
|
|
681
691
|
if (!this.streamTools.activated) this.postCheckpointStream();
|
|
682
|
-
return this.transformOutput({ error: checkpoint.error });
|
|
692
|
+
return this.attachLazyOps(this.transformOutput({ error: checkpoint.error }));
|
|
683
693
|
},
|
|
684
694
|
"steps-found": async ({ steps }) => {
|
|
685
695
|
const stepResult = await this.tryExecuteStep(steps);
|
|
686
|
-
if (stepResult) return
|
|
687
|
-
return
|
|
696
|
+
if (!stepResult) return maybeReturnNewSteps();
|
|
697
|
+
if (this.state.lazyOps.length === 0) return stepRanHandler(stepResult);
|
|
698
|
+
const transformed = await stepRanHandler(stepResult);
|
|
699
|
+
if (transformed.type !== "step-ran") return transformed;
|
|
700
|
+
return this.attachLazyOps({
|
|
701
|
+
type: "steps-found",
|
|
702
|
+
ctx: transformed.ctx,
|
|
703
|
+
ops: transformed.ops,
|
|
704
|
+
steps: [transformed.step]
|
|
705
|
+
});
|
|
688
706
|
},
|
|
689
707
|
"step-not-found": ({ step }) => {
|
|
690
708
|
const { foundSteps, totalFoundSteps } = this.getStepNotFoundDetails();
|
|
@@ -707,13 +725,18 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
707
725
|
const asyncCheckpointingHandlers = {
|
|
708
726
|
"": commonCheckpointHandler,
|
|
709
727
|
"function-resolved": async (checkpoint, i) => {
|
|
728
|
+
const lazyOps = this.state.lazyOps.drain();
|
|
710
729
|
const output = await asyncHandlers["function-resolved"](checkpoint, i);
|
|
711
730
|
if (output?.type === "function-resolved") {
|
|
712
|
-
const steps =
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
731
|
+
const steps = [
|
|
732
|
+
...this.state.checkpointingStepBuffer,
|
|
733
|
+
...lazyOps,
|
|
734
|
+
{
|
|
735
|
+
op: require_types.StepOpCode.RunComplete,
|
|
736
|
+
id: hashId(RUN_COMPLETE_STEP_ID),
|
|
737
|
+
data: output.data
|
|
738
|
+
}
|
|
739
|
+
];
|
|
717
740
|
if (isNonEmpty(steps)) return {
|
|
718
741
|
type: "steps-found",
|
|
719
742
|
ctx: output.ctx,
|
|
@@ -721,9 +744,14 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
721
744
|
steps
|
|
722
745
|
};
|
|
723
746
|
}
|
|
747
|
+
if (output?.type === "steps-found" && lazyOps.length) return {
|
|
748
|
+
...output,
|
|
749
|
+
steps: [...output.steps, ...lazyOps]
|
|
750
|
+
};
|
|
751
|
+
return output;
|
|
724
752
|
},
|
|
725
753
|
"function-rejected": async (checkpoint) => {
|
|
726
|
-
if (this.state.checkpointingStepBuffer.length) {
|
|
754
|
+
if (this.state.checkpointingStepBuffer.length || this.state.lazyOps.length > 0) {
|
|
727
755
|
const fallback = await attemptCheckpointAndResume(void 0, false, true);
|
|
728
756
|
if (fallback) return fallback;
|
|
729
757
|
}
|
|
@@ -968,7 +996,11 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
968
996
|
* Validate event data against schemas defined in function triggers.
|
|
969
997
|
*/
|
|
970
998
|
async validateEventSchemas() {
|
|
971
|
-
if (this.options.
|
|
999
|
+
if (this.options.handlerKind === "failure") return;
|
|
1000
|
+
if (this.options.handlerKind === "defer") {
|
|
1001
|
+
await this.validateDeferEventSchema();
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
972
1004
|
const triggers = this.options.fn.opts.triggers;
|
|
973
1005
|
if (!triggers || triggers.length === 0) return;
|
|
974
1006
|
const fnArgEvents = this.fnArg.events;
|
|
@@ -979,6 +1011,17 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
979
1011
|
})), triggers);
|
|
980
1012
|
}
|
|
981
1013
|
/**
|
|
1014
|
+
* Validate the deferred event's data against the defer function's own
|
|
1015
|
+
* schema (set via `createDefer`'s `opts.schema`).
|
|
1016
|
+
*/
|
|
1017
|
+
async validateDeferEventSchema() {
|
|
1018
|
+
const fn = this.options.fn;
|
|
1019
|
+
if (!require_marker.isDeferredFunction(fn) || !fn.schema) return;
|
|
1020
|
+
const eventData = this.fnArg.event?.data;
|
|
1021
|
+
const result = await fn.schema["~standard"].validate(eventData);
|
|
1022
|
+
if (result.issues) throw new require_NonRetriableError.NonRetriableError(`defer handler "${fn.id(this.options.client.id)}" schema validation failed: ${JSON.stringify(result.issues)}`);
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
982
1025
|
* Using middleware, transform output before returning.
|
|
983
1026
|
*/
|
|
984
1027
|
transformOutput(dataOrError) {
|
|
@@ -1001,6 +1044,64 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
1001
1044
|
data: require_functions.undefinedToNull(data)
|
|
1002
1045
|
};
|
|
1003
1046
|
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Drain buffered lazy ops (e.g. `DeferAdd` from `defer()`) and merge them
|
|
1049
|
+
* into `result` so they ship in the same outbound message. Lazy ops are
|
|
1050
|
+
* fire-and-forget and have no natural shipping moment, so each terminal code
|
|
1051
|
+
* path must ship them or they're silently dropped.
|
|
1052
|
+
*/
|
|
1053
|
+
attachLazyOps(result, extras = []) {
|
|
1054
|
+
const lazyOps = this.state.lazyOps.drain();
|
|
1055
|
+
if (lazyOps.length === 0 && extras.length === 0) return result;
|
|
1056
|
+
switch (result.type) {
|
|
1057
|
+
case "function-resolved": {
|
|
1058
|
+
const steps = [
|
|
1059
|
+
...extras,
|
|
1060
|
+
...lazyOps,
|
|
1061
|
+
{
|
|
1062
|
+
op: require_types.StepOpCode.RunComplete,
|
|
1063
|
+
id: hashId(RUN_COMPLETE_STEP_ID),
|
|
1064
|
+
data: require_functions.undefinedToNull(result.data)
|
|
1065
|
+
}
|
|
1066
|
+
];
|
|
1067
|
+
return {
|
|
1068
|
+
type: "steps-found",
|
|
1069
|
+
ctx: result.ctx,
|
|
1070
|
+
ops: result.ops,
|
|
1071
|
+
steps
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
case "function-rejected": {
|
|
1075
|
+
const isFinal = result.retriable === false;
|
|
1076
|
+
const steps = [
|
|
1077
|
+
...extras,
|
|
1078
|
+
...lazyOps,
|
|
1079
|
+
{
|
|
1080
|
+
op: isFinal ? require_types.StepOpCode.StepFailed : require_types.StepOpCode.StepError,
|
|
1081
|
+
id: hashId(RUN_COMPLETE_STEP_ID),
|
|
1082
|
+
error: result.error
|
|
1083
|
+
}
|
|
1084
|
+
];
|
|
1085
|
+
return {
|
|
1086
|
+
type: "steps-found",
|
|
1087
|
+
ctx: result.ctx,
|
|
1088
|
+
ops: result.ops,
|
|
1089
|
+
steps
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
case "steps-found": return {
|
|
1093
|
+
...result,
|
|
1094
|
+
steps: [
|
|
1095
|
+
...result.steps,
|
|
1096
|
+
...extras,
|
|
1097
|
+
...lazyOps
|
|
1098
|
+
]
|
|
1099
|
+
};
|
|
1100
|
+
default:
|
|
1101
|
+
for (const op of lazyOps) this.state.lazyOps.push(op);
|
|
1102
|
+
return result;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1004
1105
|
createExecutionState() {
|
|
1005
1106
|
const d = require_promises.createDeferredPromiseWithStack();
|
|
1006
1107
|
let checkpointResolve = d.deferred.resolve;
|
|
@@ -1023,6 +1124,7 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
1023
1124
|
const stepsToFulfill = Object.keys(this.options.stepState).length;
|
|
1024
1125
|
return {
|
|
1025
1126
|
stepState: this.options.stepState,
|
|
1127
|
+
priorDefers: this.options.priorDefers ?? {},
|
|
1026
1128
|
stepsToFulfill,
|
|
1027
1129
|
steps: /* @__PURE__ */ new Map(),
|
|
1028
1130
|
loop,
|
|
@@ -1037,6 +1139,7 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
1037
1139
|
return this.state.remainingStepsToBeSeen.size === 0;
|
|
1038
1140
|
},
|
|
1039
1141
|
checkpointingStepBuffer: [],
|
|
1142
|
+
lazyOps: new require_lazyOps.LazyOps(),
|
|
1040
1143
|
metadata: /* @__PURE__ */ new Map()
|
|
1041
1144
|
};
|
|
1042
1145
|
}
|
|
@@ -1044,17 +1147,22 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
1044
1147
|
return Object.fromEntries(this.state.steps);
|
|
1045
1148
|
}
|
|
1046
1149
|
createFnArg() {
|
|
1047
|
-
const step = this.createStepTools();
|
|
1150
|
+
const { step, defer } = this.createStepTools();
|
|
1048
1151
|
const experimentStepRun = step[require_InngestStepTools.experimentStepRunSymbol];
|
|
1049
1152
|
let fnArg = {
|
|
1050
1153
|
...this.options.data,
|
|
1051
1154
|
step,
|
|
1052
|
-
group: require_InngestGroupTools.createGroupTools({ experimentStepRun })
|
|
1155
|
+
group: require_InngestGroupTools.createGroupTools({ experimentStepRun }),
|
|
1156
|
+
defer
|
|
1053
1157
|
};
|
|
1158
|
+
if (this.options.handlerKind === "defer") {
|
|
1159
|
+
delete fnArg.event.data._inngest;
|
|
1160
|
+
for (const event of fnArg.events) delete event.data._inngest;
|
|
1161
|
+
}
|
|
1054
1162
|
/**
|
|
1055
1163
|
* Handle use of the `onFailure` option by deserializing the error.
|
|
1056
1164
|
*/
|
|
1057
|
-
if (this.options.
|
|
1165
|
+
if (this.options.handlerKind === "failure") {
|
|
1058
1166
|
const eventData = zod_v3.z.object({ error: require_types.jsonErrorSchema }).parse(fnArg.event?.data);
|
|
1059
1167
|
fnArg = {
|
|
1060
1168
|
...fnArg,
|
|
@@ -1183,6 +1291,30 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
1183
1291
|
};
|
|
1184
1292
|
const stepHandler = async ({ args, matchOp, opts }) => {
|
|
1185
1293
|
const opId = matchOp(require_InngestStepTools.getStepOptions(args[0]), ...args.slice(1));
|
|
1294
|
+
if (require_lazyOps.isLazyOp(opts, opId)) {
|
|
1295
|
+
const hashedId$1 = _internals.hashId(opId.id);
|
|
1296
|
+
if (this.state.lazyOps.hasId(hashedId$1)) {
|
|
1297
|
+
this.options.client[require_Inngest.internalLoggerSymbol].warn({
|
|
1298
|
+
runId: this.fnArg.runId,
|
|
1299
|
+
id: opId.userland?.id ?? opId.id
|
|
1300
|
+
}, "defer skipped: duplicate ID within run");
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
if (this.state.priorDefers[hashedId$1]) {
|
|
1304
|
+
this.state.lazyOps.markSeen(hashedId$1);
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
this.state.lazyOps.push({
|
|
1308
|
+
id: hashedId$1,
|
|
1309
|
+
op: opId.op,
|
|
1310
|
+
name: opId.name,
|
|
1311
|
+
displayName: opId.displayName ?? opId.id,
|
|
1312
|
+
opts: opId.opts,
|
|
1313
|
+
userland: opId.userland,
|
|
1314
|
+
data: null
|
|
1315
|
+
});
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1186
1318
|
if (this.state.executingStep)
|
|
1187
1319
|
/**
|
|
1188
1320
|
* If a step is found after asynchronous actions during another step's
|
|
@@ -1304,7 +1436,75 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
1304
1436
|
} else pushStepToReport(step);
|
|
1305
1437
|
return promise;
|
|
1306
1438
|
};
|
|
1307
|
-
return
|
|
1439
|
+
return {
|
|
1440
|
+
step: require_InngestStepTools.createStepTools(this.options.client, this, stepHandler),
|
|
1441
|
+
defer: this.buildDefer(stepHandler)
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Build the `defer(idOrOptions, { function, data })` method exposed on
|
|
1446
|
+
* every handler context. Validates `data` against the target function's
|
|
1447
|
+
* schema (if any) and emits a `DeferAdd` opcode that routes to the
|
|
1448
|
+
* target's companion function slug.
|
|
1449
|
+
*
|
|
1450
|
+
* `defer()` is fire-and-forget: a misuse should not derail the user's
|
|
1451
|
+
* handler. Validation failures (wrong function, async schema validator,
|
|
1452
|
+
* schema mismatch) are logged and the call is silently skipped.
|
|
1453
|
+
*/
|
|
1454
|
+
buildDefer(stepHandler) {
|
|
1455
|
+
return (idOrOptions, { function: deferFn, data }) => {
|
|
1456
|
+
const log = this.options.client[require_Inngest.internalLoggerSymbol];
|
|
1457
|
+
const runId = this.fnArg.runId;
|
|
1458
|
+
try {
|
|
1459
|
+
if (!require_marker.isDeferredFunction(deferFn)) {
|
|
1460
|
+
log.error({ runId }, "defer skipped: function not created via createDefer");
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
const { schema } = deferFn;
|
|
1464
|
+
const deferFnSlug = deferFn.id(this.options.client.id);
|
|
1465
|
+
let input = data;
|
|
1466
|
+
if (schema) {
|
|
1467
|
+
const result = schema["~standard"].validate(data);
|
|
1468
|
+
if (result instanceof Promise) {
|
|
1469
|
+
log.error({ runId }, "defer() requires a synchronous schema validator. The defer call was skipped.");
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
if (result.issues) {
|
|
1473
|
+
log.error({
|
|
1474
|
+
runId,
|
|
1475
|
+
issues: result.issues
|
|
1476
|
+
}, "defer skipped: schema validation failed");
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
input = result.value ?? data;
|
|
1480
|
+
}
|
|
1481
|
+
stepHandler({
|
|
1482
|
+
args: [idOrOptions, input],
|
|
1483
|
+
matchOp: (stepOptions, inputArg) => ({
|
|
1484
|
+
id: stepOptions.id,
|
|
1485
|
+
mode: require_types.StepMode.Sync,
|
|
1486
|
+
op: require_types.StepOpCode.DeferAdd,
|
|
1487
|
+
name: stepOptions.name ?? stepOptions.id,
|
|
1488
|
+
displayName: stepOptions.name ?? stepOptions.id,
|
|
1489
|
+
opts: {
|
|
1490
|
+
fn_slug: deferFnSlug,
|
|
1491
|
+
input: inputArg
|
|
1492
|
+
},
|
|
1493
|
+
userland: { id: stepOptions.id }
|
|
1494
|
+
})
|
|
1495
|
+
}).catch((err) => {
|
|
1496
|
+
log.error({
|
|
1497
|
+
runId,
|
|
1498
|
+
err
|
|
1499
|
+
}, "defer skipped: unexpected error");
|
|
1500
|
+
});
|
|
1501
|
+
} catch (err) {
|
|
1502
|
+
log.error({
|
|
1503
|
+
runId,
|
|
1504
|
+
err
|
|
1505
|
+
}, "defer skipped: unexpected error");
|
|
1506
|
+
}
|
|
1507
|
+
};
|
|
1308
1508
|
}
|
|
1309
1509
|
/**
|
|
1310
1510
|
* Applies middleware transformations to a step, resolves ID collisions,
|
|
@@ -1386,14 +1586,19 @@ var InngestExecutionEngine = class extends require_InngestExecution.InngestExecu
|
|
|
1386
1586
|
return userlandStep;
|
|
1387
1587
|
}
|
|
1388
1588
|
getUserFnToRun() {
|
|
1389
|
-
|
|
1390
|
-
|
|
1589
|
+
switch (this.options.handlerKind) {
|
|
1590
|
+
case "defer": return this.options.fn["fn"];
|
|
1591
|
+
case "failure":
|
|
1592
|
+
if (!this.options.fn["onFailureFn"])
|
|
1391
1593
|
/**
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1594
|
+
* Somehow, we've ended up detecting that this is a failure handler
|
|
1595
|
+
* but doesn't have an `onFailure` function. This should never
|
|
1596
|
+
* happen.
|
|
1597
|
+
*/
|
|
1598
|
+
throw new Error("Cannot find function `onFailure` handler");
|
|
1599
|
+
return this.options.fn["onFailureFn"];
|
|
1600
|
+
default: return this.options.fn["fn"];
|
|
1601
|
+
}
|
|
1397
1602
|
}
|
|
1398
1603
|
initializeTimer(state) {
|
|
1399
1604
|
if (!this.options.requestedRunStep) return;
|