inngest 2.7.1 → 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 +52 -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 +91 -59
  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 +150 -218
  135. package/types.d.ts.map +1 -1
  136. package/types.js +38 -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,673 @@
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 __asyncValues = (this && this.__asyncValues) || function (o) {
14
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
15
+ var m = o[Symbol.asyncIterator], i;
16
+ 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);
17
+ 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); }); }; }
18
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
19
+ };
20
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
21
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
22
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
23
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
24
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
25
+ function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
26
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
27
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
28
+ function fulfill(value) { resume("next", value); }
29
+ function reject(value) { resume("throw", value); }
30
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
31
+ };
32
+ var _V1InngestExecution_instances, _V1InngestExecution_state, _V1InngestExecution_fnArg, _V1InngestExecution_checkpointHandlers, _V1InngestExecution_timeoutDuration, _V1InngestExecution_execution, _V1InngestExecution_userFnToRun, _V1InngestExecution_timeout, _V1InngestExecution_start, _V1InngestExecution_createCheckpointHandlers, _V1InngestExecution_getCheckpointHandler, _V1InngestExecution_tryExecuteStep, _V1InngestExecution_getEarlyExecRunStep, _V1InngestExecution_filterNewSteps, _V1InngestExecution_executeStep, _V1InngestExecution_startExecution, _V1InngestExecution_transformInput, _V1InngestExecution_transformOutput, _V1InngestExecution_createExecutionState, _V1InngestExecution_createFnArg, _V1InngestExecution_createStepTools, _V1InngestExecution_getUserFnToRun, _V1InngestExecution_initializeTimer, _V1InngestExecution_initializeMiddleware;
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports._internals = exports.createV1InngestExecution = void 0;
35
+ const hash_js_1 = require("hash.js");
36
+ const zod_1 = require("zod");
37
+ const consts_1 = require("../../helpers/consts");
38
+ const errors_1 = require("../../helpers/errors");
39
+ const functions_1 = require("../../helpers/functions");
40
+ const promises_1 = require("../../helpers/promises");
41
+ const types_1 = require("../../types");
42
+ const InngestMiddleware_1 = require("../InngestMiddleware");
43
+ const InngestStepTools_1 = require("../InngestStepTools");
44
+ const NonRetriableError_1 = require("../NonRetriableError");
45
+ const RetryAfterError_1 = require("../RetryAfterError");
46
+ const InngestExecution_1 = require("./InngestExecution");
47
+ const createV1InngestExecution = (options) => {
48
+ return new V1InngestExecution(options);
49
+ };
50
+ exports.createV1InngestExecution = createV1InngestExecution;
51
+ class V1InngestExecution extends InngestExecution_1.InngestExecution {
52
+ constructor(options) {
53
+ super(options);
54
+ _V1InngestExecution_instances.add(this);
55
+ _V1InngestExecution_state.set(this, void 0);
56
+ _V1InngestExecution_fnArg.set(this, void 0);
57
+ _V1InngestExecution_checkpointHandlers.set(this, void 0);
58
+ _V1InngestExecution_timeoutDuration.set(this, 1000 * 10);
59
+ _V1InngestExecution_execution.set(this, void 0);
60
+ _V1InngestExecution_userFnToRun.set(this, void 0);
61
+ /**
62
+ * If we're supposed to run a particular step via `requestedRunStep`, this
63
+ * will be a `Promise` that resolves after no steps have been found for
64
+ * `timeoutDuration` milliseconds.
65
+ *
66
+ * If we're not supposed to run a particular step, this will be `undefined`.
67
+ */
68
+ _V1InngestExecution_timeout.set(this, void 0);
69
+ __classPrivateFieldSet(this, _V1InngestExecution_userFnToRun, __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_getUserFnToRun).call(this), "f");
70
+ __classPrivateFieldSet(this, _V1InngestExecution_state, __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_createExecutionState).call(this), "f");
71
+ __classPrivateFieldSet(this, _V1InngestExecution_fnArg, __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_createFnArg).call(this), "f");
72
+ __classPrivateFieldSet(this, _V1InngestExecution_checkpointHandlers, __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_createCheckpointHandlers).call(this), "f");
73
+ __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_initializeTimer).call(this, __classPrivateFieldGet(this, _V1InngestExecution_state, "f"));
74
+ this.debug("created new V1 execution for run;", this.options.requestedRunStep
75
+ ? `wanting to run step "${this.options.requestedRunStep}"`
76
+ : "discovering steps");
77
+ this.debug("existing state keys:", Object.keys(__classPrivateFieldGet(this, _V1InngestExecution_state, "f").stepState));
78
+ }
79
+ /**
80
+ * Idempotently start the execution of the user's function.
81
+ */
82
+ start() {
83
+ var _a;
84
+ this.debug("starting V1 execution");
85
+ return (__classPrivateFieldSet(this, _V1InngestExecution_execution, (_a = __classPrivateFieldGet(this, _V1InngestExecution_execution, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_start).call(this).then((result) => {
86
+ this.debug("result:", result);
87
+ return result;
88
+ }), "f"));
89
+ }
90
+ }
91
+ _V1InngestExecution_state = new WeakMap(), _V1InngestExecution_fnArg = new WeakMap(), _V1InngestExecution_checkpointHandlers = new WeakMap(), _V1InngestExecution_timeoutDuration = new WeakMap(), _V1InngestExecution_execution = new WeakMap(), _V1InngestExecution_userFnToRun = new WeakMap(), _V1InngestExecution_timeout = new WeakMap(), _V1InngestExecution_instances = new WeakSet(), _V1InngestExecution_start =
92
+ /**
93
+ * Starts execution of the user's function and the core loop.
94
+ */
95
+ async function _V1InngestExecution_start() {
96
+ var _a, e_1, _b, _c;
97
+ var _d, _e;
98
+ try {
99
+ const allCheckpointHandler = __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_getCheckpointHandler).call(this, "");
100
+ __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks = await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_initializeMiddleware).call(this);
101
+ await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_startExecution).call(this);
102
+ try {
103
+ for (var _f = true, _g = __asyncValues(__classPrivateFieldGet(this, _V1InngestExecution_state, "f").loop), _h; _h = await _g.next(), _a = _h.done, !_a; _f = true) {
104
+ _c = _h.value;
105
+ _f = false;
106
+ const checkpoint = _c;
107
+ await allCheckpointHandler(checkpoint);
108
+ const handler = __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_getCheckpointHandler).call(this, checkpoint.type);
109
+ const result = await handler(checkpoint);
110
+ if (result) {
111
+ return result;
112
+ }
113
+ }
114
+ }
115
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
116
+ finally {
117
+ try {
118
+ if (!_f && !_a && (_b = _g.return)) await _b.call(_g);
119
+ }
120
+ finally { if (e_1) throw e_1.error; }
121
+ }
122
+ }
123
+ catch (error) {
124
+ return await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_transformOutput).call(this, { error });
125
+ }
126
+ finally {
127
+ void __classPrivateFieldGet(this, _V1InngestExecution_state, "f").loop.return();
128
+ await ((_e = (_d = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _d === void 0 ? void 0 : _d.beforeResponse) === null || _e === void 0 ? void 0 : _e.call(_d));
129
+ }
130
+ /**
131
+ * If we're here, the generator somehow finished without returning a value.
132
+ * This should never happen.
133
+ */
134
+ throw new Error("Core loop finished without returning a value");
135
+ }, _V1InngestExecution_createCheckpointHandlers = function _V1InngestExecution_createCheckpointHandlers() {
136
+ return {
137
+ /**
138
+ * Run for all checkpoints. Best used for logging or common actions.
139
+ * Use other handlers to return values and interrupt the core loop.
140
+ */
141
+ "": (checkpoint) => {
142
+ this.debug("checkpoint:", checkpoint);
143
+ },
144
+ /**
145
+ * The user's function has completed and returned a value.
146
+ */
147
+ "function-resolved": async (checkpoint) => {
148
+ return await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_transformOutput).call(this, { data: checkpoint.data });
149
+ },
150
+ /**
151
+ * The user's function has thrown an error.
152
+ */
153
+ "function-rejected": async (checkpoint) => {
154
+ return await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_transformOutput).call(this, { error: checkpoint.error });
155
+ },
156
+ /**
157
+ * We've found one or more steps. Here we may want to run a step or report
158
+ * them back to Inngest.
159
+ */
160
+ "steps-found": async ({ steps }) => {
161
+ const stepResult = await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_tryExecuteStep).call(this, steps);
162
+ if (stepResult) {
163
+ const transformResult = await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_transformOutput).call(this, stepResult);
164
+ /**
165
+ * Transforming output will always return either function rejection or
166
+ * resolution. In most cases, this can be immediately returned, but in
167
+ * this particular case we want to handle it differently.
168
+ */
169
+ if (transformResult.type === "function-resolved") {
170
+ return {
171
+ type: "step-ran",
172
+ step: exports._internals.hashOp(Object.assign(Object.assign({}, stepResult), { data: { data: transformResult.data } })),
173
+ };
174
+ }
175
+ return transformResult;
176
+ }
177
+ const newSteps = await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_filterNewSteps).call(this, Object.values(__classPrivateFieldGet(this, _V1InngestExecution_state, "f").steps));
178
+ if (newSteps) {
179
+ return {
180
+ type: "steps-found",
181
+ steps: newSteps,
182
+ };
183
+ }
184
+ },
185
+ /**
186
+ * While trying to find a step that Inngest has told us to run, we've
187
+ * timed out or have otherwise decided that it doesn't exist.
188
+ */
189
+ "step-not-found": ({ step }) => {
190
+ return { type: "step-not-found", step };
191
+ },
192
+ };
193
+ }, _V1InngestExecution_getCheckpointHandler = function _V1InngestExecution_getCheckpointHandler(type) {
194
+ return __classPrivateFieldGet(this, _V1InngestExecution_checkpointHandlers, "f")[type];
195
+ }, _V1InngestExecution_tryExecuteStep = async function _V1InngestExecution_tryExecuteStep(steps) {
196
+ var _a;
197
+ const hashedStepIdToRun = this.options.requestedRunStep || __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_getEarlyExecRunStep).call(this, steps);
198
+ if (!hashedStepIdToRun) {
199
+ return;
200
+ }
201
+ const step = steps.find((step) => step.hashedId === hashedStepIdToRun && step.fn);
202
+ if (step) {
203
+ return await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_executeStep).call(this, step);
204
+ }
205
+ /**
206
+ * Ensure we reset the timeout if we have a requested run step but couldn't
207
+ * find it, but also that we don't reset if we found and executed it.
208
+ */
209
+ void ((_a = __classPrivateFieldGet(this, _V1InngestExecution_timeout, "f")) === null || _a === void 0 ? void 0 : _a.reset());
210
+ }, _V1InngestExecution_getEarlyExecRunStep = function _V1InngestExecution_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_1.StepOpCode.StepPlanned &&
223
+ typeof op.opts === "undefined") {
224
+ return op.hashedId;
225
+ }
226
+ }, _V1InngestExecution_filterNewSteps = async function _V1InngestExecution_filterNewSteps(steps) {
227
+ var _a, _b, _c, _d, _e, _f;
228
+ if (this.options.requestedRunStep) {
229
+ return;
230
+ }
231
+ /**
232
+ * Gather any steps that aren't memoized and report them.
233
+ */
234
+ const newSteps = steps.filter((step) => !step.fulfilled);
235
+ if (!newSteps.length) {
236
+ return;
237
+ }
238
+ /**
239
+ * Warn if we've found new steps but haven't yet seen all previous
240
+ * steps. This may indicate that step presence isn't determinate.
241
+ */
242
+ const stepsToFulfil = Object.keys(__classPrivateFieldGet(this, _V1InngestExecution_state, "f").stepState).length;
243
+ const fulfilledSteps = steps.filter((step) => step.fulfilled).length;
244
+ const foundAllCompletedSteps = stepsToFulfil === fulfilledSteps;
245
+ if (!foundAllCompletedSteps) {
246
+ // TODO Tag
247
+ console.warn((0, errors_1.prettyError)({
248
+ type: "warn",
249
+ whatHappened: "Function may be indeterminate",
250
+ why: "We found new steps before seeing all previous steps, which may indicate that the function is non-deterministic.",
251
+ consequences: "This may cause unexpected behaviour as Inngest executes your function.",
252
+ reassurance: "This is expected if a function is updated in the middle of a run, but may indicate a bug if not.",
253
+ }));
254
+ }
255
+ /**
256
+ * We're finishing up; let's trigger the last of the hooks.
257
+ */
258
+ await ((_b = (_a = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.afterMemoization) === null || _b === void 0 ? void 0 : _b.call(_a));
259
+ await ((_d = (_c = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _c === void 0 ? void 0 : _c.beforeExecution) === null || _d === void 0 ? void 0 : _d.call(_c));
260
+ await ((_f = (_e = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _e === void 0 ? void 0 : _e.afterExecution) === null || _f === void 0 ? void 0 : _f.call(_e));
261
+ return newSteps.map((step) => ({
262
+ op: step.op,
263
+ id: step.hashedId,
264
+ name: step.name,
265
+ opts: step.opts,
266
+ }));
267
+ }, _V1InngestExecution_executeStep = async function _V1InngestExecution_executeStep({ id, name, opts, fn }) {
268
+ var _a, _b, _c, _d, _e;
269
+ (_a = __classPrivateFieldGet(this, _V1InngestExecution_timeout, "f")) === null || _a === void 0 ? void 0 : _a.clear();
270
+ await ((_c = (_b = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _b === void 0 ? void 0 : _b.afterMemoization) === null || _c === void 0 ? void 0 : _c.call(_b));
271
+ await ((_e = (_d = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _d === void 0 ? void 0 : _d.beforeExecution) === null || _e === void 0 ? void 0 : _e.call(_d));
272
+ const outgoingOp = { id, op: types_1.StepOpCode.RunStep, name, opts };
273
+ __classPrivateFieldGet(this, _V1InngestExecution_state, "f").executingStep = outgoingOp;
274
+ this.debug(`executing step "${id}"`);
275
+ return ((0, promises_1.runAsPromise)(fn)
276
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
277
+ .finally(async () => {
278
+ var _a, _b;
279
+ await ((_b = (_a = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.afterExecution) === null || _b === void 0 ? void 0 : _b.call(_a));
280
+ })
281
+ .then((data) => {
282
+ return Object.assign(Object.assign({}, outgoingOp), { data });
283
+ })
284
+ .catch((error) => {
285
+ return Object.assign(Object.assign({}, outgoingOp), {
286
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
287
+ error });
288
+ }));
289
+ }, _V1InngestExecution_startExecution =
290
+ /**
291
+ * Starts execution of the user's function, including triggering checkpoints
292
+ * and middleware hooks where appropriate.
293
+ */
294
+ async function _V1InngestExecution_startExecution() {
295
+ var _a, _b, _c, _d, _e, _f, _g;
296
+ /**
297
+ * Mutate input as neccessary based on middleware.
298
+ */
299
+ await __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_transformInput).call(this);
300
+ /**
301
+ * Start the timer to time out the run if needed.
302
+ */
303
+ void ((_a = __classPrivateFieldGet(this, _V1InngestExecution_timeout, "f")) === null || _a === void 0 ? void 0 : _a.start());
304
+ await ((_c = (_b = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _b === void 0 ? void 0 : _b.beforeMemoization) === null || _c === void 0 ? void 0 : _c.call(_b));
305
+ /**
306
+ * If we had no state to begin with, immediately end the memoization phase.
307
+ */
308
+ if (__classPrivateFieldGet(this, _V1InngestExecution_state, "f").allStateUsed()) {
309
+ await ((_e = (_d = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _d === void 0 ? void 0 : _d.afterMemoization) === null || _e === void 0 ? void 0 : _e.call(_d));
310
+ await ((_g = (_f = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _f === void 0 ? void 0 : _f.beforeExecution) === null || _g === void 0 ? void 0 : _g.call(_f));
311
+ }
312
+ /**
313
+ * Trigger the user's function.
314
+ */
315
+ (0, promises_1.runAsPromise)(() => __classPrivateFieldGet(this, _V1InngestExecution_userFnToRun, "f").call(this, __classPrivateFieldGet(this, _V1InngestExecution_fnArg, "f")))
316
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
317
+ .finally(async () => {
318
+ var _a, _b, _c, _d, _e, _f;
319
+ await ((_b = (_a = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.afterMemoization) === null || _b === void 0 ? void 0 : _b.call(_a));
320
+ await ((_d = (_c = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _c === void 0 ? void 0 : _c.beforeExecution) === null || _d === void 0 ? void 0 : _d.call(_c));
321
+ await ((_f = (_e = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _e === void 0 ? void 0 : _e.afterExecution) === null || _f === void 0 ? void 0 : _f.call(_e));
322
+ })
323
+ .then((data) => {
324
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
325
+ __classPrivateFieldGet(this, _V1InngestExecution_state, "f").setCheckpoint({ type: "function-resolved", data });
326
+ })
327
+ .catch((error) => {
328
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
329
+ __classPrivateFieldGet(this, _V1InngestExecution_state, "f").setCheckpoint({ type: "function-rejected", error });
330
+ });
331
+ }, _V1InngestExecution_transformInput =
332
+ /**
333
+ * Using middleware, transform input before running.
334
+ */
335
+ async function _V1InngestExecution_transformInput() {
336
+ var _a, _b;
337
+ const inputMutations = await ((_b = (_a = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.transformInput) === null || _b === void 0 ? void 0 : _b.call(_a, {
338
+ ctx: Object.assign({}, __classPrivateFieldGet(this, _V1InngestExecution_fnArg, "f")),
339
+ steps: Object.values(__classPrivateFieldGet(this, _V1InngestExecution_state, "f").stepState),
340
+ fn: this.options.fn,
341
+ }));
342
+ if (inputMutations === null || inputMutations === void 0 ? void 0 : inputMutations.ctx) {
343
+ __classPrivateFieldSet(this, _V1InngestExecution_fnArg, inputMutations.ctx, "f");
344
+ }
345
+ if (inputMutations === null || inputMutations === void 0 ? void 0 : inputMutations.steps) {
346
+ __classPrivateFieldGet(this, _V1InngestExecution_state, "f").stepState = inputMutations.steps.reduce((steps, step) => (Object.assign(Object.assign({}, steps), { [step.id]: step })), {});
347
+ }
348
+ }, _V1InngestExecution_transformOutput =
349
+ /**
350
+ * Using middleware, transform output before returning.
351
+ */
352
+ async function _V1InngestExecution_transformOutput(dataOrError) {
353
+ var _a, _b;
354
+ const output = Object.assign({}, dataOrError);
355
+ if (typeof output.error !== "undefined") {
356
+ output.data = (0, errors_1.serializeError)(output.error);
357
+ }
358
+ const transformedOutput = await ((_b = (_a = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.transformOutput) === null || _b === void 0 ? void 0 : _b.call(_a, {
359
+ result: Object.assign({}, output),
360
+ step: __classPrivateFieldGet(this, _V1InngestExecution_state, "f").executingStep,
361
+ }));
362
+ const { data, error } = Object.assign(Object.assign({}, output), transformedOutput === null || transformedOutput === void 0 ? void 0 : transformedOutput.result);
363
+ if (typeof error !== "undefined") {
364
+ /**
365
+ * Ensure we give middleware the chance to decide on retriable behaviour
366
+ * by looking at the error returned from output transformation.
367
+ */
368
+ let retriable = !(error instanceof NonRetriableError_1.NonRetriableError);
369
+ if (retriable && error instanceof RetryAfterError_1.RetryAfterError) {
370
+ retriable = error.retryAfter;
371
+ }
372
+ const serializedError = (0, errors_1.serializeError)(error);
373
+ return { type: "function-rejected", error: serializedError, retriable };
374
+ }
375
+ return { type: "function-resolved", data: (0, functions_1.undefinedToNull)(data) };
376
+ }, _V1InngestExecution_createExecutionState = function _V1InngestExecution_createExecutionState() {
377
+ let { promise: checkpointPromise, resolve: checkpointResolve } = (0, promises_1.createDeferredPromise)();
378
+ const loop = (function (cleanUp) {
379
+ return __asyncGenerator(this, arguments, function* () {
380
+ try {
381
+ while (true) {
382
+ yield yield __await(yield __await(checkpointPromise));
383
+ }
384
+ }
385
+ finally {
386
+ cleanUp === null || cleanUp === void 0 ? void 0 : cleanUp();
387
+ }
388
+ });
389
+ })(() => {
390
+ var _a;
391
+ (_a = __classPrivateFieldGet(this, _V1InngestExecution_timeout, "f")) === null || _a === void 0 ? void 0 : _a.clear();
392
+ });
393
+ const state = {
394
+ stepState: this.options.stepState,
395
+ steps: {},
396
+ loop,
397
+ hasSteps: Boolean(Object.keys(this.options.stepState).length),
398
+ stepCompletionOrder: this.options.stepCompletionOrder,
399
+ setCheckpoint: (checkpoint) => {
400
+ ({ promise: checkpointPromise, resolve: checkpointResolve } =
401
+ checkpointResolve(checkpoint));
402
+ },
403
+ allStateUsed: () => {
404
+ return Object.values(state.stepState).every((step) => {
405
+ return step.seen;
406
+ });
407
+ },
408
+ };
409
+ return state;
410
+ }, _V1InngestExecution_createFnArg = function _V1InngestExecution_createFnArg() {
411
+ var _a;
412
+ const step = __classPrivateFieldGet(this, _V1InngestExecution_instances, "m", _V1InngestExecution_createStepTools).call(this);
413
+ let fnArg = Object.assign(Object.assign({}, this.options.data), { step });
414
+ /**
415
+ * Handle use of the `onFailure` option by deserializing the error.
416
+ */
417
+ if (this.options.isFailureHandler) {
418
+ const eventData = zod_1.z
419
+ .object({ error: types_1.failureEventErrorSchema })
420
+ .parse((_a = fnArg.event) === null || _a === void 0 ? void 0 : _a.data);
421
+ fnArg = Object.assign(Object.assign({}, fnArg), { error: (0, errors_1.deserializeError)(eventData.error) });
422
+ }
423
+ return fnArg;
424
+ }, _V1InngestExecution_createStepTools = function _V1InngestExecution_createStepTools() {
425
+ /**
426
+ * A list of steps that have been found and are being rolled up before being
427
+ * reported to the core loop.
428
+ */
429
+ let foundStepsToReport = [];
430
+ /**
431
+ * A promise that's used to ensure that step reporting cannot be run more than
432
+ * once in a given asynchronous time span.
433
+ */
434
+ let foundStepsReportPromise;
435
+ /**
436
+ * A promise that's used to represent middleware hooks running before
437
+ * execution.
438
+ */
439
+ let beforeExecHooksPromise;
440
+ /**
441
+ * A flag used to ensure that we only warn about parallel indexing once per
442
+ * execution to avoid spamming the console.
443
+ */
444
+ let warnOfParallelIndexing = false;
445
+ /**
446
+ * Given a colliding step ID, maybe warn the user about parallel indexing.
447
+ */
448
+ const maybeWarnOfParallelIndexing = (collisionId) => {
449
+ if (warnOfParallelIndexing) {
450
+ return;
451
+ }
452
+ const stepExists = Boolean(__classPrivateFieldGet(this, _V1InngestExecution_state, "f").steps[collisionId]);
453
+ const stepFoundThisTick = foundStepsToReport.some((step) => {
454
+ return step.id === collisionId;
455
+ });
456
+ if (stepExists && !stepFoundThisTick) {
457
+ warnOfParallelIndexing = true;
458
+ console.warn((0, errors_1.prettyError)({
459
+ type: "warn",
460
+ whatHappened: "We detected that you have multiple steps with the same ID.",
461
+ code: errors_1.ErrCode.AUTOMATIC_PARALLEL_INDEXING,
462
+ why: `This can happen if you're using the same ID for multiple steps across different chains of parallel work. We found the issue with step "${collisionId}".`,
463
+ reassurance: "Your function is still running, though it may exhibit unexpected behaviour.",
464
+ consequences: "Using the same IDs across parallel chains of work can cause unexpected behaviour.",
465
+ toFixNow: "We recommend using a unique ID for each step, especially those happening in parallel.",
466
+ }));
467
+ }
468
+ };
469
+ /**
470
+ * A helper used to report steps to the core loop. Used after adding an item
471
+ * to `foundStepsToReport`.
472
+ */
473
+ const reportNextTick = () => {
474
+ // Being explicit instead of using `??=` to appease TypeScript.
475
+ if (foundStepsReportPromise) {
476
+ return;
477
+ }
478
+ foundStepsReportPromise = (0, promises_1.resolveAfterPending)()
479
+ /**
480
+ * Ensure that we wait for this promise to resolve before continuing.
481
+ *
482
+ * The groups in which steps are reported can affect how we detect some
483
+ * more complex determinism issues like parallel indexing. This promise
484
+ * can represent middleware hooks being run early, in the middle of
485
+ * ingesting steps to report.
486
+ *
487
+ * Because of this, it's important we wait for this middleware to resolve
488
+ * before continuing to report steps to ensure that all steps have a
489
+ * chance to be reported throughout this asynchronous action.
490
+ */
491
+ .then(() => beforeExecHooksPromise)
492
+ .then(() => {
493
+ var _a;
494
+ foundStepsReportPromise = undefined;
495
+ for (let i = 0; i < __classPrivateFieldGet(this, _V1InngestExecution_state, "f").stepCompletionOrder.length; i++) {
496
+ const handled = (_a = foundStepsToReport
497
+ .find((step) => {
498
+ return step.hashedId === __classPrivateFieldGet(this, _V1InngestExecution_state, "f").stepCompletionOrder[i];
499
+ })) === null || _a === void 0 ? void 0 : _a.handle();
500
+ if (handled) {
501
+ return void reportNextTick();
502
+ }
503
+ }
504
+ // If we've handled no steps in this "tick," roll up everything we've
505
+ // found and report it.
506
+ const steps = [...foundStepsToReport];
507
+ foundStepsToReport = [];
508
+ return void __classPrivateFieldGet(this, _V1InngestExecution_state, "f").setCheckpoint({
509
+ type: "steps-found",
510
+ steps: steps,
511
+ });
512
+ });
513
+ };
514
+ /**
515
+ * A helper used to push a step to the list of steps to report.
516
+ */
517
+ const pushStepToReport = (step) => {
518
+ foundStepsToReport.push(step);
519
+ reportNextTick();
520
+ };
521
+ const stepHandler = async ({ args, matchOp, opts, }) => {
522
+ var _a;
523
+ await beforeExecHooksPromise;
524
+ if (!__classPrivateFieldGet(this, _V1InngestExecution_state, "f").hasSteps && (opts === null || opts === void 0 ? void 0 : opts.nonStepExecuteInline) && opts.fn) {
525
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
526
+ return (0, promises_1.runAsPromise)(() => { var _a; return (_a = opts.fn) === null || _a === void 0 ? void 0 : _a.call(opts, ...args); });
527
+ }
528
+ if (__classPrivateFieldGet(this, _V1InngestExecution_state, "f").executingStep) {
529
+ /**
530
+ * If a step is found after asynchronous actions during another step's
531
+ * execution, everything is fine. The problem here is if we've found
532
+ * that a step nested inside another a step, which is something we don't
533
+ * support at the time of writing.
534
+ *
535
+ * In this case, we could use something like Async Hooks to understand
536
+ * how the step is being triggered, though this isn't available in all
537
+ * environments.
538
+ *
539
+ * Therefore, we'll only show a warning here to indicate that this is
540
+ * potentially an issue.
541
+ */
542
+ console.warn((0, errors_1.prettyError)({
543
+ whatHappened: "We detected that you have nested `step.*` tooling.",
544
+ consequences: "Nesting `step.*` tooling is not supported.",
545
+ type: "warn",
546
+ reassurance: "It's possible to see this warning if steps are separated by regular asynchronous calls, which is fine.",
547
+ stack: true,
548
+ 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.",
549
+ code: errors_1.ErrCode.NESTING_STEPS,
550
+ }));
551
+ }
552
+ const stepOptions = (0, InngestStepTools_1.getStepOptions)(args[0]);
553
+ const opId = matchOp(stepOptions, ...args.slice(1));
554
+ if (__classPrivateFieldGet(this, _V1InngestExecution_state, "f").steps[opId.id]) {
555
+ const originalId = opId.id;
556
+ maybeWarnOfParallelIndexing(originalId);
557
+ for (let i = 1;; i++) {
558
+ const newId = [originalId, InngestStepTools_1.STEP_INDEXING_SUFFIX, i].join("");
559
+ if (!__classPrivateFieldGet(this, _V1InngestExecution_state, "f").steps[newId]) {
560
+ opId.id = newId;
561
+ break;
562
+ }
563
+ }
564
+ console.debug(`${consts_1.logPrefix} debug - Step "${originalId}" already exists; automatically indexing to "${opId.id}"`);
565
+ }
566
+ const { promise, resolve, reject } = (0, promises_1.createDeferredPromise)();
567
+ const hashedId = exports._internals.hashId(opId.id);
568
+ const stepState = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").stepState[hashedId];
569
+ if (stepState) {
570
+ stepState.seen = true;
571
+ }
572
+ const step = Object.assign(Object.assign({}, opId), { hashedId,
573
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
574
+ 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, ...args); } : undefined, fulfilled: Boolean(stepState), displayName: (_a = opId.displayName) !== null && _a !== void 0 ? _a : opId.id, handled: false, handle: () => {
575
+ if (step.handled) {
576
+ return false;
577
+ }
578
+ step.handled = true;
579
+ if (stepState) {
580
+ stepState.fulfilled = true;
581
+ if (typeof stepState.data !== "undefined") {
582
+ resolve(stepState.data);
583
+ }
584
+ else {
585
+ reject(stepState.error);
586
+ }
587
+ }
588
+ return true;
589
+ } });
590
+ __classPrivateFieldGet(this, _V1InngestExecution_state, "f").steps[opId.id] = step;
591
+ __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hasSteps = true;
592
+ pushStepToReport(step);
593
+ /**
594
+ * If this is the last piece of state we had, we've now finished
595
+ * memoizing.
596
+ */
597
+ if (!beforeExecHooksPromise && __classPrivateFieldGet(this, _V1InngestExecution_state, "f").allStateUsed()) {
598
+ await (beforeExecHooksPromise = (async () => {
599
+ var _a, _b, _c, _d;
600
+ await ((_b = (_a = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.beforeExecution) === null || _b === void 0 ? void 0 : _b.call(_a));
601
+ await ((_d = (_c = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _c === void 0 ? void 0 : _c.afterMemoization) === null || _d === void 0 ? void 0 : _d.call(_c));
602
+ })());
603
+ }
604
+ return promise;
605
+ };
606
+ return (0, InngestStepTools_1.createStepTools)(this.options.client, stepHandler);
607
+ }, _V1InngestExecution_getUserFnToRun = function _V1InngestExecution_getUserFnToRun() {
608
+ if (!this.options.isFailureHandler) {
609
+ return this.options.fn["fn"];
610
+ }
611
+ if (!this.options.fn["onFailureFn"]) {
612
+ /**
613
+ * Somehow, we've ended up detecting that this is a failure handler but
614
+ * doesn't have an `onFailure` function. This should never happen.
615
+ */
616
+ throw new Error("Cannot find function `onFailure` handler");
617
+ }
618
+ return this.options.fn["onFailureFn"];
619
+ }, _V1InngestExecution_initializeTimer = function _V1InngestExecution_initializeTimer(state) {
620
+ if (!this.options.requestedRunStep) {
621
+ return;
622
+ }
623
+ __classPrivateFieldSet(this, _V1InngestExecution_timeout, (0, promises_1.createTimeoutPromise)(__classPrivateFieldGet(this, _V1InngestExecution_timeoutDuration, "f")), "f");
624
+ void __classPrivateFieldGet(this, _V1InngestExecution_timeout, "f").then(async () => {
625
+ var _a, _b, _c, _d, _e, _f;
626
+ await ((_b = (_a = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _a === void 0 ? void 0 : _a.afterMemoization) === null || _b === void 0 ? void 0 : _b.call(_a));
627
+ await ((_d = (_c = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _c === void 0 ? void 0 : _c.beforeExecution) === null || _d === void 0 ? void 0 : _d.call(_c));
628
+ await ((_f = (_e = __classPrivateFieldGet(this, _V1InngestExecution_state, "f").hooks) === null || _e === void 0 ? void 0 : _e.afterExecution) === null || _f === void 0 ? void 0 : _f.call(_e));
629
+ state.setCheckpoint({
630
+ type: "step-not-found",
631
+ step: {
632
+ id: this.options.requestedRunStep,
633
+ op: types_1.StepOpCode.StepNotFound,
634
+ },
635
+ });
636
+ });
637
+ }, _V1InngestExecution_initializeMiddleware = async function _V1InngestExecution_initializeMiddleware() {
638
+ const ctx = this.options.data;
639
+ const hooks = await (0, InngestMiddleware_1.getHookStack)(this.options.fn["middleware"], "onFunctionRun", {
640
+ ctx,
641
+ fn: this.options.fn,
642
+ steps: Object.values(this.options.stepState),
643
+ }, {
644
+ transformInput: (prev, output) => {
645
+ return {
646
+ ctx: Object.assign(Object.assign({}, prev.ctx), output === null || output === void 0 ? void 0 : output.ctx),
647
+ fn: this.options.fn,
648
+ steps: prev.steps.map((step, i) => {
649
+ var _a;
650
+ return (Object.assign(Object.assign({}, step), (_a = output === null || output === void 0 ? void 0 : output.steps) === null || _a === void 0 ? void 0 : _a[i]));
651
+ }),
652
+ };
653
+ },
654
+ transformOutput: (prev, output) => {
655
+ return {
656
+ result: Object.assign(Object.assign({}, prev.result), output === null || output === void 0 ? void 0 : output.result),
657
+ step: prev.step,
658
+ };
659
+ },
660
+ });
661
+ return hooks;
662
+ };
663
+ const hashId = (id) => {
664
+ return (0, hash_js_1.sha1)().update(id).digest("hex");
665
+ };
666
+ const hashOp = (op) => {
667
+ return Object.assign(Object.assign({}, op), { id: hashId(op.id) });
668
+ };
669
+ /**
670
+ * Exported for testing.
671
+ */
672
+ exports._internals = { hashOp, hashId };
673
+ //# sourceMappingURL=v1.js.map