inngest 4.1.2 → 4.2.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 (93) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/api/api.cjs +30 -1
  3. package/api/api.cjs.map +1 -1
  4. package/api/api.d.cts +19 -0
  5. package/api/api.d.cts.map +1 -1
  6. package/api/api.d.ts +19 -0
  7. package/api/api.d.ts.map +1 -1
  8. package/api/api.js +30 -1
  9. package/api/api.js.map +1 -1
  10. package/components/InngestCommHandler.cjs +9 -1
  11. package/components/InngestCommHandler.cjs.map +1 -1
  12. package/components/InngestCommHandler.d.cts.map +1 -1
  13. package/components/InngestCommHandler.d.ts.map +1 -1
  14. package/components/InngestCommHandler.js +9 -1
  15. package/components/InngestCommHandler.js.map +1 -1
  16. package/components/StreamTools.cjs +241 -0
  17. package/components/StreamTools.cjs.map +1 -0
  18. package/components/StreamTools.d.cts +161 -0
  19. package/components/StreamTools.d.cts.map +1 -0
  20. package/components/StreamTools.d.ts +161 -0
  21. package/components/StreamTools.d.ts.map +1 -0
  22. package/components/StreamTools.js +240 -0
  23. package/components/StreamTools.js.map +1 -0
  24. package/components/createWebApiCommHandler.cjs +46 -0
  25. package/components/createWebApiCommHandler.cjs.map +1 -0
  26. package/components/createWebApiCommHandler.js +46 -0
  27. package/components/createWebApiCommHandler.js.map +1 -0
  28. package/components/execution/InngestExecution.cjs.map +1 -1
  29. package/components/execution/InngestExecution.d.cts +6 -0
  30. package/components/execution/InngestExecution.d.cts.map +1 -1
  31. package/components/execution/InngestExecution.d.ts +6 -0
  32. package/components/execution/InngestExecution.d.ts.map +1 -1
  33. package/components/execution/InngestExecution.js.map +1 -1
  34. package/components/execution/als.cjs.map +1 -1
  35. package/components/execution/als.d.cts +9 -1
  36. package/components/execution/als.d.cts.map +1 -1
  37. package/components/execution/als.d.ts +9 -1
  38. package/components/execution/als.d.ts.map +1 -1
  39. package/components/execution/als.js.map +1 -1
  40. package/components/execution/engine.cjs +334 -26
  41. package/components/execution/engine.cjs.map +1 -1
  42. package/components/execution/engine.d.cts +1 -0
  43. package/components/execution/engine.d.cts.map +1 -1
  44. package/components/execution/engine.d.ts +1 -0
  45. package/components/execution/engine.d.ts.map +1 -1
  46. package/components/execution/engine.js +334 -26
  47. package/components/execution/engine.js.map +1 -1
  48. package/components/execution/streaming.cjs +208 -0
  49. package/components/execution/streaming.cjs.map +1 -0
  50. package/components/execution/streaming.d.cts +12 -0
  51. package/components/execution/streaming.d.cts.map +1 -0
  52. package/components/execution/streaming.d.ts +12 -0
  53. package/components/execution/streaming.d.ts.map +1 -0
  54. package/components/execution/streaming.js +198 -0
  55. package/components/execution/streaming.js.map +1 -0
  56. package/edge.cjs +19 -32
  57. package/edge.cjs.map +1 -1
  58. package/edge.d.cts +1 -1
  59. package/edge.d.cts.map +1 -1
  60. package/edge.d.ts +1 -1
  61. package/edge.d.ts.map +1 -1
  62. package/edge.js +19 -32
  63. package/edge.js.map +1 -1
  64. package/experimental/durable-endpoints/client.cjs +114 -0
  65. package/experimental/durable-endpoints/client.cjs.map +1 -0
  66. package/experimental/durable-endpoints/client.d.cts +49 -0
  67. package/experimental/durable-endpoints/client.d.cts.map +1 -0
  68. package/experimental/durable-endpoints/client.d.ts +49 -0
  69. package/experimental/durable-endpoints/client.d.ts.map +1 -0
  70. package/experimental/durable-endpoints/client.js +114 -0
  71. package/experimental/durable-endpoints/client.js.map +1 -0
  72. package/experimental/durable-endpoints/index.cjs +3 -0
  73. package/experimental/durable-endpoints/index.d.cts +2 -0
  74. package/experimental/durable-endpoints/index.d.ts +2 -0
  75. package/experimental/durable-endpoints/index.js +3 -0
  76. package/helpers/promises.cjs.map +1 -1
  77. package/helpers/promises.js.map +1 -1
  78. package/node.cjs +97 -0
  79. package/node.cjs.map +1 -1
  80. package/node.d.cts +34 -2
  81. package/node.d.cts.map +1 -1
  82. package/node.d.ts +34 -2
  83. package/node.d.ts.map +1 -1
  84. package/node.js +95 -2
  85. package/node.js.map +1 -1
  86. package/package.json +17 -1
  87. package/react.d.cts.map +1 -1
  88. package/version.cjs +1 -1
  89. package/version.cjs.map +1 -1
  90. package/version.d.cts +1 -1
  91. package/version.d.ts +1 -1
  92. package/version.js +1 -1
  93. package/version.js.map +1 -1
@@ -0,0 +1,240 @@
1
+ import { getAsyncCtx, getAsyncCtxSync } from "./execution/als.js";
2
+ import { buildSseCommitEvent, buildSseFailedEvent, buildSseRedirectEvent, buildSseRollbackEvent, buildSseStreamEvent, buildSseSucceededEvent } from "./execution/streaming.js";
3
+
4
+ //#region src/components/StreamTools.ts
5
+ /**
6
+ * Wraps a `TransformStream<Uint8Array>` to provide push/pipe SSE streaming
7
+ * capabilities within an Inngest execution.
8
+ *
9
+ * @internal
10
+ */
11
+ var Stream = class {
12
+ transform;
13
+ writer;
14
+ encoder = new TextEncoder();
15
+ _activated = false;
16
+ _errored = false;
17
+ writeChain = Promise.resolve();
18
+ /**
19
+ * Optional callback invoked the first time `push` or `pipe` is called.
20
+ * Used by the execution engine to fire a checkpoint that returns the SSE
21
+ * Response to the client immediately.
22
+ */
23
+ onActivated;
24
+ /**
25
+ * Optional callback invoked when a write to the underlying stream fails
26
+ * (e.g. the client disconnected or the transform stream errored). Used by
27
+ * the execution engine to emit diagnostic logs.
28
+ */
29
+ onWriteError;
30
+ constructor(opts) {
31
+ this.onActivated = opts?.onActivated;
32
+ this.onWriteError = opts?.onWriteError;
33
+ this.transform = new TransformStream(void 0, void 0, new CountQueuingStrategy({ highWaterMark: 1024 }));
34
+ this.writer = this.transform.writable.getWriter();
35
+ }
36
+ /**
37
+ * Whether `push` or `pipe` has been called at least once.
38
+ */
39
+ get activated() {
40
+ return this._activated;
41
+ }
42
+ /**
43
+ * The readable side of the underlying transform stream. Consumers (i.e. the
44
+ * HTTP response) read SSE events from here.
45
+ */
46
+ get readable() {
47
+ return this.transform.readable;
48
+ }
49
+ /**
50
+ * Resolve the current hashed step ID for stream events. Returns the
51
+ * executing step's hashed ID (read from ALS), or undefined if outside a step.
52
+ */
53
+ currentHashedStepId() {
54
+ return getAsyncCtxSync()?.execution?.executingStep?.hashedId;
55
+ }
56
+ activate() {
57
+ if (!this._activated) {
58
+ this._activated = true;
59
+ this.onActivated?.();
60
+ }
61
+ }
62
+ /**
63
+ * Encode and write an SSE event string to the underlying writer.
64
+ */
65
+ writeEncoded(sseEvent) {
66
+ return this.writer.write(this.encoder.encode(sseEvent));
67
+ }
68
+ /**
69
+ * Enqueue a pre-built SSE event string onto the write chain.
70
+ */
71
+ enqueue(sseEvent) {
72
+ if (this._errored) return;
73
+ this.writeChain = this.writeChain.then(() => this.writeEncoded(sseEvent)).catch((err) => {
74
+ this._errored = true;
75
+ this.onWriteError?.(err);
76
+ });
77
+ }
78
+ /**
79
+ * Emit an `inngest.commit` SSE event indicating that uncommitted streamed data
80
+ * should be committed (i.e. will not be rolled back). Internal use only.
81
+ */
82
+ commit(hashedStepId) {
83
+ this.enqueue(buildSseCommitEvent(hashedStepId));
84
+ }
85
+ /**
86
+ * Emit an `inngest.rollback` SSE event indicating the uncommitted streamed
87
+ * data should be discarded (e.g. step errored). Internal use only.
88
+ */
89
+ rollback(hashedStepId) {
90
+ this.enqueue(buildSseRollbackEvent(hashedStepId));
91
+ }
92
+ /**
93
+ * Serialize `data` into an SSE stream event and enqueue it. Returns `false`
94
+ * if serialization fails (e.g. circular reference) so callers can skip.
95
+ */
96
+ enqueueStreamEvent(data, hashedStepId) {
97
+ let sseEvent;
98
+ try {
99
+ sseEvent = buildSseStreamEvent(data, hashedStepId);
100
+ } catch {
101
+ return false;
102
+ }
103
+ this.enqueue(sseEvent);
104
+ return true;
105
+ }
106
+ /**
107
+ * Write a single SSE stream event containing `data`. The current step's
108
+ * hashed ID is automatically included as stepId for rollback tracking.
109
+ */
110
+ push(data) {
111
+ this.activate();
112
+ this.enqueueStreamEvent(data, this.currentHashedStepId());
113
+ }
114
+ /**
115
+ * Pipe a source to the client, writing each chunk as an SSE stream event.
116
+ * Returns the concatenated content of all chunks.
117
+ */
118
+ async pipe(source) {
119
+ this.activate();
120
+ let iterable;
121
+ if (source instanceof ReadableStream) iterable = this.readableToAsyncIterable(source);
122
+ else if (typeof source === "function") iterable = source();
123
+ else iterable = source;
124
+ return this.pipeIterable(iterable);
125
+ }
126
+ /**
127
+ * Adapt a ReadableStream into an AsyncIterable<string>. TypeScript's
128
+ * ReadableStream type doesn't declare Symbol.asyncIterator, so we use the
129
+ * reader API for type safety.
130
+ */
131
+ async *readableToAsyncIterable(readable) {
132
+ const reader = readable.getReader();
133
+ const decoder = new TextDecoder();
134
+ try {
135
+ while (true) {
136
+ const { done, value } = await reader.read();
137
+ if (done) break;
138
+ yield typeof value === "string" ? value : decoder.decode(value, { stream: true });
139
+ }
140
+ const final = decoder.decode();
141
+ if (final) yield final;
142
+ } finally {
143
+ reader.releaseLock();
144
+ }
145
+ }
146
+ /**
147
+ * Core pipe loop: iterate an async iterable, writing each chunk as an SSE
148
+ * stream event and collecting the concatenated result.
149
+ */
150
+ async pipeIterable(source) {
151
+ const hashedStepId = this.currentHashedStepId();
152
+ const chunks = [];
153
+ for await (const chunk of source) {
154
+ if (this._errored) break;
155
+ chunks.push(chunk);
156
+ if (!this.enqueueStreamEvent(chunk, hashedStepId)) continue;
157
+ await this.writeChain;
158
+ }
159
+ return chunks.join("");
160
+ }
161
+ /**
162
+ * Write a redirect info event. Tells the client where to reconnect if the
163
+ * durable endpoint goes async. Does NOT close the writer — more stream
164
+ * events may follow before the durable endpoint actually switches to async
165
+ * mode. Internal use only.
166
+ */
167
+ sendRedirectInfo(data) {
168
+ this.enqueue(buildSseRedirectEvent(data));
169
+ }
170
+ /**
171
+ * Write a succeeded result event and close the writer. Internal use only.
172
+ */
173
+ closeSucceeded(response) {
174
+ let sseEvent;
175
+ try {
176
+ sseEvent = buildSseSucceededEvent(response);
177
+ } catch {
178
+ sseEvent = buildSseFailedEvent("Failed to serialize result");
179
+ }
180
+ this.closeWriter(sseEvent);
181
+ }
182
+ /**
183
+ * Write a failed result event and close the writer. Internal use only.
184
+ */
185
+ closeFailed(error) {
186
+ this.closeWriter(buildSseFailedEvent(error));
187
+ }
188
+ /**
189
+ * Optionally write a final SSE event, then close the writer.
190
+ */
191
+ closeWriter(finalEvent) {
192
+ this.writeChain = this.writeChain.then(async () => {
193
+ if (finalEvent) await this.writeEncoded(finalEvent);
194
+ await this.writer.close();
195
+ }).catch((err) => {
196
+ this.onWriteError?.(err);
197
+ });
198
+ }
199
+ /**
200
+ * Close the writer without writing a result event. Used when the durable endpoint goes
201
+ * async and the real result will arrive on the redirected stream.
202
+ */
203
+ end() {
204
+ this.closeWriter();
205
+ }
206
+ };
207
+ /** Synchronous ALS lookup for the stream tools (fast path). */
208
+ const getStreamToolsSync = () => {
209
+ return getAsyncCtxSync()?.execution?.stream;
210
+ };
211
+ const getDeferredStreamTooling = async () => {
212
+ return (await getAsyncCtx())?.execution?.stream;
213
+ };
214
+ /**
215
+ * Stream tools that use ALS to resolve the current execution context.
216
+ * Outside an Inngest execution, `push()` is a no-op and `pipe()` resolves immediately.
217
+ */
218
+ const stream = {
219
+ push: (data) => {
220
+ const syncStream = getStreamToolsSync();
221
+ if (syncStream) {
222
+ syncStream.push(data);
223
+ return;
224
+ }
225
+ getDeferredStreamTooling().then((s) => {
226
+ s?.push(data);
227
+ }).catch(() => {});
228
+ },
229
+ pipe: async (source) => {
230
+ const syncStream = getStreamToolsSync();
231
+ if (syncStream) return syncStream.pipe(source);
232
+ const s = await getDeferredStreamTooling();
233
+ if (s) return s.pipe(source);
234
+ return "";
235
+ }
236
+ };
237
+
238
+ //#endregion
239
+ export { Stream, stream };
240
+ //# sourceMappingURL=StreamTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StreamTools.js","names":["sseEvent: string","iterable: AsyncIterable<string>","chunks: string[]","stream: StreamTools"],"sources":["../../src/components/StreamTools.ts"],"sourcesContent":["import { getAsyncCtx, getAsyncCtxSync } from \"./execution/als.ts\";\nimport {\n buildSseCommitEvent,\n buildSseFailedEvent,\n buildSseRedirectEvent,\n buildSseRollbackEvent,\n buildSseStreamEvent,\n buildSseSucceededEvent,\n type SseResponse,\n} from \"./execution/streaming.ts\";\n\n/**\n * Accepted source types for `stream.pipe()`.\n *\n * - `ReadableStream` — piped directly\n * - `AsyncIterable<string>` — iterated; each yielded value becomes a chunk\n * - `() => AsyncIterable<string>` — factory invoked lazily, then iterated\n */\nexport type PipeSource =\n | ReadableStream\n | AsyncIterable<string>\n | (() => AsyncIterable<string>);\n\n/**\n * The public interface for stream tools available to user code.\n */\nexport interface StreamTools {\n /**\n * Push data to the client as an SSE stream event. Fire-and-forget from the\n * caller's perspective.\n *\n * Outside of an Inngest execution context this is a silent no-op (graceful\n * degradation).\n */\n push(data: unknown): void;\n\n /**\n * Pipe a source to the client, writing each chunk as an SSE stream event.\n * Resolves with the concatenated content of all chunks when the source is\n * fully consumed.\n *\n * Accepts a `ReadableStream`, an `AsyncIterable<string>`, or a factory\n * function that returns an `AsyncIterable<string>` (e.g. an async\n * generator function).\n *\n * Outside of an Inngest execution context this resolves with an empty string.\n */\n pipe(source: PipeSource): Promise<string>;\n}\n\n/**\n * Wraps a `TransformStream<Uint8Array>` to provide push/pipe SSE streaming\n * capabilities within an Inngest execution.\n *\n * @internal\n */\nexport class Stream implements StreamTools {\n private transform: TransformStream<Uint8Array, Uint8Array>;\n private writer: WritableStreamDefaultWriter<Uint8Array>;\n private encoder = new TextEncoder();\n private _activated = false;\n private _errored = false;\n private writeChain: Promise<void> = Promise.resolve();\n\n /**\n * Optional callback invoked the first time `push` or `pipe` is called.\n * Used by the execution engine to fire a checkpoint that returns the SSE\n * Response to the client immediately.\n */\n private onActivated?: () => void;\n\n /**\n * Optional callback invoked when a write to the underlying stream fails\n * (e.g. the client disconnected or the transform stream errored). Used by\n * the execution engine to emit diagnostic logs.\n */\n private onWriteError?: (err: unknown) => void;\n\n constructor(opts?: {\n onActivated?: () => void;\n onWriteError?: (err: unknown) => void;\n }) {\n this.onActivated = opts?.onActivated;\n this.onWriteError = opts?.onWriteError;\n this.transform = new TransformStream<Uint8Array, Uint8Array>(\n undefined,\n undefined,\n // Use a generous high water mark on the readable side so that writes\n // don't block due to backpressure before the consumer reads.\n new CountQueuingStrategy({ highWaterMark: 1024 }),\n );\n this.writer = this.transform.writable.getWriter();\n }\n\n /**\n * Whether `push` or `pipe` has been called at least once.\n */\n get activated(): boolean {\n return this._activated;\n }\n\n /**\n * The readable side of the underlying transform stream. Consumers (i.e. the\n * HTTP response) read SSE events from here.\n */\n get readable(): ReadableStream<Uint8Array> {\n return this.transform.readable;\n }\n\n /**\n * Resolve the current hashed step ID for stream events. Returns the\n * executing step's hashed ID (read from ALS), or undefined if outside a step.\n */\n private currentHashedStepId(): string | undefined {\n return getAsyncCtxSync()?.execution?.executingStep?.hashedId;\n }\n\n private activate(): void {\n if (!this._activated) {\n this._activated = true;\n this.onActivated?.();\n }\n }\n\n /**\n * Encode and write an SSE event string to the underlying writer.\n */\n private writeEncoded(sseEvent: string): Promise<void> {\n return this.writer.write(this.encoder.encode(sseEvent));\n }\n\n /**\n * Enqueue a pre-built SSE event string onto the write chain.\n */\n private enqueue(sseEvent: string): void {\n if (this._errored) return;\n\n this.writeChain = this.writeChain\n .then(() => this.writeEncoded(sseEvent))\n .catch((err) => {\n // Writer errored (e.g. stream closed) — swallow so the chain\n // doesn't break and subsequent writes fail gracefully.\n this._errored = true;\n this.onWriteError?.(err);\n });\n }\n\n /**\n * Emit an `inngest.commit` SSE event indicating that uncommitted streamed data\n * should be committed (i.e. will not be rolled back). Internal use only.\n */\n commit(hashedStepId: string | null): void {\n this.enqueue(buildSseCommitEvent(hashedStepId));\n }\n\n /**\n * Emit an `inngest.rollback` SSE event indicating the uncommitted streamed\n * data should be discarded (e.g. step errored). Internal use only.\n */\n rollback(hashedStepId: string | null): void {\n this.enqueue(buildSseRollbackEvent(hashedStepId));\n }\n\n /**\n * Serialize `data` into an SSE stream event and enqueue it. Returns `false`\n * if serialization fails (e.g. circular reference) so callers can skip.\n */\n private enqueueStreamEvent(data: unknown, hashedStepId?: string): boolean {\n let sseEvent: string;\n try {\n sseEvent = buildSseStreamEvent(data, hashedStepId);\n } catch {\n return false;\n }\n\n this.enqueue(sseEvent);\n return true;\n }\n\n /**\n * Write a single SSE stream event containing `data`. The current step's\n * hashed ID is automatically included as stepId for rollback tracking.\n */\n push(data: unknown): void {\n this.activate();\n this.enqueueStreamEvent(data, this.currentHashedStepId());\n }\n\n /**\n * Pipe a source to the client, writing each chunk as an SSE stream event.\n * Returns the concatenated content of all chunks.\n */\n async pipe(source: PipeSource): Promise<string> {\n this.activate();\n\n let iterable: AsyncIterable<string>;\n if (source instanceof ReadableStream) {\n iterable = this.readableToAsyncIterable(source);\n } else if (typeof source === \"function\") {\n iterable = source();\n } else {\n iterable = source;\n }\n\n return this.pipeIterable(iterable);\n }\n\n /**\n * Adapt a ReadableStream into an AsyncIterable<string>. TypeScript's\n * ReadableStream type doesn't declare Symbol.asyncIterator, so we use the\n * reader API for type safety.\n */\n private async *readableToAsyncIterable(\n readable: ReadableStream,\n ): AsyncIterable<string> {\n const reader = readable.getReader();\n const decoder = new TextDecoder();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n yield typeof value === \"string\"\n ? value\n : decoder.decode(value, { stream: true });\n }\n // flush any partially buffered multibyte characters from the decoder\n const final = decoder.decode();\n if (final) yield final;\n } finally {\n reader.releaseLock();\n }\n }\n\n /**\n * Core pipe loop: iterate an async iterable, writing each chunk as an SSE\n * stream event and collecting the concatenated result.\n */\n private async pipeIterable(source: AsyncIterable<string>): Promise<string> {\n const hashedStepId = this.currentHashedStepId();\n const chunks: string[] = [];\n\n for await (const chunk of source) {\n if (this._errored) break;\n\n chunks.push(chunk);\n\n if (!this.enqueueStreamEvent(chunk, hashedStepId)) {\n continue;\n }\n\n await this.writeChain;\n }\n\n return chunks.join(\"\");\n }\n\n /**\n * Write a redirect info event. Tells the client where to reconnect if the\n * durable endpoint goes async. Does NOT close the writer — more stream\n * events may follow before the durable endpoint actually switches to async\n * mode. Internal use only.\n */\n sendRedirectInfo(data: { runId: string; url: string }): void {\n this.enqueue(buildSseRedirectEvent(data));\n }\n\n /**\n * Write a succeeded result event and close the writer. Internal use only.\n */\n closeSucceeded(response: SseResponse): void {\n let sseEvent: string;\n try {\n sseEvent = buildSseSucceededEvent(response);\n } catch {\n sseEvent = buildSseFailedEvent(\"Failed to serialize result\");\n }\n this.closeWriter(sseEvent);\n }\n\n /**\n * Write a failed result event and close the writer. Internal use only.\n */\n closeFailed(error: string): void {\n this.closeWriter(buildSseFailedEvent(error));\n }\n\n /**\n * Optionally write a final SSE event, then close the writer.\n */\n private closeWriter(finalEvent?: string): void {\n this.writeChain = this.writeChain\n .then(async () => {\n if (finalEvent) {\n await this.writeEncoded(finalEvent);\n }\n await this.writer.close();\n })\n .catch((err) => {\n this.onWriteError?.(err);\n });\n }\n\n /**\n * Close the writer without writing a result event. Used when the durable endpoint goes\n * async and the real result will arrive on the redirected stream.\n */\n end(): void {\n this.closeWriter();\n }\n}\n\n/** Synchronous ALS lookup for the stream tools (fast path). */\nconst getStreamToolsSync = (): Stream | undefined => {\n const ctx = getAsyncCtxSync();\n return ctx?.execution?.stream;\n};\n\nconst getDeferredStreamTooling = async (): Promise<Stream | undefined> => {\n const ctx = await getAsyncCtx();\n return ctx?.execution?.stream;\n};\n\n/**\n * Stream tools that use ALS to resolve the current execution context.\n * Outside an Inngest execution, `push()` is a no-op and `pipe()` resolves immediately.\n */\nexport const stream: StreamTools = {\n push: (data) => {\n // Sync fast path: activate the stream before the next microtask tick.\n const syncStream = getStreamToolsSync();\n if (syncStream) {\n syncStream.push(data);\n return;\n }\n\n // Fallback: ALS not yet initialized (first import still resolving).\n void getDeferredStreamTooling()\n .then((s) => {\n s?.push(data);\n })\n .catch(() => {\n // ALS initialization failure — already warned in als.ts.\n // push() is best-effort, so silently degrade.\n });\n },\n pipe: async (source) => {\n const syncStream = getStreamToolsSync();\n if (syncStream) {\n return syncStream.pipe(source);\n }\n\n const s = await getDeferredStreamTooling();\n if (s) {\n return s.pipe(source);\n }\n return \"\";\n },\n};\n"],"mappings":";;;;;;;;;;AAwDA,IAAa,SAAb,MAA2C;CACzC,AAAQ;CACR,AAAQ;CACR,AAAQ,UAAU,IAAI,aAAa;CACnC,AAAQ,aAAa;CACrB,AAAQ,WAAW;CACnB,AAAQ,aAA4B,QAAQ,SAAS;;;;;;CAOrD,AAAQ;;;;;;CAOR,AAAQ;CAER,YAAY,MAGT;AACD,OAAK,cAAc,MAAM;AACzB,OAAK,eAAe,MAAM;AAC1B,OAAK,YAAY,IAAI,gBACnB,QACA,QAGA,IAAI,qBAAqB,EAAE,eAAe,MAAM,CAAC,CAClD;AACD,OAAK,SAAS,KAAK,UAAU,SAAS,WAAW;;;;;CAMnD,IAAI,YAAqB;AACvB,SAAO,KAAK;;;;;;CAOd,IAAI,WAAuC;AACzC,SAAO,KAAK,UAAU;;;;;;CAOxB,AAAQ,sBAA0C;AAChD,SAAO,iBAAiB,EAAE,WAAW,eAAe;;CAGtD,AAAQ,WAAiB;AACvB,MAAI,CAAC,KAAK,YAAY;AACpB,QAAK,aAAa;AAClB,QAAK,eAAe;;;;;;CAOxB,AAAQ,aAAa,UAAiC;AACpD,SAAO,KAAK,OAAO,MAAM,KAAK,QAAQ,OAAO,SAAS,CAAC;;;;;CAMzD,AAAQ,QAAQ,UAAwB;AACtC,MAAI,KAAK,SAAU;AAEnB,OAAK,aAAa,KAAK,WACpB,WAAW,KAAK,aAAa,SAAS,CAAC,CACvC,OAAO,QAAQ;AAGd,QAAK,WAAW;AAChB,QAAK,eAAe,IAAI;IACxB;;;;;;CAON,OAAO,cAAmC;AACxC,OAAK,QAAQ,oBAAoB,aAAa,CAAC;;;;;;CAOjD,SAAS,cAAmC;AAC1C,OAAK,QAAQ,sBAAsB,aAAa,CAAC;;;;;;CAOnD,AAAQ,mBAAmB,MAAe,cAAgC;EACxE,IAAIA;AACJ,MA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OAAqB;AAC/B,OAAK,YAAY,oBAAoB,MAAM,CAAC;;;;;CAM9C,AAAQ,YAAY,YAA2B;AAC7C,OAAK,aAAa,KAAK,WACpB,KAAK,YAAY;AAChB,OAAI,WACF,OAAM,KAAK,aAAa,WAAW;AAErC,SAAM,KAAK,OAAO,OAAO;IACzB,CACD,OAAO,QAAQ;AACd,QAAK,eAAe,IAAI;IACxB;;;;;;CAON,MAAY;AACV,OAAK,aAAa;;;;AAKtB,MAAM,2BAA+C;AAEnD,QADY,iBAAiB,EACjB,WAAW;;AAGzB,MAAM,2BAA2B,YAAyC;AAExE,SADY,MAAM,aAAa,GACnB,WAAW;;;;;;AAOzB,MAAaG,SAAsB;CACjC,OAAO,SAAS;EAEd,MAAM,aAAa,oBAAoB;AACvC,MAAI,YAAY;AACd,cAAW,KAAK,KAAK;AACrB;;AAIF,EAAK,0BAA0B,CAC5B,MAAM,MAAM;AACX,MAAG,KAAK,KAAK;IACb,CACD,YAAY,GAGX;;CAEN,MAAM,OAAO,WAAW;EACtB,MAAM,aAAa,oBAAoB;AACvC,MAAI,WACF,QAAO,WAAW,KAAK,OAAO;EAGhC,MAAM,IAAI,MAAM,0BAA0B;AAC1C,MAAI,EACF,QAAO,EAAE,KAAK,OAAO;AAEvB,SAAO;;CAEV"}
@@ -0,0 +1,46 @@
1
+ const require_InngestCommHandler = require('./InngestCommHandler.cjs');
2
+
3
+ //#region src/components/createWebApiCommHandler.ts
4
+ /**
5
+ * Creates an {@link InngestCommHandler} that uses Web API `Request`/`Response`.
6
+ *
7
+ * This is shared by the edge and Node.js adapters so the handler logic isn't
8
+ * duplicated.
9
+ */
10
+ const createWebApiCommHandler = (frameworkName, options, syncOptions) => {
11
+ return new require_InngestCommHandler.InngestCommHandler({
12
+ frameworkName,
13
+ ...options,
14
+ syncOptions,
15
+ handler: (req) => {
16
+ return {
17
+ body: () => req.text(),
18
+ headers: (key) => req.headers.get(key),
19
+ method: () => req.method,
20
+ url: () => new URL(req.url, `https://${req.headers.get("host") || ""}`),
21
+ transformResponse: ({ body, status, headers }) => {
22
+ return new Response(body, {
23
+ status,
24
+ headers
25
+ });
26
+ },
27
+ experimentalTransformSyncResponse: async (data) => {
28
+ const res = data;
29
+ const headers = {};
30
+ res.headers.forEach((v, k) => {
31
+ headers[k] = v;
32
+ });
33
+ return {
34
+ headers,
35
+ status: res.status,
36
+ body: await res.clone().text()
37
+ };
38
+ }
39
+ };
40
+ }
41
+ });
42
+ };
43
+
44
+ //#endregion
45
+ exports.createWebApiCommHandler = createWebApiCommHandler;
46
+ //# sourceMappingURL=createWebApiCommHandler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWebApiCommHandler.cjs","names":["InngestCommHandler","headers: Record<string, string>"],"sources":["../../src/components/createWebApiCommHandler.ts"],"sourcesContent":["import type { RegisterOptions, SupportedFrameworkName } from \"../types.ts\";\nimport type { Inngest } from \"./Inngest.ts\";\nimport {\n InngestCommHandler,\n type SyncHandlerOptions,\n} from \"./InngestCommHandler.ts\";\n\n/**\n * Creates an {@link InngestCommHandler} that uses Web API `Request`/`Response`.\n *\n * This is shared by the edge and Node.js adapters so the handler logic isn't\n * duplicated.\n */\nexport const createWebApiCommHandler = (\n frameworkName: SupportedFrameworkName,\n options: RegisterOptions & { client: Inngest.Like },\n syncOptions?: SyncHandlerOptions,\n): InngestCommHandler => {\n return new InngestCommHandler({\n frameworkName,\n ...options,\n syncOptions,\n handler: (req: Request) => {\n return {\n body: () => req.text(),\n headers: (key: string) => req.headers.get(key),\n method: () => req.method,\n url: () => new URL(req.url, `https://${req.headers.get(\"host\") || \"\"}`),\n transformResponse: ({ body, status, headers }) => {\n return new Response(body, { status, headers });\n },\n experimentalTransformSyncResponse: async (data) => {\n const res = data as Response;\n\n const headers: Record<string, string> = {};\n res.headers.forEach((v, k) => {\n headers[k] = v;\n });\n\n return {\n headers,\n status: res.status,\n body: await res.clone().text(),\n };\n },\n };\n },\n });\n};\n"],"mappings":";;;;;;;;;AAaA,MAAa,2BACX,eACA,SACA,gBACuB;AACvB,QAAO,IAAIA,8CAAmB;EAC5B;EACA,GAAG;EACH;EACA,UAAU,QAAiB;AACzB,UAAO;IACL,YAAY,IAAI,MAAM;IACtB,UAAU,QAAgB,IAAI,QAAQ,IAAI,IAAI;IAC9C,cAAc,IAAI;IAClB,WAAW,IAAI,IAAI,IAAI,KAAK,WAAW,IAAI,QAAQ,IAAI,OAAO,IAAI,KAAK;IACvE,oBAAoB,EAAE,MAAM,QAAQ,cAAc;AAChD,YAAO,IAAI,SAAS,MAAM;MAAE;MAAQ;MAAS,CAAC;;IAEhD,mCAAmC,OAAO,SAAS;KACjD,MAAM,MAAM;KAEZ,MAAMC,UAAkC,EAAE;AAC1C,SAAI,QAAQ,SAAS,GAAG,MAAM;AAC5B,cAAQ,KAAK;OACb;AAEF,YAAO;MACL;MACA,QAAQ,IAAI;MACZ,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM;MAC/B;;IAEJ;;EAEJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { InngestCommHandler } from "./InngestCommHandler.js";
2
+
3
+ //#region src/components/createWebApiCommHandler.ts
4
+ /**
5
+ * Creates an {@link InngestCommHandler} that uses Web API `Request`/`Response`.
6
+ *
7
+ * This is shared by the edge and Node.js adapters so the handler logic isn't
8
+ * duplicated.
9
+ */
10
+ const createWebApiCommHandler = (frameworkName, options, syncOptions) => {
11
+ return new InngestCommHandler({
12
+ frameworkName,
13
+ ...options,
14
+ syncOptions,
15
+ handler: (req) => {
16
+ return {
17
+ body: () => req.text(),
18
+ headers: (key) => req.headers.get(key),
19
+ method: () => req.method,
20
+ url: () => new URL(req.url, `https://${req.headers.get("host") || ""}`),
21
+ transformResponse: ({ body, status, headers }) => {
22
+ return new Response(body, {
23
+ status,
24
+ headers
25
+ });
26
+ },
27
+ experimentalTransformSyncResponse: async (data) => {
28
+ const res = data;
29
+ const headers = {};
30
+ res.headers.forEach((v, k) => {
31
+ headers[k] = v;
32
+ });
33
+ return {
34
+ headers,
35
+ status: res.status,
36
+ body: await res.clone().text()
37
+ };
38
+ }
39
+ };
40
+ }
41
+ });
42
+ };
43
+
44
+ //#endregion
45
+ export { createWebApiCommHandler };
46
+ //# sourceMappingURL=createWebApiCommHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWebApiCommHandler.js","names":["headers: Record<string, string>"],"sources":["../../src/components/createWebApiCommHandler.ts"],"sourcesContent":["import type { RegisterOptions, SupportedFrameworkName } from \"../types.ts\";\nimport type { Inngest } from \"./Inngest.ts\";\nimport {\n InngestCommHandler,\n type SyncHandlerOptions,\n} from \"./InngestCommHandler.ts\";\n\n/**\n * Creates an {@link InngestCommHandler} that uses Web API `Request`/`Response`.\n *\n * This is shared by the edge and Node.js adapters so the handler logic isn't\n * duplicated.\n */\nexport const createWebApiCommHandler = (\n frameworkName: SupportedFrameworkName,\n options: RegisterOptions & { client: Inngest.Like },\n syncOptions?: SyncHandlerOptions,\n): InngestCommHandler => {\n return new InngestCommHandler({\n frameworkName,\n ...options,\n syncOptions,\n handler: (req: Request) => {\n return {\n body: () => req.text(),\n headers: (key: string) => req.headers.get(key),\n method: () => req.method,\n url: () => new URL(req.url, `https://${req.headers.get(\"host\") || \"\"}`),\n transformResponse: ({ body, status, headers }) => {\n return new Response(body, { status, headers });\n },\n experimentalTransformSyncResponse: async (data) => {\n const res = data as Response;\n\n const headers: Record<string, string> = {};\n res.headers.forEach((v, k) => {\n headers[k] = v;\n });\n\n return {\n headers,\n status: res.status,\n body: await res.clone().text(),\n };\n },\n };\n },\n });\n};\n"],"mappings":";;;;;;;;;AAaA,MAAa,2BACX,eACA,SACA,gBACuB;AACvB,QAAO,IAAI,mBAAmB;EAC5B;EACA,GAAG;EACH;EACA,UAAU,QAAiB;AACzB,UAAO;IACL,YAAY,IAAI,MAAM;IACtB,UAAU,QAAgB,IAAI,QAAQ,IAAI,IAAI;IAC9C,cAAc,IAAI;IAClB,WAAW,IAAI,IAAI,IAAI,KAAK,WAAW,IAAI,QAAQ,IAAI,OAAO,IAAI,KAAK;IACvE,oBAAoB,EAAE,MAAM,QAAQ,cAAc;AAChD,YAAO,IAAI,SAAS,MAAM;MAAE;MAAQ;MAAS,CAAC;;IAEhD,mCAAmC,OAAO,SAAS;KACjD,MAAM,MAAM;KAEZ,MAAMA,UAAkC,EAAE;AAC1C,SAAI,QAAQ,SAAS,GAAG,MAAM;AAC5B,cAAQ,KAAK;OACb;AAEF,YAAO;MACL;MACA,QAAQ,IAAI;MACZ,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM;MAC/B;;IAEJ;;EAEJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"InngestExecution.cjs","names":["ExecutionVersion","options: InngestExecutionOptions","debugPrefix"],"sources":["../../../src/components/execution/InngestExecution.ts"],"sourcesContent":["import Debug, { type Debugger } from \"debug\";\nimport { debugPrefix, ExecutionVersion } from \"../../helpers/consts.ts\";\nimport type { ServerTiming } from \"../../helpers/ServerTiming.ts\";\nimport type { MaybePromise, Simplify } from \"../../helpers/types.ts\";\nimport type {\n Context,\n IncomingOp,\n InternalCheckpointingOptions,\n OutgoingOp,\n StepMode,\n} from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { ActionResponse } from \"../InngestCommHandler.ts\";\nimport type { InngestFunction } from \"../InngestFunction.ts\";\nimport type {\n MetadataKind,\n MetadataOpcode,\n MetadataScope,\n} from \"../InngestMetadata.ts\";\nimport type { Middleware } from \"../middleware/middleware.ts\";\n\n// Re-export ExecutionVersion so it's correctly recognized as an enum and not\n// just a type. This can be lost when bundling if we don't re-export it here.\n// See `pnpm run test:dist`.\nexport { ExecutionVersion };\n\n/**\n * The possible results of an execution.\n */\nexport interface ExecutionResults {\n \"function-resolved\": { data: unknown };\n \"step-ran\": { step: OutgoingOp; retriable?: boolean | string };\n \"function-rejected\": { error: unknown; retriable: boolean | string };\n \"steps-found\": { steps: [OutgoingOp, ...OutgoingOp[]] };\n \"step-not-found\": {\n step: OutgoingOp;\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n };\n\n /**\n * Indicates that we need to relinquish control back to Inngest in order to\n * change step modes.\n */\n \"change-mode\": {\n to: StepMode;\n token: string;\n };\n}\n\nexport type ExecutionResult = {\n [K in keyof ExecutionResults]: Simplify<\n {\n type: K;\n ctx: Context.Any;\n ops: Record<string, MemoizedOp>;\n } & ExecutionResults[K]\n >;\n}[keyof ExecutionResults];\n\nexport interface BasicFoundStep {\n id: string;\n displayName?: string;\n}\n\nexport type ExecutionResultHandler<T = ActionResponse> = (\n result: ExecutionResult,\n) => MaybePromise<T>;\n\nexport type ExecutionResultHandlers<T = ActionResponse> = {\n [E in ExecutionResult as E[\"type\"]]: (result: E) => MaybePromise<T>;\n};\n\nexport interface MemoizedOp extends IncomingOp {\n /**\n * If the step has been hit during this run, these will be the arguments\n * passed to it.\n */\n rawArgs?: unknown[];\n fulfilled?: boolean;\n\n /**\n * The promise that has been returned to userland code.\n */\n promise?: Promise<unknown>;\n seen?: boolean;\n}\n\n/**\n * The preferred execution version that will be used by the SDK when handling\n * brand new runs where the Executor is allowing us to choose.\n *\n * Changing this should not ever be a breaking change, as this will only change\n * new runs, not existing ones.\n */\nexport const PREFERRED_ASYNC_EXECUTION_VERSION =\n ExecutionVersion.V2 satisfies ExecutionVersion;\n\n/**\n * Options for creating a new {@link InngestExecution} instance.\n */\nexport interface InngestExecutionOptions {\n client: Inngest.Any;\n fn: InngestFunction.Any;\n\n /**\n * The UUID that represents this function in Inngest.\n *\n * This is used to reference the function during async checkpointing, when we\n * know the function/run already exists and just wish to reference it\n * directly.\n */\n internalFnId?: string;\n reqArgs: unknown[];\n runId: string;\n data: Omit<Context.Any, \"step\" | \"group\" | \"publish\">;\n stepState: Record<string, MemoizedOp>;\n stepCompletionOrder: string[];\n stepMode: StepMode;\n checkpointingConfig?: InternalCheckpointingOptions;\n\n /**\n * If this execution is being run from a queue job, this will be an identifier\n * used to reference this execution in Inngest. SDKs are expected to parrot\n * this back in some responses to correctly attribute actions to this queue\n * item.\n */\n queueItemId?: string;\n\n /**\n * Headers to be sent with any request to Inngest during this execution.\n */\n headers: Record<string, string>;\n requestedRunStep?: string;\n timer?: ServerTiming;\n isFailureHandler?: boolean;\n disableImmediateExecution?: boolean;\n\n /**\n * Information about the incoming HTTP request that triggered this execution.\n * Used by middleware `wrapRequest` hooks.\n */\n requestInfo?: Middleware.Request;\n\n /**\n * Pre-created middleware instances to use for this execution. When provided,\n * the execution will use these instead of instantiating new ones from the\n * client. This ensures `wrapRequest` and other hooks share state on `this`.\n */\n middlewareInstances?: Middleware.BaseMiddleware[];\n\n /**\n * Provide the ability to transform the context passed to the function before\n * the execution starts.\n */\n transformCtx?: (ctx: Readonly<Context.Any>) => Context.Any;\n\n /**\n * A hook that is called to create an {@link ActionResponse} from the returned\n * value of an execution.\n *\n * This is required for checkpointing executions.\n */\n createResponse?: (data: unknown) => MaybePromise<ActionResponse>;\n}\n\nexport type InngestExecutionFactory = (\n options: InngestExecutionOptions,\n) => IInngestExecution;\n\nexport class InngestExecution {\n protected devDebug: Debugger;\n\n constructor(protected options: InngestExecutionOptions) {\n this.devDebug = Debug(`${debugPrefix}:${this.options.runId}`);\n }\n}\n\nexport interface IInngestExecution {\n version: ExecutionVersion;\n start(): Promise<ExecutionResult>;\n\n addMetadata(\n stepId: string,\n kind: MetadataKind,\n scope: MetadataScope,\n op: MetadataOpcode,\n values: Record<string, unknown>,\n ): boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+FA,MAAa,oCACXA,gCAAiB;AA0EnB,IAAa,mBAAb,MAA8B;CAC5B,AAAU;CAEV,YAAY,AAAUC,SAAkC;EAAlC;AACpB,OAAK,8BAAiB,GAAGC,2BAAY,GAAG,KAAK,QAAQ,QAAQ"}
1
+ {"version":3,"file":"InngestExecution.cjs","names":["ExecutionVersion","options: InngestExecutionOptions","debugPrefix"],"sources":["../../../src/components/execution/InngestExecution.ts"],"sourcesContent":["import Debug, { type Debugger } from \"debug\";\nimport { debugPrefix, ExecutionVersion } from \"../../helpers/consts.ts\";\nimport type { ServerTiming } from \"../../helpers/ServerTiming.ts\";\nimport type { MaybePromise, Simplify } from \"../../helpers/types.ts\";\nimport type {\n Context,\n IncomingOp,\n InternalCheckpointingOptions,\n OutgoingOp,\n StepMode,\n} from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { ActionResponse } from \"../InngestCommHandler.ts\";\nimport type { InngestFunction } from \"../InngestFunction.ts\";\nimport type {\n MetadataKind,\n MetadataOpcode,\n MetadataScope,\n} from \"../InngestMetadata.ts\";\nimport type { Middleware } from \"../middleware/middleware.ts\";\n\n// Re-export ExecutionVersion so it's correctly recognized as an enum and not\n// just a type. This can be lost when bundling if we don't re-export it here.\n// See `pnpm run test:dist`.\nexport { ExecutionVersion };\n\n/**\n * The possible results of an execution.\n */\nexport interface ExecutionResults {\n \"function-resolved\": { data: unknown };\n \"step-ran\": { step: OutgoingOp; retriable?: boolean | string };\n \"function-rejected\": { error: unknown; retriable: boolean | string };\n \"steps-found\": { steps: [OutgoingOp, ...OutgoingOp[]] };\n \"step-not-found\": {\n step: OutgoingOp;\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n };\n\n /**\n * Indicates that we need to relinquish control back to Inngest in order to\n * change step modes.\n */\n \"change-mode\": {\n to: StepMode;\n token: string;\n };\n}\n\nexport type ExecutionResult = {\n [K in keyof ExecutionResults]: Simplify<\n {\n type: K;\n ctx: Context.Any;\n ops: Record<string, MemoizedOp>;\n } & ExecutionResults[K]\n >;\n}[keyof ExecutionResults];\n\nexport interface BasicFoundStep {\n id: string;\n displayName?: string;\n}\n\nexport type ExecutionResultHandler<T = ActionResponse> = (\n result: ExecutionResult,\n) => MaybePromise<T>;\n\nexport type ExecutionResultHandlers<T = ActionResponse> = {\n [E in ExecutionResult as E[\"type\"]]: (result: E) => MaybePromise<T>;\n};\n\nexport interface MemoizedOp extends IncomingOp {\n /**\n * If the step has been hit during this run, these will be the arguments\n * passed to it.\n */\n rawArgs?: unknown[];\n fulfilled?: boolean;\n\n /**\n * The promise that has been returned to userland code.\n */\n promise?: Promise<unknown>;\n seen?: boolean;\n}\n\n/**\n * The preferred execution version that will be used by the SDK when handling\n * brand new runs where the Executor is allowing us to choose.\n *\n * Changing this should not ever be a breaking change, as this will only change\n * new runs, not existing ones.\n */\nexport const PREFERRED_ASYNC_EXECUTION_VERSION =\n ExecutionVersion.V2 satisfies ExecutionVersion;\n\n/**\n * Options for creating a new {@link InngestExecution} instance.\n */\nexport interface InngestExecutionOptions {\n client: Inngest.Any;\n fn: InngestFunction.Any;\n\n /**\n * The UUID that represents this function in Inngest.\n *\n * This is used to reference the function during async checkpointing, when we\n * know the function/run already exists and just wish to reference it\n * directly.\n */\n internalFnId?: string;\n reqArgs: unknown[];\n runId: string;\n data: Omit<Context.Any, \"step\" | \"group\" | \"publish\">;\n stepState: Record<string, MemoizedOp>;\n stepCompletionOrder: string[];\n stepMode: StepMode;\n checkpointingConfig?: InternalCheckpointingOptions;\n\n /**\n * If this execution is being run from a queue job, this will be an identifier\n * used to reference this execution in Inngest. SDKs are expected to parrot\n * this back in some responses to correctly attribute actions to this queue\n * item.\n */\n queueItemId?: string;\n\n /**\n * Headers to be sent with any request to Inngest during this execution.\n */\n headers: Record<string, string>;\n requestedRunStep?: string;\n timer?: ServerTiming;\n isFailureHandler?: boolean;\n disableImmediateExecution?: boolean;\n\n /**\n * Information about the incoming HTTP request that triggered this execution.\n * Used by middleware `wrapRequest` hooks.\n */\n requestInfo?: Middleware.Request;\n\n /**\n * Pre-created middleware instances to use for this execution. When provided,\n * the execution will use these instead of instantiating new ones from the\n * client. This ensures `wrapRequest` and other hooks share state on `this`.\n */\n middlewareInstances?: Middleware.BaseMiddleware[];\n\n /**\n * Whether the client accepts SSE (`Accept: text/event-stream`). When true,\n * the execution engine may deliver the result as an SSE stream even if\n * `stream.push()` was not called.\n */\n acceptsSse?: boolean;\n\n /**\n * Provide the ability to transform the context passed to the function before\n * the execution starts.\n */\n transformCtx?: (ctx: Readonly<Context.Any>) => Context.Any;\n\n /**\n * A hook that is called to create an {@link ActionResponse} from the returned\n * value of an execution.\n *\n * This is required for checkpointing executions.\n */\n createResponse?: (data: unknown) => MaybePromise<ActionResponse>;\n}\n\nexport type InngestExecutionFactory = (\n options: InngestExecutionOptions,\n) => IInngestExecution;\n\nexport class InngestExecution {\n protected devDebug: Debugger;\n\n constructor(protected options: InngestExecutionOptions) {\n this.devDebug = Debug(`${debugPrefix}:${this.options.runId}`);\n }\n}\n\nexport interface IInngestExecution {\n version: ExecutionVersion;\n start(): Promise<ExecutionResult>;\n\n addMetadata(\n stepId: string,\n kind: MetadataKind,\n scope: MetadataScope,\n op: MetadataOpcode,\n values: Record<string, unknown>,\n ): boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+FA,MAAa,oCACXA,gCAAiB;AAiFnB,IAAa,mBAAb,MAA8B;CAC5B,AAAU;CAEV,YAAY,AAAUC,SAAkC;EAAlC;AACpB,OAAK,8BAAiB,GAAGC,2BAAY,GAAG,KAAK,QAAQ,QAAQ"}
@@ -124,6 +124,12 @@ interface InngestExecutionOptions {
124
124
  * client. This ensures `wrapRequest` and other hooks share state on `this`.
125
125
  */
126
126
  middlewareInstances?: Middleware.BaseMiddleware[];
127
+ /**
128
+ * Whether the client accepts SSE (`Accept: text/event-stream`). When true,
129
+ * the execution engine may deliver the result as an SSE stream even if
130
+ * `stream.push()` was not called.
131
+ */
132
+ acceptsSse?: boolean;
127
133
  /**
128
134
  * Provide the ability to transform the context passed to the function before
129
135
  * the execution starts.
@@ -1 +1 @@
1
- {"version":3,"file":"InngestExecution.d.cts","names":[],"sources":["../../../src/components/execution/InngestExecution.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;UA6BiB,gBAAA;;;;;UAEK;;;;;;;;IAFL,KAAA,EAAA,CAIU,UAJM,EAAA,GAIS,UAJT,EAAA,CAAA;EAAA,CAAA;kBAEX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SAAS,OAAA,CAAQ;;;;;;;sCAQnB,aAAa;;KAGvC,uBAAA,aACD,4BACN;cAEQ,gBAAA;qBAGoB;sBAFX;uBAEW;;UAKhB,iBAAA;WACN;WACA,QAAQ;oCAIT,qBACC,mBACH,wBACI"}
@@ -124,6 +124,12 @@ interface InngestExecutionOptions {
124
124
  * client. This ensures `wrapRequest` and other hooks share state on `this`.
125
125
  */
126
126
  middlewareInstances?: Middleware.BaseMiddleware[];
127
+ /**
128
+ * Whether the client accepts SSE (`Accept: text/event-stream`). When true,
129
+ * the execution engine may deliver the result as an SSE stream even if
130
+ * `stream.push()` was not called.
131
+ */
132
+ acceptsSse?: boolean;
127
133
  /**
128
134
  * Provide the ability to transform the context passed to the function before
129
135
  * the execution starts.
@@ -1 +1 @@
1
- {"version":3,"file":"InngestExecution.d.ts","names":[],"sources":["../../../src/components/execution/InngestExecution.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;UA6BiB,gBAAA;;;;;UAEK;;;;;;;;IAFL,KAAA,EAAA,CAIU,UAJM,EAAA,GAIS,UAJT,EAAA,CAAA;EAAA,CAAA;kBAEX,EAAA;IAEK,IAAA,EAEjB,UAFiB;IAAe,UAAA,EAG1B,cAH0B,EAAA;IAEhC,eAAA,EAAA,MAAA;;;;AAeV;;eACc,EAAA;IAEF,EAAA,EARJ,QAQI;IACD,KAAA,EAAQ,MAAA;;;AAEX,KANI,eAAA,GAMJ,QAAiB,MALX,gBAKW,GALQ,QAKR,CAAA;EALQ,IAAA,EAErB,CAFqB;EAOzB,GAAA,EAJG,OAAA,CAAQ,GAIX;EAAgB,GAAA,EAHb,MAGa,CAAA,MAAA,EAHE,UAGF,CAAA;AAEP,CAAA,GAJT,gBAIuB,CAJN,CAIM,CAAA,CAAA,EAK/B,CAAA,MAPQ,gBAOI,CAAA;AAAsB,UALjB,cAAA,CAKiB;MAAK,MAAA;aAC7B,CAAA,EAAA,MAAA;;AACL,KAFO,sBAEP,CAAA,IAFkC,cAElC,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BAAA;WACN;WACA,QAAQ;oCAIT,qBACC,mBACH,wBACI"}
1
+ {"version":3,"file":"InngestExecution.d.ts","names":[],"sources":["../../../src/components/execution/InngestExecution.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;UA6BiB,gBAAA;;;;;UAEK;;;;;;;;IAFL,KAAA,EAAA,CAIU,UAJM,EAAA,GAIS,UAJT,EAAA,CAAA;EAAA,CAAA;kBAEX,EAAA;IAEK,IAAA,EAEjB,UAFiB;IAAe,UAAA,EAG1B,cAH0B,EAAA;IAEhC,eAAA,EAAA,MAAA;;;;AAeV;;eACc,EAAA;IAEF,EAAA,EARJ,QAQI;IACD,KAAA,EAAQ,MAAA;;;AAEX,KANI,eAAA,GAMJ,QAAiB,MALX,gBAKW,GALQ,QAKR,CAAA;EALQ,IAAA,EAErB,CAFqB;EAOzB,GAAA,EAJG,OAAA,CAAQ,GAIX;EAAgB,GAAA,EAHb,MAGa,CAAA,MAAA,EAHE,UAGF,CAAA;AAEP,CAAA,GAJT,gBAIuB,CAJN,CAIM,CAAA,CAAA,EAK/B,CAAA,MAPQ,gBAOI,CAAA;AAAsB,UALjB,cAAA,CAKiB;MAAK,MAAA;aAC7B,CAAA,EAAA,MAAA;;AACL,KAFO,sBAEP,CAAA,IAFkC,cAElC,CAAA,GAAA,CAAA,MAAA,EADK,eACL,EAAA,GAAA,YAAA,CAAa,CAAb,CAAA;AAAY,KAEL,uBAFK,CAAA,IAEuB,cAFvB,CAAA,GAAA,QAGT,eADI,IACe,CADQ,CAAA,MAAA,CAAA,GAAA,CAAA,MAAA,EACa,CADb,EAAA,GACmB,YADnB,CACgC,CADhC,CAAA,EAAA;AAAK,UAIvB,UAAA,SAAmB,UAJI,CAAA;;;;;SACc,CAAA,EAAA,OAAA,EAAA;EAAY,SAAA,CAAA,EAAA,OAAA;EAGjD;;;SAAmB,CAAA,EAWxB,OAXwB,CAAA,OAAA,CAAA;EAAU,IAAA,CAAA,EAAA,OAAA;AAsB9C;AAMA;;;;;;;AAea,cArBA,iCAAA,GAqBA,gBAAA,CAAA,EAAA;;;;AAkBH,UAjCO,uBAAA,CAiCP;QAQM,EAxCN,OAAA,CAAQ,GAwCS;MAvCrB,eAAA,CAAgB,GA8Ca;;;;;;;AAwBnC;EAAmC,YAAA,CAAA,EAAA,MAAA;SACxB,EAAA,OAAA,EAAA;OACN,EAAA,MAAA;EAAiB,IAAA,EA5Dd,IA4Dc,CA5DT,OAAA,CAAQ,GA4DC,EAAA,MAAA,GAAA,OAAA,GAAA,SAAA,CAAA;EAET,SAAA,EA7DA,MA6DA,CAAA,MAAgB,EA7DD,UA6DC,CAAA;EAAA,mBAAA,EAAA,MAAA,EAAA;UAGI,EA9DrB,QA8DqB;qBAFX,CAAA,EA3DE,4BA2DF;;;AAOtB;;;;aAEW,CAAA,EAAA,MAAA;;;;SAOC,EA9DD,MA8DC,CAAA,MAAA,EAAA,MAAA,CAAA;EAAM,gBAAA,CAAA,EAAA,MAAA;UA5DR;;;;;;;gBAQM,UAAA,CAAW;;;;;;wBAOH,UAAA,CAAW;;;;;;;;;;;uBAaZ,SAAS,OAAA,CAAQ,SAAS,OAAA,CAAQ;;;;;;;sCAQnB,aAAa;;KAGvC,uBAAA,aACD,4BACN;cAEQ,gBAAA;qBAGoB;sBAFX;uBAEW;;UAKhB,iBAAA;WACN;WACA,QAAQ;oCAIT,qBACC,mBACH,wBACI"}
@@ -1 +1 @@
1
- {"version":3,"file":"InngestExecution.js","names":["options: InngestExecutionOptions"],"sources":["../../../src/components/execution/InngestExecution.ts"],"sourcesContent":["import Debug, { type Debugger } from \"debug\";\nimport { debugPrefix, ExecutionVersion } from \"../../helpers/consts.ts\";\nimport type { ServerTiming } from \"../../helpers/ServerTiming.ts\";\nimport type { MaybePromise, Simplify } from \"../../helpers/types.ts\";\nimport type {\n Context,\n IncomingOp,\n InternalCheckpointingOptions,\n OutgoingOp,\n StepMode,\n} from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { ActionResponse } from \"../InngestCommHandler.ts\";\nimport type { InngestFunction } from \"../InngestFunction.ts\";\nimport type {\n MetadataKind,\n MetadataOpcode,\n MetadataScope,\n} from \"../InngestMetadata.ts\";\nimport type { Middleware } from \"../middleware/middleware.ts\";\n\n// Re-export ExecutionVersion so it's correctly recognized as an enum and not\n// just a type. This can be lost when bundling if we don't re-export it here.\n// See `pnpm run test:dist`.\nexport { ExecutionVersion };\n\n/**\n * The possible results of an execution.\n */\nexport interface ExecutionResults {\n \"function-resolved\": { data: unknown };\n \"step-ran\": { step: OutgoingOp; retriable?: boolean | string };\n \"function-rejected\": { error: unknown; retriable: boolean | string };\n \"steps-found\": { steps: [OutgoingOp, ...OutgoingOp[]] };\n \"step-not-found\": {\n step: OutgoingOp;\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n };\n\n /**\n * Indicates that we need to relinquish control back to Inngest in order to\n * change step modes.\n */\n \"change-mode\": {\n to: StepMode;\n token: string;\n };\n}\n\nexport type ExecutionResult = {\n [K in keyof ExecutionResults]: Simplify<\n {\n type: K;\n ctx: Context.Any;\n ops: Record<string, MemoizedOp>;\n } & ExecutionResults[K]\n >;\n}[keyof ExecutionResults];\n\nexport interface BasicFoundStep {\n id: string;\n displayName?: string;\n}\n\nexport type ExecutionResultHandler<T = ActionResponse> = (\n result: ExecutionResult,\n) => MaybePromise<T>;\n\nexport type ExecutionResultHandlers<T = ActionResponse> = {\n [E in ExecutionResult as E[\"type\"]]: (result: E) => MaybePromise<T>;\n};\n\nexport interface MemoizedOp extends IncomingOp {\n /**\n * If the step has been hit during this run, these will be the arguments\n * passed to it.\n */\n rawArgs?: unknown[];\n fulfilled?: boolean;\n\n /**\n * The promise that has been returned to userland code.\n */\n promise?: Promise<unknown>;\n seen?: boolean;\n}\n\n/**\n * The preferred execution version that will be used by the SDK when handling\n * brand new runs where the Executor is allowing us to choose.\n *\n * Changing this should not ever be a breaking change, as this will only change\n * new runs, not existing ones.\n */\nexport const PREFERRED_ASYNC_EXECUTION_VERSION =\n ExecutionVersion.V2 satisfies ExecutionVersion;\n\n/**\n * Options for creating a new {@link InngestExecution} instance.\n */\nexport interface InngestExecutionOptions {\n client: Inngest.Any;\n fn: InngestFunction.Any;\n\n /**\n * The UUID that represents this function in Inngest.\n *\n * This is used to reference the function during async checkpointing, when we\n * know the function/run already exists and just wish to reference it\n * directly.\n */\n internalFnId?: string;\n reqArgs: unknown[];\n runId: string;\n data: Omit<Context.Any, \"step\" | \"group\" | \"publish\">;\n stepState: Record<string, MemoizedOp>;\n stepCompletionOrder: string[];\n stepMode: StepMode;\n checkpointingConfig?: InternalCheckpointingOptions;\n\n /**\n * If this execution is being run from a queue job, this will be an identifier\n * used to reference this execution in Inngest. SDKs are expected to parrot\n * this back in some responses to correctly attribute actions to this queue\n * item.\n */\n queueItemId?: string;\n\n /**\n * Headers to be sent with any request to Inngest during this execution.\n */\n headers: Record<string, string>;\n requestedRunStep?: string;\n timer?: ServerTiming;\n isFailureHandler?: boolean;\n disableImmediateExecution?: boolean;\n\n /**\n * Information about the incoming HTTP request that triggered this execution.\n * Used by middleware `wrapRequest` hooks.\n */\n requestInfo?: Middleware.Request;\n\n /**\n * Pre-created middleware instances to use for this execution. When provided,\n * the execution will use these instead of instantiating new ones from the\n * client. This ensures `wrapRequest` and other hooks share state on `this`.\n */\n middlewareInstances?: Middleware.BaseMiddleware[];\n\n /**\n * Provide the ability to transform the context passed to the function before\n * the execution starts.\n */\n transformCtx?: (ctx: Readonly<Context.Any>) => Context.Any;\n\n /**\n * A hook that is called to create an {@link ActionResponse} from the returned\n * value of an execution.\n *\n * This is required for checkpointing executions.\n */\n createResponse?: (data: unknown) => MaybePromise<ActionResponse>;\n}\n\nexport type InngestExecutionFactory = (\n options: InngestExecutionOptions,\n) => IInngestExecution;\n\nexport class InngestExecution {\n protected devDebug: Debugger;\n\n constructor(protected options: InngestExecutionOptions) {\n this.devDebug = Debug(`${debugPrefix}:${this.options.runId}`);\n }\n}\n\nexport interface IInngestExecution {\n version: ExecutionVersion;\n start(): Promise<ExecutionResult>;\n\n addMetadata(\n stepId: string,\n kind: MetadataKind,\n scope: MetadataScope,\n op: MetadataOpcode,\n values: Record<string, unknown>,\n ): boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA+FA,MAAa,oCACX,iBAAiB;AA0EnB,IAAa,mBAAb,MAA8B;CAC5B,AAAU;CAEV,YAAY,AAAUA,SAAkC;EAAlC;AACpB,OAAK,WAAW,MAAM,GAAG,YAAY,GAAG,KAAK,QAAQ,QAAQ"}
1
+ {"version":3,"file":"InngestExecution.js","names":["options: InngestExecutionOptions"],"sources":["../../../src/components/execution/InngestExecution.ts"],"sourcesContent":["import Debug, { type Debugger } from \"debug\";\nimport { debugPrefix, ExecutionVersion } from \"../../helpers/consts.ts\";\nimport type { ServerTiming } from \"../../helpers/ServerTiming.ts\";\nimport type { MaybePromise, Simplify } from \"../../helpers/types.ts\";\nimport type {\n Context,\n IncomingOp,\n InternalCheckpointingOptions,\n OutgoingOp,\n StepMode,\n} from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { ActionResponse } from \"../InngestCommHandler.ts\";\nimport type { InngestFunction } from \"../InngestFunction.ts\";\nimport type {\n MetadataKind,\n MetadataOpcode,\n MetadataScope,\n} from \"../InngestMetadata.ts\";\nimport type { Middleware } from \"../middleware/middleware.ts\";\n\n// Re-export ExecutionVersion so it's correctly recognized as an enum and not\n// just a type. This can be lost when bundling if we don't re-export it here.\n// See `pnpm run test:dist`.\nexport { ExecutionVersion };\n\n/**\n * The possible results of an execution.\n */\nexport interface ExecutionResults {\n \"function-resolved\": { data: unknown };\n \"step-ran\": { step: OutgoingOp; retriable?: boolean | string };\n \"function-rejected\": { error: unknown; retriable: boolean | string };\n \"steps-found\": { steps: [OutgoingOp, ...OutgoingOp[]] };\n \"step-not-found\": {\n step: OutgoingOp;\n foundSteps: BasicFoundStep[];\n totalFoundSteps: number;\n };\n\n /**\n * Indicates that we need to relinquish control back to Inngest in order to\n * change step modes.\n */\n \"change-mode\": {\n to: StepMode;\n token: string;\n };\n}\n\nexport type ExecutionResult = {\n [K in keyof ExecutionResults]: Simplify<\n {\n type: K;\n ctx: Context.Any;\n ops: Record<string, MemoizedOp>;\n } & ExecutionResults[K]\n >;\n}[keyof ExecutionResults];\n\nexport interface BasicFoundStep {\n id: string;\n displayName?: string;\n}\n\nexport type ExecutionResultHandler<T = ActionResponse> = (\n result: ExecutionResult,\n) => MaybePromise<T>;\n\nexport type ExecutionResultHandlers<T = ActionResponse> = {\n [E in ExecutionResult as E[\"type\"]]: (result: E) => MaybePromise<T>;\n};\n\nexport interface MemoizedOp extends IncomingOp {\n /**\n * If the step has been hit during this run, these will be the arguments\n * passed to it.\n */\n rawArgs?: unknown[];\n fulfilled?: boolean;\n\n /**\n * The promise that has been returned to userland code.\n */\n promise?: Promise<unknown>;\n seen?: boolean;\n}\n\n/**\n * The preferred execution version that will be used by the SDK when handling\n * brand new runs where the Executor is allowing us to choose.\n *\n * Changing this should not ever be a breaking change, as this will only change\n * new runs, not existing ones.\n */\nexport const PREFERRED_ASYNC_EXECUTION_VERSION =\n ExecutionVersion.V2 satisfies ExecutionVersion;\n\n/**\n * Options for creating a new {@link InngestExecution} instance.\n */\nexport interface InngestExecutionOptions {\n client: Inngest.Any;\n fn: InngestFunction.Any;\n\n /**\n * The UUID that represents this function in Inngest.\n *\n * This is used to reference the function during async checkpointing, when we\n * know the function/run already exists and just wish to reference it\n * directly.\n */\n internalFnId?: string;\n reqArgs: unknown[];\n runId: string;\n data: Omit<Context.Any, \"step\" | \"group\" | \"publish\">;\n stepState: Record<string, MemoizedOp>;\n stepCompletionOrder: string[];\n stepMode: StepMode;\n checkpointingConfig?: InternalCheckpointingOptions;\n\n /**\n * If this execution is being run from a queue job, this will be an identifier\n * used to reference this execution in Inngest. SDKs are expected to parrot\n * this back in some responses to correctly attribute actions to this queue\n * item.\n */\n queueItemId?: string;\n\n /**\n * Headers to be sent with any request to Inngest during this execution.\n */\n headers: Record<string, string>;\n requestedRunStep?: string;\n timer?: ServerTiming;\n isFailureHandler?: boolean;\n disableImmediateExecution?: boolean;\n\n /**\n * Information about the incoming HTTP request that triggered this execution.\n * Used by middleware `wrapRequest` hooks.\n */\n requestInfo?: Middleware.Request;\n\n /**\n * Pre-created middleware instances to use for this execution. When provided,\n * the execution will use these instead of instantiating new ones from the\n * client. This ensures `wrapRequest` and other hooks share state on `this`.\n */\n middlewareInstances?: Middleware.BaseMiddleware[];\n\n /**\n * Whether the client accepts SSE (`Accept: text/event-stream`). When true,\n * the execution engine may deliver the result as an SSE stream even if\n * `stream.push()` was not called.\n */\n acceptsSse?: boolean;\n\n /**\n * Provide the ability to transform the context passed to the function before\n * the execution starts.\n */\n transformCtx?: (ctx: Readonly<Context.Any>) => Context.Any;\n\n /**\n * A hook that is called to create an {@link ActionResponse} from the returned\n * value of an execution.\n *\n * This is required for checkpointing executions.\n */\n createResponse?: (data: unknown) => MaybePromise<ActionResponse>;\n}\n\nexport type InngestExecutionFactory = (\n options: InngestExecutionOptions,\n) => IInngestExecution;\n\nexport class InngestExecution {\n protected devDebug: Debugger;\n\n constructor(protected options: InngestExecutionOptions) {\n this.devDebug = Debug(`${debugPrefix}:${this.options.runId}`);\n }\n}\n\nexport interface IInngestExecution {\n version: ExecutionVersion;\n start(): Promise<ExecutionResult>;\n\n addMetadata(\n stepId: string,\n kind: MetadataKind,\n scope: MetadataScope,\n op: MetadataOpcode,\n values: Record<string, unknown>,\n ): boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA+FA,MAAa,oCACX,iBAAiB;AAiFnB,IAAa,mBAAb,MAA8B;CAC5B,AAAU;CAEV,YAAY,AAAUA,SAAkC;EAAlC;AACpB,OAAK,WAAW,MAAM,GAAG,YAAY,GAAG,KAAK,QAAQ,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"als.cjs","names":["fallback: AsyncLocalStorageIsh"],"sources":["../../../src/components/execution/als.ts"],"sourcesContent":["import type { Context, StepOptions } from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { IInngestExecution } from \"./InngestExecution.ts\";\n\n/**\n * Note - this structure can be used by other libraries, so cannot have breaking changes.\n */\nexport interface AsyncContext {\n /**\n * The Inngest App that is currently being used to execute the function.\n *\n * If this is defined, we are in the context of an Inngest function execution,\n * or a possible one.\n */\n app: Inngest.Like;\n\n /**\n * Details of the current function execution context. If this doesn't exist,\n * then we're not currently in a function execution context.\n */\n execution?: {\n /**\n * The execution instance that is currently running the function.\n */\n instance: IInngestExecution;\n\n /**\n * The `ctx` object that has been passed in to this function execution,\n * including values such as `step` and `event`.\n */\n ctx: Context.Any;\n\n /**\n * If present, this indicates we are currently executing a `step.run()` step's\n * callback. Useful to understand whether we are in the context of a step\n * execution or within the main function body.\n */\n executingStep?: StepOptions;\n\n /**\n * If present, indicates the parallel mode that should be applied to steps\n * created within this context. Set by `group.parallel()`.\n */\n parallelMode?: \"race\";\n\n /**\n * If present, indicates the variant callback is executing within an\n * experiment. Set by `group.experiment()`. Any `step.*()` call within\n * this context will include these fields in `OutgoingOp.opts`.\n */\n experimentContext?: {\n experimentStepID: string;\n experimentName: string;\n variant: string;\n };\n\n /**\n * A mutable tracker used to detect whether any step tool was invoked\n * during a variant callback. Set by `group.experiment()`, flipped by\n * `createTool` in `InngestStepTools.ts`.\n */\n experimentStepTracker?: { found: boolean };\n\n /**\n * If true, we are inside the `select()` callback of\n * `group.experiment()`. Any `step.*()` call here would create a\n * nested step, which is not allowed.\n */\n insideExperimentSelect?: boolean;\n };\n}\n\n/**\n * A local-only symbol used as a key in global state to store the async local\n * storage instance.\n */\nconst alsSymbol = Symbol.for(\"inngest:als\");\n\n/**\n * Cache structure that stores both the promise and resolved ALS instance.\n * This allows synchronous access after initialization.\n */\ntype ALSCache = {\n promise: Promise<AsyncLocalStorageIsh>;\n resolved?: AsyncLocalStorageIsh;\n isFallback?: boolean;\n};\n\n/**\n * A type that represents a partial, runtime-agnostic interface of\n * `AsyncLocalStorage`.\n */\ntype AsyncLocalStorageIsh = {\n getStore: () => AsyncContext | undefined;\n run: <R>(store: AsyncContext, fn: () => R) => R;\n};\n\nconst getCache = (): ALSCache => {\n const g = globalThis as Record<symbol, ALSCache | undefined>;\n\n if (!g[alsSymbol]) {\n g[alsSymbol] = createCache();\n }\n\n return g[alsSymbol];\n};\n\nconst createCache = (): ALSCache => {\n const cache = {} as ALSCache;\n cache.promise = initializeALS(cache);\n return cache;\n};\n\nconst initializeALS = async (\n cache: ALSCache,\n): Promise<AsyncLocalStorageIsh> => {\n try {\n const { AsyncLocalStorage } = await import(\"node:async_hooks\");\n const als = new AsyncLocalStorage<AsyncContext>();\n cache.resolved = als;\n cache.isFallback = false;\n return als;\n } catch {\n const fallback: AsyncLocalStorageIsh = {\n getStore: () => undefined,\n run: (_, fn) => fn(),\n };\n cache.resolved = fallback;\n cache.isFallback = true;\n console.warn(\n \"node:async_hooks is not supported in this runtime. Async context is disabled.\",\n );\n return fallback;\n }\n};\n\n/**\n * Check if AsyncLocalStorage is unavailable and we're using the fallback.\n * Returns `undefined` if ALS hasn't been initialized yet.\n */\nexport const isALSFallback = (): boolean | undefined => {\n return getCache().isFallback;\n};\n\n/**\n * Retrieve the async context for the current execution.\n */\nexport const getAsyncCtx = async (): Promise<AsyncContext | undefined> => {\n return getAsyncLocalStorage().then((als) => als.getStore());\n};\n\n/**\n * Retrieve the async context for the current execution synchronously.\n * Returns undefined if ALS hasn't been initialized yet.\n */\nexport const getAsyncCtxSync = (): AsyncContext | undefined => {\n return getCache().resolved?.getStore();\n};\n\n/**\n * Get a singleton instance of `AsyncLocalStorage` used to store and retrieve\n * async context for the current execution.\n */\nexport const getAsyncLocalStorage = async (): Promise<AsyncLocalStorageIsh> => {\n return getCache().promise;\n};\n"],"mappings":";;;;;;AA4EA,MAAM,YAAY,OAAO,IAAI,cAAc;AAqB3C,MAAM,iBAA2B;CAC/B,MAAM,IAAI;AAEV,KAAI,CAAC,EAAE,WACL,GAAE,aAAa,aAAa;AAG9B,QAAO,EAAE;;AAGX,MAAM,oBAA8B;CAClC,MAAM,QAAQ,EAAE;AAChB,OAAM,UAAU,cAAc,MAAM;AACpC,QAAO;;AAGT,MAAM,gBAAgB,OACpB,UACkC;AAClC,KAAI;EACF,MAAM,EAAE,sBAAsB,MAAM,OAAO;EAC3C,MAAM,MAAM,IAAI,mBAAiC;AACjD,QAAM,WAAW;AACjB,QAAM,aAAa;AACnB,SAAO;SACD;EACN,MAAMA,WAAiC;GACrC,gBAAgB;GAChB,MAAM,GAAG,OAAO,IAAI;GACrB;AACD,QAAM,WAAW;AACjB,QAAM,aAAa;AACnB,UAAQ,KACN,gFACD;AACD,SAAO;;;;;;;AAQX,MAAa,sBAA2C;AACtD,QAAO,UAAU,CAAC;;;;;AAMpB,MAAa,cAAc,YAA+C;AACxE,QAAO,sBAAsB,CAAC,MAAM,QAAQ,IAAI,UAAU,CAAC;;;;;;AAO7D,MAAa,wBAAkD;AAC7D,QAAO,UAAU,CAAC,UAAU,UAAU;;;;;;AAOxC,MAAa,uBAAuB,YAA2C;AAC7E,QAAO,UAAU,CAAC"}
1
+ {"version":3,"file":"als.cjs","names":["fallback: AsyncLocalStorageIsh"],"sources":["../../../src/components/execution/als.ts"],"sourcesContent":["import type { Context, StepOptions } from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { Stream } from \"../StreamTools.ts\";\nimport type { IInngestExecution } from \"./InngestExecution.ts\";\n\n/**\n * Note - this structure can be used by other libraries, so cannot have breaking changes.\n */\nexport interface AsyncContext {\n /**\n * The Inngest App that is currently being used to execute the function.\n *\n * If this is defined, we are in the context of an Inngest function execution,\n * or a possible one.\n */\n app: Inngest.Like;\n\n /**\n * Details of the current function execution context. If this doesn't exist,\n * then we're not currently in a function execution context.\n */\n execution?: {\n /**\n * The execution instance that is currently running the function.\n */\n instance: IInngestExecution;\n\n /**\n * The `ctx` object that has been passed in to this function execution,\n * including values such as `step` and `event`.\n */\n ctx: Context.Any;\n\n /**\n * If present, this indicates we are currently executing a `step.run()` step's\n * callback. Useful to understand whether we are in the context of a step\n * execution or within the main function body.\n */\n executingStep?: StepOptions & { hashedId?: string };\n\n /**\n * If present, indicates the parallel mode that should be applied to steps\n * created within this context. Set by `group.parallel()`.\n */\n parallelMode?: \"race\";\n\n /**\n * The stream tools instance for this execution context. Used by the\n * `stream` singleton to push/pipe SSE data to the client.\n */\n stream?: Stream;\n\n /**\n * If present, indicates the variant callback is executing within an\n * experiment. Set by `group.experiment()`. Any `step.*()` call within\n * this context will include these fields in `OutgoingOp.opts`.\n */\n experimentContext?: {\n experimentStepID: string;\n experimentName: string;\n variant: string;\n };\n\n /**\n * A mutable tracker used to detect whether any step tool was invoked\n * during a variant callback. Set by `group.experiment()`, flipped by\n * `createTool` in `InngestStepTools.ts`.\n */\n experimentStepTracker?: { found: boolean };\n\n /**\n * If true, we are inside the `select()` callback of\n * `group.experiment()`. Any `step.*()` call here would create a\n * nested step, which is not allowed.\n */\n insideExperimentSelect?: boolean;\n };\n}\n\n/**\n * A local-only symbol used as a key in global state to store the async local\n * storage instance.\n */\nconst alsSymbol = Symbol.for(\"inngest:als\");\n\n/**\n * Cache structure that stores both the promise and resolved ALS instance.\n * This allows synchronous access after initialization.\n */\ntype ALSCache = {\n promise: Promise<AsyncLocalStorageIsh>;\n resolved?: AsyncLocalStorageIsh;\n isFallback?: boolean;\n};\n\n/**\n * A type that represents a partial, runtime-agnostic interface of\n * `AsyncLocalStorage`.\n */\ntype AsyncLocalStorageIsh = {\n getStore: () => AsyncContext | undefined;\n run: <R>(store: AsyncContext, fn: () => R) => R;\n};\n\nconst getCache = (): ALSCache => {\n const g = globalThis as Record<symbol, ALSCache | undefined>;\n\n if (!g[alsSymbol]) {\n g[alsSymbol] = createCache();\n }\n\n return g[alsSymbol];\n};\n\nconst createCache = (): ALSCache => {\n const cache = {} as ALSCache;\n cache.promise = initializeALS(cache);\n return cache;\n};\n\nconst initializeALS = async (\n cache: ALSCache,\n): Promise<AsyncLocalStorageIsh> => {\n try {\n const { AsyncLocalStorage } = await import(\"node:async_hooks\");\n const als = new AsyncLocalStorage<AsyncContext>();\n cache.resolved = als;\n cache.isFallback = false;\n return als;\n } catch {\n const fallback: AsyncLocalStorageIsh = {\n getStore: () => undefined,\n run: (_, fn) => fn(),\n };\n cache.resolved = fallback;\n cache.isFallback = true;\n console.warn(\n \"node:async_hooks is not supported in this runtime. Async context is disabled.\",\n );\n return fallback;\n }\n};\n\n/**\n * Check if AsyncLocalStorage is unavailable and we're using the fallback.\n * Returns `undefined` if ALS hasn't been initialized yet.\n */\nexport const isALSFallback = (): boolean | undefined => {\n return getCache().isFallback;\n};\n\n/**\n * Retrieve the async context for the current execution.\n */\nexport const getAsyncCtx = async (): Promise<AsyncContext | undefined> => {\n return getAsyncLocalStorage().then((als) => als.getStore());\n};\n\n/**\n * Retrieve the async context for the current execution synchronously.\n * Returns undefined if ALS hasn't been initialized yet.\n */\nexport const getAsyncCtxSync = (): AsyncContext | undefined => {\n return getCache().resolved?.getStore();\n};\n\n/**\n * Get a singleton instance of `AsyncLocalStorage` used to store and retrieve\n * async context for the current execution.\n */\nexport const getAsyncLocalStorage = async (): Promise<AsyncLocalStorageIsh> => {\n return getCache().promise;\n};\n"],"mappings":";;;;;;AAmFA,MAAM,YAAY,OAAO,IAAI,cAAc;AAqB3C,MAAM,iBAA2B;CAC/B,MAAM,IAAI;AAEV,KAAI,CAAC,EAAE,WACL,GAAE,aAAa,aAAa;AAG9B,QAAO,EAAE;;AAGX,MAAM,oBAA8B;CAClC,MAAM,QAAQ,EAAE;AAChB,OAAM,UAAU,cAAc,MAAM;AACpC,QAAO;;AAGT,MAAM,gBAAgB,OACpB,UACkC;AAClC,KAAI;EACF,MAAM,EAAE,sBAAsB,MAAM,OAAO;EAC3C,MAAM,MAAM,IAAI,mBAAiC;AACjD,QAAM,WAAW;AACjB,QAAM,aAAa;AACnB,SAAO;SACD;EACN,MAAMA,WAAiC;GACrC,gBAAgB;GAChB,MAAM,GAAG,OAAO,IAAI;GACrB;AACD,QAAM,WAAW;AACjB,QAAM,aAAa;AACnB,UAAQ,KACN,gFACD;AACD,SAAO;;;;;;;AAQX,MAAa,sBAA2C;AACtD,QAAO,UAAU,CAAC;;;;;AAMpB,MAAa,cAAc,YAA+C;AACxE,QAAO,sBAAsB,CAAC,MAAM,QAAQ,IAAI,UAAU,CAAC;;;;;;AAO7D,MAAa,wBAAkD;AAC7D,QAAO,UAAU,CAAC,UAAU,UAAU;;;;;;AAOxC,MAAa,uBAAuB,YAA2C;AAC7E,QAAO,UAAU,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { Stream } from "../StreamTools.cjs";
1
2
  import { IInngestExecution } from "./InngestExecution.cjs";
2
3
  import { Context, StepOptions } from "../../types.cjs";
3
4
  import { Inngest } from "../Inngest.cjs";
@@ -34,12 +35,19 @@ interface AsyncContext {
34
35
  * callback. Useful to understand whether we are in the context of a step
35
36
  * execution or within the main function body.
36
37
  */
37
- executingStep?: StepOptions;
38
+ executingStep?: StepOptions & {
39
+ hashedId?: string;
40
+ };
38
41
  /**
39
42
  * If present, indicates the parallel mode that should be applied to steps
40
43
  * created within this context. Set by `group.parallel()`.
41
44
  */
42
45
  parallelMode?: "race";
46
+ /**
47
+ * The stream tools instance for this execution context. Used by the
48
+ * `stream` singleton to push/pipe SSE data to the client.
49
+ */
50
+ stream?: Stream;
43
51
  /**
44
52
  * If present, indicates the variant callback is executing within an
45
53
  * experiment. Set by `group.experiment()`. Any `step.*()` call within
@@ -1 +1 @@
1
- {"version":3,"file":"als.d.cts","names":[],"sources":["../../../src/components/execution/als.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAOA;AAA6B,UAAZ,YAAA,CAAY;;;;;;AA4I7B;EAEC,GAAA,EAvIM,OAAA,CAAQ,IAuId;;;;;;;;;cA7Ha;;;;;SAML,OAAA,CAAQ;;;;;;oBAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8GP,mBAAwB,QAAQ"}
1
+ {"version":3,"file":"als.d.cts","names":[],"sources":["../../../src/components/execution/als.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAQA;AAA6B,UAAZ,YAAA,CAAY;;;;;;;EAkJhB,GAAA,EA3IN,OAAA,CAAQ,IA6Id;EAAA;;;;;;;;cAnIa;;;;;SAML,OAAA,CAAQ;;;;;;oBAOG;;;;;;;;;;;;aAYP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwGA,mBAAwB,QAAQ"}
@@ -1,3 +1,4 @@
1
+ import { Stream } from "../StreamTools.js";
1
2
  import { IInngestExecution } from "./InngestExecution.js";
2
3
  import { Context, StepOptions } from "../../types.js";
3
4
  import { Inngest } from "../Inngest.js";
@@ -34,12 +35,19 @@ interface AsyncContext {
34
35
  * callback. Useful to understand whether we are in the context of a step
35
36
  * execution or within the main function body.
36
37
  */
37
- executingStep?: StepOptions;
38
+ executingStep?: StepOptions & {
39
+ hashedId?: string;
40
+ };
38
41
  /**
39
42
  * If present, indicates the parallel mode that should be applied to steps
40
43
  * created within this context. Set by `group.parallel()`.
41
44
  */
42
45
  parallelMode?: "race";
46
+ /**
47
+ * The stream tools instance for this execution context. Used by the
48
+ * `stream` singleton to push/pipe SSE data to the client.
49
+ */
50
+ stream?: Stream;
43
51
  /**
44
52
  * If present, indicates the variant callback is executing within an
45
53
  * experiment. Set by `group.experiment()`. Any `step.*()` call within
@@ -1 +1 @@
1
- {"version":3,"file":"als.d.ts","names":[],"sources":["../../../src/components/execution/als.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAOA;AAA6B,UAAZ,YAAA,CAAY;;;;;;AA4I7B;EAEC,GAAA,EAvIM,OAAA,CAAQ,IAuId;;;;;;;;;cA7Ha;;;;;SAML,OAAA,CAAQ;;;;;;oBAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8GP,mBAAwB,QAAQ"}
1
+ {"version":3,"file":"als.d.ts","names":[],"sources":["../../../src/components/execution/als.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAQA;AAA6B,UAAZ,YAAA,CAAY;;;;;;;EAkJhB,GAAA,EA3IN,OAAA,CAAQ,IA6Id;EAAA;;;;;;;;cAnIa;;;;;SAML,OAAA,CAAQ;;;;;;oBAOG;;;;;;;;;;;;aAYP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwGA,mBAAwB,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"als.js","names":["fallback: AsyncLocalStorageIsh"],"sources":["../../../src/components/execution/als.ts"],"sourcesContent":["import type { Context, StepOptions } from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { IInngestExecution } from \"./InngestExecution.ts\";\n\n/**\n * Note - this structure can be used by other libraries, so cannot have breaking changes.\n */\nexport interface AsyncContext {\n /**\n * The Inngest App that is currently being used to execute the function.\n *\n * If this is defined, we are in the context of an Inngest function execution,\n * or a possible one.\n */\n app: Inngest.Like;\n\n /**\n * Details of the current function execution context. If this doesn't exist,\n * then we're not currently in a function execution context.\n */\n execution?: {\n /**\n * The execution instance that is currently running the function.\n */\n instance: IInngestExecution;\n\n /**\n * The `ctx` object that has been passed in to this function execution,\n * including values such as `step` and `event`.\n */\n ctx: Context.Any;\n\n /**\n * If present, this indicates we are currently executing a `step.run()` step's\n * callback. Useful to understand whether we are in the context of a step\n * execution or within the main function body.\n */\n executingStep?: StepOptions;\n\n /**\n * If present, indicates the parallel mode that should be applied to steps\n * created within this context. Set by `group.parallel()`.\n */\n parallelMode?: \"race\";\n\n /**\n * If present, indicates the variant callback is executing within an\n * experiment. Set by `group.experiment()`. Any `step.*()` call within\n * this context will include these fields in `OutgoingOp.opts`.\n */\n experimentContext?: {\n experimentStepID: string;\n experimentName: string;\n variant: string;\n };\n\n /**\n * A mutable tracker used to detect whether any step tool was invoked\n * during a variant callback. Set by `group.experiment()`, flipped by\n * `createTool` in `InngestStepTools.ts`.\n */\n experimentStepTracker?: { found: boolean };\n\n /**\n * If true, we are inside the `select()` callback of\n * `group.experiment()`. Any `step.*()` call here would create a\n * nested step, which is not allowed.\n */\n insideExperimentSelect?: boolean;\n };\n}\n\n/**\n * A local-only symbol used as a key in global state to store the async local\n * storage instance.\n */\nconst alsSymbol = Symbol.for(\"inngest:als\");\n\n/**\n * Cache structure that stores both the promise and resolved ALS instance.\n * This allows synchronous access after initialization.\n */\ntype ALSCache = {\n promise: Promise<AsyncLocalStorageIsh>;\n resolved?: AsyncLocalStorageIsh;\n isFallback?: boolean;\n};\n\n/**\n * A type that represents a partial, runtime-agnostic interface of\n * `AsyncLocalStorage`.\n */\ntype AsyncLocalStorageIsh = {\n getStore: () => AsyncContext | undefined;\n run: <R>(store: AsyncContext, fn: () => R) => R;\n};\n\nconst getCache = (): ALSCache => {\n const g = globalThis as Record<symbol, ALSCache | undefined>;\n\n if (!g[alsSymbol]) {\n g[alsSymbol] = createCache();\n }\n\n return g[alsSymbol];\n};\n\nconst createCache = (): ALSCache => {\n const cache = {} as ALSCache;\n cache.promise = initializeALS(cache);\n return cache;\n};\n\nconst initializeALS = async (\n cache: ALSCache,\n): Promise<AsyncLocalStorageIsh> => {\n try {\n const { AsyncLocalStorage } = await import(\"node:async_hooks\");\n const als = new AsyncLocalStorage<AsyncContext>();\n cache.resolved = als;\n cache.isFallback = false;\n return als;\n } catch {\n const fallback: AsyncLocalStorageIsh = {\n getStore: () => undefined,\n run: (_, fn) => fn(),\n };\n cache.resolved = fallback;\n cache.isFallback = true;\n console.warn(\n \"node:async_hooks is not supported in this runtime. Async context is disabled.\",\n );\n return fallback;\n }\n};\n\n/**\n * Check if AsyncLocalStorage is unavailable and we're using the fallback.\n * Returns `undefined` if ALS hasn't been initialized yet.\n */\nexport const isALSFallback = (): boolean | undefined => {\n return getCache().isFallback;\n};\n\n/**\n * Retrieve the async context for the current execution.\n */\nexport const getAsyncCtx = async (): Promise<AsyncContext | undefined> => {\n return getAsyncLocalStorage().then((als) => als.getStore());\n};\n\n/**\n * Retrieve the async context for the current execution synchronously.\n * Returns undefined if ALS hasn't been initialized yet.\n */\nexport const getAsyncCtxSync = (): AsyncContext | undefined => {\n return getCache().resolved?.getStore();\n};\n\n/**\n * Get a singleton instance of `AsyncLocalStorage` used to store and retrieve\n * async context for the current execution.\n */\nexport const getAsyncLocalStorage = async (): Promise<AsyncLocalStorageIsh> => {\n return getCache().promise;\n};\n"],"mappings":";;;;;AA4EA,MAAM,YAAY,OAAO,IAAI,cAAc;AAqB3C,MAAM,iBAA2B;CAC/B,MAAM,IAAI;AAEV,KAAI,CAAC,EAAE,WACL,GAAE,aAAa,aAAa;AAG9B,QAAO,EAAE;;AAGX,MAAM,oBAA8B;CAClC,MAAM,QAAQ,EAAE;AAChB,OAAM,UAAU,cAAc,MAAM;AACpC,QAAO;;AAGT,MAAM,gBAAgB,OACpB,UACkC;AAClC,KAAI;EACF,MAAM,EAAE,sBAAsB,MAAM,OAAO;EAC3C,MAAM,MAAM,IAAI,mBAAiC;AACjD,QAAM,WAAW;AACjB,QAAM,aAAa;AACnB,SAAO;SACD;EACN,MAAMA,WAAiC;GACrC,gBAAgB;GAChB,MAAM,GAAG,OAAO,IAAI;GACrB;AACD,QAAM,WAAW;AACjB,QAAM,aAAa;AACnB,UAAQ,KACN,gFACD;AACD,SAAO;;;;;;;AAQX,MAAa,sBAA2C;AACtD,QAAO,UAAU,CAAC;;;;;AAMpB,MAAa,cAAc,YAA+C;AACxE,QAAO,sBAAsB,CAAC,MAAM,QAAQ,IAAI,UAAU,CAAC;;;;;;AAO7D,MAAa,wBAAkD;AAC7D,QAAO,UAAU,CAAC,UAAU,UAAU;;;;;;AAOxC,MAAa,uBAAuB,YAA2C;AAC7E,QAAO,UAAU,CAAC"}
1
+ {"version":3,"file":"als.js","names":["fallback: AsyncLocalStorageIsh"],"sources":["../../../src/components/execution/als.ts"],"sourcesContent":["import type { Context, StepOptions } from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { Stream } from \"../StreamTools.ts\";\nimport type { IInngestExecution } from \"./InngestExecution.ts\";\n\n/**\n * Note - this structure can be used by other libraries, so cannot have breaking changes.\n */\nexport interface AsyncContext {\n /**\n * The Inngest App that is currently being used to execute the function.\n *\n * If this is defined, we are in the context of an Inngest function execution,\n * or a possible one.\n */\n app: Inngest.Like;\n\n /**\n * Details of the current function execution context. If this doesn't exist,\n * then we're not currently in a function execution context.\n */\n execution?: {\n /**\n * The execution instance that is currently running the function.\n */\n instance: IInngestExecution;\n\n /**\n * The `ctx` object that has been passed in to this function execution,\n * including values such as `step` and `event`.\n */\n ctx: Context.Any;\n\n /**\n * If present, this indicates we are currently executing a `step.run()` step's\n * callback. Useful to understand whether we are in the context of a step\n * execution or within the main function body.\n */\n executingStep?: StepOptions & { hashedId?: string };\n\n /**\n * If present, indicates the parallel mode that should be applied to steps\n * created within this context. Set by `group.parallel()`.\n */\n parallelMode?: \"race\";\n\n /**\n * The stream tools instance for this execution context. Used by the\n * `stream` singleton to push/pipe SSE data to the client.\n */\n stream?: Stream;\n\n /**\n * If present, indicates the variant callback is executing within an\n * experiment. Set by `group.experiment()`. Any `step.*()` call within\n * this context will include these fields in `OutgoingOp.opts`.\n */\n experimentContext?: {\n experimentStepID: string;\n experimentName: string;\n variant: string;\n };\n\n /**\n * A mutable tracker used to detect whether any step tool was invoked\n * during a variant callback. Set by `group.experiment()`, flipped by\n * `createTool` in `InngestStepTools.ts`.\n */\n experimentStepTracker?: { found: boolean };\n\n /**\n * If true, we are inside the `select()` callback of\n * `group.experiment()`. Any `step.*()` call here would create a\n * nested step, which is not allowed.\n */\n insideExperimentSelect?: boolean;\n };\n}\n\n/**\n * A local-only symbol used as a key in global state to store the async local\n * storage instance.\n */\nconst alsSymbol = Symbol.for(\"inngest:als\");\n\n/**\n * Cache structure that stores both the promise and resolved ALS instance.\n * This allows synchronous access after initialization.\n */\ntype ALSCache = {\n promise: Promise<AsyncLocalStorageIsh>;\n resolved?: AsyncLocalStorageIsh;\n isFallback?: boolean;\n};\n\n/**\n * A type that represents a partial, runtime-agnostic interface of\n * `AsyncLocalStorage`.\n */\ntype AsyncLocalStorageIsh = {\n getStore: () => AsyncContext | undefined;\n run: <R>(store: AsyncContext, fn: () => R) => R;\n};\n\nconst getCache = (): ALSCache => {\n const g = globalThis as Record<symbol, ALSCache | undefined>;\n\n if (!g[alsSymbol]) {\n g[alsSymbol] = createCache();\n }\n\n return g[alsSymbol];\n};\n\nconst createCache = (): ALSCache => {\n const cache = {} as ALSCache;\n cache.promise = initializeALS(cache);\n return cache;\n};\n\nconst initializeALS = async (\n cache: ALSCache,\n): Promise<AsyncLocalStorageIsh> => {\n try {\n const { AsyncLocalStorage } = await import(\"node:async_hooks\");\n const als = new AsyncLocalStorage<AsyncContext>();\n cache.resolved = als;\n cache.isFallback = false;\n return als;\n } catch {\n const fallback: AsyncLocalStorageIsh = {\n getStore: () => undefined,\n run: (_, fn) => fn(),\n };\n cache.resolved = fallback;\n cache.isFallback = true;\n console.warn(\n \"node:async_hooks is not supported in this runtime. Async context is disabled.\",\n );\n return fallback;\n }\n};\n\n/**\n * Check if AsyncLocalStorage is unavailable and we're using the fallback.\n * Returns `undefined` if ALS hasn't been initialized yet.\n */\nexport const isALSFallback = (): boolean | undefined => {\n return getCache().isFallback;\n};\n\n/**\n * Retrieve the async context for the current execution.\n */\nexport const getAsyncCtx = async (): Promise<AsyncContext | undefined> => {\n return getAsyncLocalStorage().then((als) => als.getStore());\n};\n\n/**\n * Retrieve the async context for the current execution synchronously.\n * Returns undefined if ALS hasn't been initialized yet.\n */\nexport const getAsyncCtxSync = (): AsyncContext | undefined => {\n return getCache().resolved?.getStore();\n};\n\n/**\n * Get a singleton instance of `AsyncLocalStorage` used to store and retrieve\n * async context for the current execution.\n */\nexport const getAsyncLocalStorage = async (): Promise<AsyncLocalStorageIsh> => {\n return getCache().promise;\n};\n"],"mappings":";;;;;AAmFA,MAAM,YAAY,OAAO,IAAI,cAAc;AAqB3C,MAAM,iBAA2B;CAC/B,MAAM,IAAI;AAEV,KAAI,CAAC,EAAE,WACL,GAAE,aAAa,aAAa;AAG9B,QAAO,EAAE;;AAGX,MAAM,oBAA8B;CAClC,MAAM,QAAQ,EAAE;AAChB,OAAM,UAAU,cAAc,MAAM;AACpC,QAAO;;AAGT,MAAM,gBAAgB,OACpB,UACkC;AAClC,KAAI;EACF,MAAM,EAAE,sBAAsB,MAAM,OAAO;EAC3C,MAAM,MAAM,IAAI,mBAAiC;AACjD,QAAM,WAAW;AACjB,QAAM,aAAa;AACnB,SAAO;SACD;EACN,MAAMA,WAAiC;GACrC,gBAAgB;GAChB,MAAM,GAAG,OAAO,IAAI;GACrB;AACD,QAAM,WAAW;AACjB,QAAM,aAAa;AACnB,UAAQ,KACN,gFACD;AACD,SAAO;;;;;;;AAQX,MAAa,sBAA2C;AACtD,QAAO,UAAU,CAAC;;;;;AAMpB,MAAa,cAAc,YAA+C;AACxE,QAAO,sBAAsB,CAAC,MAAM,QAAQ,IAAI,UAAU,CAAC;;;;;;AAO7D,MAAa,wBAAkD;AAC7D,QAAO,UAAU,CAAC,UAAU,UAAU;;;;;;AAOxC,MAAa,uBAAuB,YAA2C;AAC7E,QAAO,UAAU,CAAC"}