inngest 2.7.2 → 3.0.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.
Files changed (143) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/api/api.js +4 -4
  3. package/api/schema.d.ts +54 -6
  4. package/api/schema.d.ts.map +1 -1
  5. package/api/schema.js +17 -7
  6. package/api/schema.js.map +1 -1
  7. package/cloudflare.d.ts +6 -3
  8. package/cloudflare.d.ts.map +1 -1
  9. package/cloudflare.js +19 -41
  10. package/cloudflare.js.map +1 -1
  11. package/components/EventSchemas.d.ts +1 -12
  12. package/components/EventSchemas.d.ts.map +1 -1
  13. package/components/EventSchemas.js.map +1 -1
  14. package/components/Inngest.d.ts +44 -57
  15. package/components/Inngest.d.ts.map +1 -1
  16. package/components/Inngest.js +47 -26
  17. package/components/Inngest.js.map +1 -1
  18. package/components/InngestCommHandler.d.ts +156 -198
  19. package/components/InngestCommHandler.d.ts.map +1 -1
  20. package/components/InngestCommHandler.js +311 -305
  21. package/components/InngestCommHandler.js.map +1 -1
  22. package/components/InngestFunction.d.ts +9 -82
  23. package/components/InngestFunction.d.ts.map +1 -1
  24. package/components/InngestFunction.js +21 -413
  25. package/components/InngestFunction.js.map +1 -1
  26. package/components/InngestMiddleware.d.ts +37 -26
  27. package/components/InngestMiddleware.d.ts.map +1 -1
  28. package/components/InngestMiddleware.js +1 -3
  29. package/components/InngestMiddleware.js.map +1 -1
  30. package/components/InngestStepTools.d.ts +69 -37
  31. package/components/InngestStepTools.d.ts.map +1 -1
  32. package/components/InngestStepTools.js +34 -95
  33. package/components/InngestStepTools.js.map +1 -1
  34. package/components/NonRetriableError.d.ts.map +1 -1
  35. package/components/NonRetriableError.js +1 -0
  36. package/components/NonRetriableError.js.map +1 -1
  37. package/components/RetryAfterError.d.ts +38 -0
  38. package/components/RetryAfterError.d.ts.map +1 -0
  39. package/components/RetryAfterError.js +42 -0
  40. package/components/RetryAfterError.js.map +1 -0
  41. package/components/execution/InngestExecution.d.ts +72 -0
  42. package/components/execution/InngestExecution.d.ts.map +1 -0
  43. package/components/execution/InngestExecution.js +23 -0
  44. package/components/execution/InngestExecution.js.map +1 -0
  45. package/components/execution/v0.d.ts +114 -0
  46. package/components/execution/v0.d.ts.map +1 -0
  47. package/components/execution/v0.js +394 -0
  48. package/components/execution/v0.js.map +1 -0
  49. package/components/execution/v1.d.ts +88 -0
  50. package/components/execution/v1.d.ts.map +1 -0
  51. package/components/execution/v1.js +673 -0
  52. package/components/execution/v1.js.map +1 -0
  53. package/deno/fresh.d.ts +3 -3
  54. package/deno/fresh.d.ts.map +1 -1
  55. package/deno/fresh.js +17 -38
  56. package/deno/fresh.js.map +1 -1
  57. package/digitalocean.d.ts +5 -5
  58. package/digitalocean.d.ts.map +1 -1
  59. package/digitalocean.js +14 -46
  60. package/digitalocean.js.map +1 -1
  61. package/edge.d.ts +5 -5
  62. package/edge.d.ts.map +1 -1
  63. package/edge.js +16 -38
  64. package/edge.js.map +1 -1
  65. package/express.d.ts +7 -3
  66. package/express.d.ts.map +1 -1
  67. package/express.js +38 -45
  68. package/express.js.map +1 -1
  69. package/fastify.d.ts +8 -3
  70. package/fastify.d.ts.map +1 -1
  71. package/fastify.js +37 -47
  72. package/fastify.js.map +1 -1
  73. package/h3.d.ts +4 -3
  74. package/h3.d.ts.map +1 -1
  75. package/h3.js +18 -45
  76. package/h3.js.map +1 -1
  77. package/helpers/ServerTiming.d.ts.map +1 -1
  78. package/helpers/ServerTiming.js +2 -1
  79. package/helpers/ServerTiming.js.map +1 -1
  80. package/helpers/consts.d.ts +23 -9
  81. package/helpers/consts.d.ts.map +1 -1
  82. package/helpers/consts.js +31 -13
  83. package/helpers/consts.js.map +1 -1
  84. package/helpers/devserver.d.ts +0 -34
  85. package/helpers/devserver.d.ts.map +1 -1
  86. package/helpers/devserver.js.map +1 -1
  87. package/helpers/env.d.ts +14 -6
  88. package/helpers/env.d.ts.map +1 -1
  89. package/helpers/env.js +4 -4
  90. package/helpers/env.js.map +1 -1
  91. package/helpers/errors.d.ts +37 -2
  92. package/helpers/errors.d.ts.map +1 -1
  93. package/helpers/errors.js +66 -15
  94. package/helpers/errors.js.map +1 -1
  95. package/helpers/functions.d.ts +52 -5
  96. package/helpers/functions.d.ts.map +1 -1
  97. package/helpers/functions.js +121 -22
  98. package/helpers/functions.js.map +1 -1
  99. package/helpers/promises.d.ts +45 -0
  100. package/helpers/promises.d.ts.map +1 -1
  101. package/helpers/promises.js +69 -1
  102. package/helpers/promises.js.map +1 -1
  103. package/helpers/strings.d.ts +6 -1
  104. package/helpers/strings.d.ts.map +1 -1
  105. package/helpers/strings.js +7 -2
  106. package/helpers/strings.js.map +1 -1
  107. package/helpers/types.d.ts +5 -17
  108. package/helpers/types.d.ts.map +1 -1
  109. package/index.d.ts +4 -2
  110. package/index.d.ts.map +1 -1
  111. package/index.js +5 -1
  112. package/index.js.map +1 -1
  113. package/lambda.d.ts +10 -8
  114. package/lambda.d.ts.map +1 -1
  115. package/lambda.js +48 -72
  116. package/lambda.js.map +1 -1
  117. package/next.d.ts +11 -5
  118. package/next.d.ts.map +1 -1
  119. package/next.js +84 -103
  120. package/next.js.map +1 -1
  121. package/nuxt.d.ts +3 -3
  122. package/nuxt.d.ts.map +1 -1
  123. package/nuxt.js +5 -6
  124. package/nuxt.js.map +1 -1
  125. package/package.json +5 -4
  126. package/redwood.d.ts +4 -3
  127. package/redwood.d.ts.map +1 -1
  128. package/redwood.js +22 -48
  129. package/redwood.js.map +1 -1
  130. package/remix.d.ts +7 -5
  131. package/remix.d.ts.map +1 -1
  132. package/remix.js +15 -36
  133. package/remix.js.map +1 -1
  134. package/types.d.ts +126 -220
  135. package/types.d.ts.map +1 -1
  136. package/types.js +24 -45
  137. package/types.js.map +1 -1
  138. package/version.d.ts +1 -1
  139. package/version.js +1 -1
  140. package/helpers/scalar.d.ts +0 -8
  141. package/helpers/scalar.d.ts.map +0 -1
  142. package/helpers/scalar.js +0 -19
  143. package/helpers/scalar.js.map +0 -1
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ var _V0InngestExecution_instances, _V0InngestExecution_state, _V0InngestExecution_execution, _V0InngestExecution_userFnToRun, _V0InngestExecution_fnArg, _V0InngestExecution_start, _V0InngestExecution_initializeMiddleware, _V0InngestExecution_createExecutionState, _V0InngestExecution_getUserFnToRun, _V0InngestExecution_createFnArg, _V0InngestExecution_transformInput, _V0InngestExecution_getEarlyExecRunStep, _V0InngestExecution_transformOutput;
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports._internals = exports.V0InngestExecution = exports.createV0InngestExecution = void 0;
30
+ const canonicalize_1 = __importDefault(require("canonicalize"));
31
+ const hash_js_1 = require("hash.js");
32
+ const zod_1 = require("zod");
33
+ const errors_1 = require("../../helpers/errors");
34
+ const functions_1 = require("../../helpers/functions");
35
+ const promises_1 = require("../../helpers/promises");
36
+ const types_1 = require("../../types");
37
+ const InngestMiddleware_1 = require("../InngestMiddleware");
38
+ const InngestStepTools_1 = require("../InngestStepTools");
39
+ const NonRetriableError_1 = require("../NonRetriableError");
40
+ const RetryAfterError_1 = require("../RetryAfterError");
41
+ const InngestExecution_1 = require("./InngestExecution");
42
+ const createV0InngestExecution = (options) => {
43
+ return new V0InngestExecution(options);
44
+ };
45
+ exports.createV0InngestExecution = createV0InngestExecution;
46
+ class V0InngestExecution extends InngestExecution_1.InngestExecution {
47
+ constructor(options) {
48
+ super(options);
49
+ _V0InngestExecution_instances.add(this);
50
+ _V0InngestExecution_state.set(this, void 0);
51
+ _V0InngestExecution_execution.set(this, void 0);
52
+ _V0InngestExecution_userFnToRun.set(this, void 0);
53
+ _V0InngestExecution_fnArg.set(this, void 0);
54
+ __classPrivateFieldSet(this, _V0InngestExecution_userFnToRun, __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_getUserFnToRun).call(this), "f");
55
+ __classPrivateFieldSet(this, _V0InngestExecution_state, __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_createExecutionState).call(this), "f");
56
+ __classPrivateFieldSet(this, _V0InngestExecution_fnArg, __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_createFnArg).call(this), "f");
57
+ }
58
+ start() {
59
+ var _a;
60
+ this.debug("starting V0 execution");
61
+ return (__classPrivateFieldSet(this, _V0InngestExecution_execution, (_a = __classPrivateFieldGet(this, _V0InngestExecution_execution, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_start).call(this).then((result) => {
62
+ this.debug("result:", result);
63
+ return result;
64
+ }), "f"));
65
+ }
66
+ }
67
+ exports.V0InngestExecution = V0InngestExecution;
68
+ _V0InngestExecution_state = new WeakMap(), _V0InngestExecution_execution = new WeakMap(), _V0InngestExecution_userFnToRun = new WeakMap(), _V0InngestExecution_fnArg = new WeakMap(), _V0InngestExecution_instances = new WeakSet(), _V0InngestExecution_start = async function _V0InngestExecution_start() {
69
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
70
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks = await __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_initializeMiddleware).call(this);
71
+ try {
72
+ await __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_transformInput).call(this);
73
+ await ((_b = (_a = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).beforeMemoization) === null || _b === void 0 ? void 0 : _b.call(_a));
74
+ if (__classPrivateFieldGet(this, _V0InngestExecution_state, "f").opStack.length === 0 && !this.options.requestedRunStep) {
75
+ await ((_d = (_c = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).afterMemoization) === null || _d === void 0 ? void 0 : _d.call(_c));
76
+ await ((_f = (_e = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).beforeExecution) === null || _f === void 0 ? void 0 : _f.call(_e));
77
+ }
78
+ const userFnPromise = (0, promises_1.runAsPromise)(() => __classPrivateFieldGet(this, _V0InngestExecution_userFnToRun, "f").call(this, __classPrivateFieldGet(this, _V0InngestExecution_fnArg, "f")));
79
+ let pos = -1;
80
+ do {
81
+ if (pos >= 0) {
82
+ if (!this.options.requestedRunStep &&
83
+ pos === __classPrivateFieldGet(this, _V0InngestExecution_state, "f").opStack.length - 1) {
84
+ await ((_h = (_g = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).afterMemoization) === null || _h === void 0 ? void 0 : _h.call(_g));
85
+ await ((_k = (_j = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).beforeExecution) === null || _k === void 0 ? void 0 : _k.call(_j));
86
+ }
87
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").tickOps = {};
88
+ const incomingOp = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").opStack[pos];
89
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").currentOp = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").allFoundOps[incomingOp.id];
90
+ if (!__classPrivateFieldGet(this, _V0InngestExecution_state, "f").currentOp) {
91
+ /**
92
+ * We're trying to resume the function, but we can't find where to go.
93
+ *
94
+ * This means that either the function has changed or there are async
95
+ * actions in-between steps that we haven't noticed in previous
96
+ * executions.
97
+ *
98
+ * Whichever the case, this is bad and we can't continue in this
99
+ * undefined state.
100
+ */
101
+ throw new NonRetriableError_1.NonRetriableError((0, errors_1.prettyError)({
102
+ whatHappened: " Your function was stopped from running",
103
+ why: "We couldn't resume your function's state because it may have changed since the run started or there are async actions in-between steps that we haven't noticed in previous executions.",
104
+ consequences: "Continuing to run the function may result in unexpected behaviour, so we've stopped your function to ensure nothing unexpected happened!",
105
+ toFixNow: "Ensure that your function is either entirely step-based or entirely non-step-based, by either wrapping all asynchronous logic in `step.run()` calls or by removing all `step.*()` calls.",
106
+ otherwise: "For more information on why step functions work in this manner, see https://www.inngest.com/docs/functions/multi-step#gotchas",
107
+ stack: true,
108
+ code: errors_1.ErrCode.NON_DETERMINISTIC_FUNCTION,
109
+ }));
110
+ }
111
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").currentOp.fulfilled = true;
112
+ if (typeof incomingOp.data !== "undefined") {
113
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").currentOp.resolve(incomingOp.data);
114
+ }
115
+ else {
116
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").currentOp.reject(incomingOp.error);
117
+ }
118
+ }
119
+ await (0, promises_1.resolveAfterPending)();
120
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").reset();
121
+ pos++;
122
+ } while (pos < __classPrivateFieldGet(this, _V0InngestExecution_state, "f").opStack.length);
123
+ await ((_m = (_l = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).afterMemoization) === null || _m === void 0 ? void 0 : _m.call(_l));
124
+ const discoveredOps = Object.values(__classPrivateFieldGet(this, _V0InngestExecution_state, "f").tickOps).map(tickOpToOutgoing);
125
+ const runStep = this.options.requestedRunStep ||
126
+ __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_getEarlyExecRunStep).call(this, discoveredOps);
127
+ if (runStep) {
128
+ const userFnOp = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").allFoundOps[runStep];
129
+ const stepToRun = userFnOp === null || userFnOp === void 0 ? void 0 : userFnOp.fn;
130
+ if (!stepToRun) {
131
+ throw new Error(`Bad stack; executor requesting to run unknown step "${runStep}"`);
132
+ }
133
+ const outgoingUserFnOp = Object.assign(Object.assign({}, tickOpToOutgoing(userFnOp)), { op: types_1.StepOpCode.RunStep });
134
+ await ((_p = (_o = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).beforeExecution) === null || _p === void 0 ? void 0 : _p.call(_o));
135
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").executingStep = true;
136
+ const result = await (0, promises_1.runAsPromise)(stepToRun)
137
+ .finally(() => {
138
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").executingStep = false;
139
+ })
140
+ .catch(async (error) => {
141
+ return await __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_transformOutput).call(this, { error }, outgoingUserFnOp);
142
+ })
143
+ .then(async (data) => {
144
+ var _a, _b;
145
+ await ((_b = (_a = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.afterExecution) === null || _b === void 0 ? void 0 : _b.call(_a));
146
+ return await __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_transformOutput).call(this, { data }, outgoingUserFnOp);
147
+ });
148
+ const { type: _type } = result, rest = __rest(result, ["type"]);
149
+ return { type: "step-ran", step: Object.assign(Object.assign({}, outgoingUserFnOp), rest) };
150
+ }
151
+ if (!discoveredOps.length) {
152
+ const fnRet = await Promise.race([
153
+ userFnPromise.then((data) => ({ type: "complete", data })),
154
+ (0, promises_1.resolveNextTick)().then(() => ({ type: "incomplete" })),
155
+ ]);
156
+ if (fnRet.type === "complete") {
157
+ await ((_r = (_q = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).afterExecution) === null || _r === void 0 ? void 0 : _r.call(_q));
158
+ const allOpsFulfilled = Object.values(__classPrivateFieldGet(this, _V0InngestExecution_state, "f").allFoundOps).every((op) => {
159
+ return op.fulfilled;
160
+ });
161
+ if (allOpsFulfilled) {
162
+ return await __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_transformOutput).call(this, { data: fnRet.data });
163
+ }
164
+ }
165
+ else if (!__classPrivateFieldGet(this, _V0InngestExecution_state, "f").hasUsedTools) {
166
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").nonStepFnDetected = true;
167
+ const data = await userFnPromise;
168
+ await ((_t = (_s = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).afterExecution) === null || _t === void 0 ? void 0 : _t.call(_s));
169
+ return await __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_transformOutput).call(this, { data });
170
+ }
171
+ else {
172
+ const hasOpsPending = Object.values(__classPrivateFieldGet(this, _V0InngestExecution_state, "f").allFoundOps).some((op) => {
173
+ return op.fulfilled === false;
174
+ });
175
+ if (!hasOpsPending) {
176
+ throw new NonRetriableError_1.NonRetriableError((0, errors_1.functionStoppedRunningErr)(errors_1.ErrCode.ASYNC_DETECTED_AFTER_MEMOIZATION));
177
+ }
178
+ }
179
+ }
180
+ await ((_v = (_u = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).afterExecution) === null || _v === void 0 ? void 0 : _v.call(_u));
181
+ return {
182
+ type: "steps-found",
183
+ steps: discoveredOps,
184
+ };
185
+ }
186
+ catch (error) {
187
+ return await __classPrivateFieldGet(this, _V0InngestExecution_instances, "m", _V0InngestExecution_transformOutput).call(this, { error });
188
+ }
189
+ finally {
190
+ await ((_x = (_w = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks).beforeResponse) === null || _x === void 0 ? void 0 : _x.call(_w));
191
+ }
192
+ }, _V0InngestExecution_initializeMiddleware = async function _V0InngestExecution_initializeMiddleware() {
193
+ const ctx = this.options.data;
194
+ const hooks = await (0, InngestMiddleware_1.getHookStack)(this.options.fn["middleware"], "onFunctionRun", {
195
+ ctx,
196
+ fn: this.options.fn,
197
+ steps: Object.values(this.options.stepState),
198
+ }, {
199
+ transformInput: (prev, output) => {
200
+ return {
201
+ ctx: Object.assign(Object.assign({}, prev.ctx), output === null || output === void 0 ? void 0 : output.ctx),
202
+ fn: this.options.fn,
203
+ steps: prev.steps.map((step, i) => {
204
+ var _a;
205
+ return (Object.assign(Object.assign({}, step), (_a = output === null || output === void 0 ? void 0 : output.steps) === null || _a === void 0 ? void 0 : _a[i]));
206
+ }),
207
+ };
208
+ },
209
+ transformOutput: (prev, output) => {
210
+ return {
211
+ result: Object.assign(Object.assign({}, prev.result), output === null || output === void 0 ? void 0 : output.result),
212
+ step: prev.step,
213
+ };
214
+ },
215
+ });
216
+ return hooks;
217
+ }, _V0InngestExecution_createExecutionState = function _V0InngestExecution_createExecutionState() {
218
+ const state = {
219
+ allFoundOps: {},
220
+ tickOps: {},
221
+ tickOpHashes: {},
222
+ currentOp: undefined,
223
+ hasUsedTools: false,
224
+ reset: () => {
225
+ state.tickOpHashes = {};
226
+ state.allFoundOps = Object.assign(Object.assign({}, state.allFoundOps), state.tickOps);
227
+ },
228
+ nonStepFnDetected: false,
229
+ executingStep: false,
230
+ opStack: this.options.stepCompletionOrder.reduce((acc, stepId) => {
231
+ const stepState = this.options.stepState[stepId];
232
+ if (!stepState) {
233
+ return acc;
234
+ }
235
+ return [...acc, stepState];
236
+ }, []),
237
+ };
238
+ return state;
239
+ }, _V0InngestExecution_getUserFnToRun = function _V0InngestExecution_getUserFnToRun() {
240
+ if (!this.options.isFailureHandler) {
241
+ return this.options.fn["fn"];
242
+ }
243
+ if (!this.options.fn["onFailureFn"]) {
244
+ /**
245
+ * Somehow, we've ended up detecting that this is a failure handler but
246
+ * doesn't have an `onFailure` function. This should never happen.
247
+ */
248
+ throw new Error("Cannot find function `onFailure` handler");
249
+ }
250
+ return this.options.fn["onFailureFn"];
251
+ }, _V0InngestExecution_createFnArg = function _V0InngestExecution_createFnArg() {
252
+ var _a;
253
+ // Start referencing everything
254
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").tickOps = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").allFoundOps;
255
+ /**
256
+ * Create a unique hash of an operation using only a subset of the operation's
257
+ * properties; will never use `data` and will guarantee the order of the
258
+ * object so we don't rely on individual tools for that.
259
+ *
260
+ * If the operation already contains an ID, the current ID will be used
261
+ * instead, so that users can provide their own IDs.
262
+ */
263
+ const hashOp = (
264
+ /**
265
+ * The op to generate a hash from. We only use a subset of the op's
266
+ * properties when creating the hash.
267
+ */
268
+ op) => {
269
+ var _a, _b, _c, _d;
270
+ /**
271
+ * It's difficult for v0 to understand whether or not an op has
272
+ * historically contained a custom ID, as all step usage now require them.
273
+ *
274
+ * For this reason, we make the assumption that steps in v0 do not have a
275
+ * custom ID and generate one for them as we would in all recommendations
276
+ * and examples.
277
+ */
278
+ const obj = {
279
+ parent: (_b = (_a = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").currentOp) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null,
280
+ op: op.op,
281
+ name: op.name,
282
+ opts: (_c = op.opts) !== null && _c !== void 0 ? _c : null,
283
+ };
284
+ const collisionHash = exports._internals.hashData(obj);
285
+ const pos = (__classPrivateFieldGet(this, _V0InngestExecution_state, "f").tickOpHashes[collisionHash] =
286
+ ((_d = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").tickOpHashes[collisionHash]) !== null && _d !== void 0 ? _d : -1) + 1);
287
+ return Object.assign(Object.assign({}, op), { id: exports._internals.hashData(Object.assign({ pos }, obj)) });
288
+ };
289
+ const stepHandler = ({ args, matchOp, opts }) => {
290
+ if (__classPrivateFieldGet(this, _V0InngestExecution_state, "f").nonStepFnDetected) {
291
+ if ((opts === null || opts === void 0 ? void 0 : opts.nonStepExecuteInline) && opts.fn) {
292
+ return Promise.resolve(opts.fn(...args));
293
+ }
294
+ throw new NonRetriableError_1.NonRetriableError((0, errors_1.functionStoppedRunningErr)(errors_1.ErrCode.STEP_USED_AFTER_ASYNC));
295
+ }
296
+ if (__classPrivateFieldGet(this, _V0InngestExecution_state, "f").executingStep) {
297
+ throw new NonRetriableError_1.NonRetriableError((0, errors_1.prettyError)({
298
+ whatHappened: "Your function was stopped from running",
299
+ why: "We detected that you have nested `step.*` tooling.",
300
+ consequences: "Nesting `step.*` tooling is not supported.",
301
+ stack: true,
302
+ 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.",
303
+ otherwise: "For more information on step functions with Inngest, see https://www.inngest.com/docs/functions/multi-step",
304
+ code: errors_1.ErrCode.NESTING_STEPS,
305
+ }));
306
+ }
307
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hasUsedTools = true;
308
+ const stepOptions = (0, InngestStepTools_1.getStepOptions)(args[0]);
309
+ const opId = hashOp(matchOp(stepOptions, ...args.slice(1)));
310
+ return new Promise((resolve, reject) => {
311
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").tickOps[opId.id] = Object.assign(Object.assign(Object.assign({}, opId), ((opts === null || opts === void 0 ? void 0 : opts.fn) ? { fn: () => { var _a; return (_a = opts.fn) === null || _a === void 0 ? void 0 : _a.call(opts, ...args); } } : {})), { resolve,
312
+ reject, fulfilled: false });
313
+ });
314
+ };
315
+ const step = (0, InngestStepTools_1.createStepTools)(this.options.client, stepHandler);
316
+ let fnArg = Object.assign(Object.assign({}, this.options.data), { step });
317
+ if (this.options.isFailureHandler) {
318
+ const eventData = zod_1.z
319
+ .object({ error: types_1.failureEventErrorSchema })
320
+ .parse((_a = fnArg.event) === null || _a === void 0 ? void 0 : _a.data);
321
+ fnArg = Object.assign(Object.assign({}, fnArg), { error: (0, errors_1.deserializeError)(eventData.error) });
322
+ }
323
+ return fnArg;
324
+ }, _V0InngestExecution_transformInput =
325
+ /**
326
+ * Using middleware, transform input before running.
327
+ */
328
+ async function _V0InngestExecution_transformInput() {
329
+ var _a, _b;
330
+ const inputMutations = await ((_b = (_a = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.transformInput) === null || _b === void 0 ? void 0 : _b.call(_a, {
331
+ ctx: Object.assign({}, __classPrivateFieldGet(this, _V0InngestExecution_fnArg, "f")),
332
+ steps: Object.values(this.options.stepState),
333
+ fn: this.options.fn,
334
+ }));
335
+ if (inputMutations === null || inputMutations === void 0 ? void 0 : inputMutations.ctx) {
336
+ __classPrivateFieldSet(this, _V0InngestExecution_fnArg, inputMutations.ctx, "f");
337
+ }
338
+ if (inputMutations === null || inputMutations === void 0 ? void 0 : inputMutations.steps) {
339
+ __classPrivateFieldGet(this, _V0InngestExecution_state, "f").opStack = [...inputMutations.steps];
340
+ }
341
+ }, _V0InngestExecution_getEarlyExecRunStep = function _V0InngestExecution_getEarlyExecRunStep(ops) {
342
+ if (ops.length !== 1)
343
+ return;
344
+ const op = ops[0];
345
+ if (op &&
346
+ op.op === types_1.StepOpCode.StepPlanned &&
347
+ typeof op.opts === "undefined") {
348
+ return op.id;
349
+ }
350
+ }, _V0InngestExecution_transformOutput =
351
+ /**
352
+ * Using middleware, transform output before returning.
353
+ */
354
+ async function _V0InngestExecution_transformOutput(dataOrError, step) {
355
+ var _a, _b;
356
+ const output = Object.assign({}, dataOrError);
357
+ if (typeof output.error !== "undefined") {
358
+ output.data = (0, errors_1.serializeError)(output.error);
359
+ }
360
+ const transformedOutput = await ((_b = (_a = __classPrivateFieldGet(this, _V0InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.transformOutput) === null || _b === void 0 ? void 0 : _b.call(_a, {
361
+ result: Object.assign({}, output),
362
+ step,
363
+ }));
364
+ const { data, error } = Object.assign(Object.assign({}, output), transformedOutput === null || transformedOutput === void 0 ? void 0 : transformedOutput.result);
365
+ if (typeof error !== "undefined") {
366
+ /**
367
+ * Ensure we give middleware the chance to decide on retriable behaviour
368
+ * by looking at the error returned from output transformation.
369
+ */
370
+ let retriable = !(error instanceof NonRetriableError_1.NonRetriableError);
371
+ if (retriable && error instanceof RetryAfterError_1.RetryAfterError) {
372
+ retriable = error.retryAfter;
373
+ }
374
+ const serializedError = (0, errors_1.serializeError)(error);
375
+ return { type: "function-rejected", error: serializedError, retriable };
376
+ }
377
+ return { type: "function-resolved", data: (0, functions_1.undefinedToNull)(data) };
378
+ };
379
+ const tickOpToOutgoing = (op) => {
380
+ return {
381
+ op: op.op,
382
+ id: op.id,
383
+ name: op.name,
384
+ opts: op.opts,
385
+ };
386
+ };
387
+ const hashData = (op) => {
388
+ return (0, hash_js_1.sha1)().update((0, canonicalize_1.default)(op)).digest("hex");
389
+ };
390
+ /**
391
+ * Exported for testing.
392
+ */
393
+ exports._internals = { hashData };
394
+ //# sourceMappingURL=v0.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v0.js","sourceRoot":"","sources":["../../../src/components/execution/v0.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAwC;AACxC,qCAA+B;AAC/B,6BAAwB;AACxB,iDAM8B;AAC9B,uDAA0D;AAC1D,qDAIgC;AAEhC,uCAaqB;AACrB,4DAAuE;A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,GAAG,IAAA,uBAAc,EAAC,KAAK,CAAC,CAAC;QAE9C,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;KACzE;IAED,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,IAAA,2BAAe,EAAC,IAAI,CAAC,EAAE,CAAC;AACpE,CAAC;AAoGH,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAc,EAAE;IAClD,OAAO;QACL,EAAE,EAAE,EAAE,CAAC,EAAE;QACT,EAAE,EAAE,EAAE,CAAC,EAAE;QACT,IAAI,EAAE,EAAE,CAAC,IAAI;QACb,IAAI,EAAE,EAAE,CAAC,IAAI;KACd,CAAC;AACJ,CAAC,CAAC;AAeF,MAAM,QAAQ,GAAG,CAAC,EAAc,EAAU,EAAE;IAC1C,OAAO,IAAA,cAAI,GAAE,CAAC,MAAM,CAAC,IAAA,sBAAY,EAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,UAAU,GAAG,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { type Simplify } from "type-fest";
2
+ import { type OutgoingOp } from "../../types";
3
+ import { type RunHookStack } from "../InngestMiddleware";
4
+ import { type FoundStep } from "../InngestStepTools";
5
+ import { type InngestExecutionFactory, type MemoizedOp } from "./InngestExecution";
6
+ export declare const createV1InngestExecution: InngestExecutionFactory;
7
+ /**
8
+ * Types of checkpoints that can be reached during execution.
9
+ */
10
+ export interface Checkpoints {
11
+ "steps-found": {
12
+ steps: [FoundStep, ...FoundStep[]];
13
+ };
14
+ "function-rejected": {
15
+ error: unknown;
16
+ };
17
+ "function-resolved": {
18
+ data: unknown;
19
+ };
20
+ "step-not-found": {
21
+ step: OutgoingOp;
22
+ };
23
+ }
24
+ type Checkpoint = {
25
+ [K in keyof Checkpoints]: Simplify<{
26
+ type: K;
27
+ } & Checkpoints[K]>;
28
+ }[keyof Checkpoints];
29
+ export interface V1ExecutionState {
30
+ /**
31
+ * A value that indicates that we're executing this step. Can be used to
32
+ * ensure steps are not accidentally nested until we support this across all
33
+ * platforms.
34
+ */
35
+ executingStep?: Readonly<Omit<OutgoingOp, "id">>;
36
+ /**
37
+ * A map of step IDs to their data, used to fill previously-completed steps
38
+ * with state from the executor.
39
+ */
40
+ stepState: Record<string, MemoizedOp>;
41
+ /**
42
+ * A map of step IDs to their functions to run. The executor can request a
43
+ * specific step to run, so we need to store the function to run here.
44
+ */
45
+ steps: Record<string, FoundStep>;
46
+ /**
47
+ * A flag which represents whether or not steps are understood to be used in
48
+ * this function. This is used to determine whether or not we should run
49
+ * some steps (such as `step.sendEvent`) inline as they are found.
50
+ */
51
+ hasSteps: boolean;
52
+ /**
53
+ * The core loop - a generator used to take an action upon finding the next
54
+ * checkpoint. Manages the flow of execution and cleaning up after itself.
55
+ */
56
+ loop: AsyncGenerator<Checkpoint, void, void>;
57
+ /**
58
+ * A function that resolves the `Promise` returned by `waitForNextDecision`.
59
+ */
60
+ setCheckpoint: (data: Checkpoint) => void;
61
+ /**
62
+ * Initialized middleware hooks for this execution.
63
+ *
64
+ * Middleware hooks are cached to ensure they can only be run once, which
65
+ * means that these hooks can be called in many different places to ensure we
66
+ * handle all possible execution paths.
67
+ */
68
+ hooks?: RunHookStack;
69
+ /**
70
+ * Returns whether or not all state passed from the executor has been used to
71
+ * fulfill found steps.
72
+ */
73
+ allStateUsed: () => boolean;
74
+ /**
75
+ * An ordered list of step IDs that represents the order in which their
76
+ * execution was completed.
77
+ */
78
+ stepCompletionOrder: string[];
79
+ }
80
+ /**
81
+ * Exported for testing.
82
+ */
83
+ export declare const _internals: {
84
+ hashOp: (op: OutgoingOp) => OutgoingOp;
85
+ hashId: (id: string) => string;
86
+ };
87
+ export {};
88
+ //# sourceMappingURL=v1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1.d.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