inngest 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/api/schema.d.cts +2 -2
  3. package/api/schema.d.cts.map +1 -1
  4. package/api/schema.d.ts +2 -2
  5. package/api/schema.d.ts.map +1 -1
  6. package/components/DeferredFunction.cjs +66 -0
  7. package/components/DeferredFunction.cjs.map +1 -0
  8. package/components/DeferredFunction.d.cts +99 -0
  9. package/components/DeferredFunction.d.cts.map +1 -0
  10. package/components/DeferredFunction.d.ts +99 -0
  11. package/components/DeferredFunction.d.ts.map +1 -0
  12. package/components/DeferredFunction.js +65 -0
  13. package/components/DeferredFunction.js.map +1 -0
  14. package/components/Inngest.cjs +5 -2
  15. package/components/Inngest.cjs.map +1 -1
  16. package/components/Inngest.d.cts +4 -3
  17. package/components/Inngest.d.cts.map +1 -1
  18. package/components/Inngest.d.ts +4 -3
  19. package/components/Inngest.d.ts.map +1 -1
  20. package/components/Inngest.js +5 -2
  21. package/components/Inngest.js.map +1 -1
  22. package/components/InngestCommHandler.cjs +28 -23
  23. package/components/InngestCommHandler.cjs.map +1 -1
  24. package/components/InngestCommHandler.d.cts +9 -4
  25. package/components/InngestCommHandler.d.cts.map +1 -1
  26. package/components/InngestCommHandler.d.ts +9 -4
  27. package/components/InngestCommHandler.d.ts.map +1 -1
  28. package/components/InngestCommHandler.js +28 -23
  29. package/components/InngestCommHandler.js.map +1 -1
  30. package/components/InngestFunction.cjs +27 -19
  31. package/components/InngestFunction.cjs.map +1 -1
  32. package/components/InngestFunction.d.cts +6 -1
  33. package/components/InngestFunction.d.cts.map +1 -1
  34. package/components/InngestFunction.d.ts +6 -1
  35. package/components/InngestFunction.d.ts.map +1 -1
  36. package/components/InngestFunction.js +27 -19
  37. package/components/InngestFunction.js.map +1 -1
  38. package/components/InngestGroupTools.cjs +1 -1
  39. package/components/InngestGroupTools.cjs.map +1 -1
  40. package/components/InngestGroupTools.js +1 -1
  41. package/components/InngestGroupTools.js.map +1 -1
  42. package/components/connect/config.cjs +2 -0
  43. package/components/connect/config.cjs.map +1 -1
  44. package/components/connect/config.js +2 -0
  45. package/components/connect/config.js.map +1 -1
  46. package/components/execution/InngestExecution.cjs.map +1 -1
  47. package/components/execution/InngestExecution.d.cts +19 -2
  48. package/components/execution/InngestExecution.d.cts.map +1 -1
  49. package/components/execution/InngestExecution.d.ts +19 -2
  50. package/components/execution/InngestExecution.d.ts.map +1 -1
  51. package/components/execution/InngestExecution.js.map +1 -1
  52. package/components/execution/engine.cjs +232 -27
  53. package/components/execution/engine.cjs.map +1 -1
  54. package/components/execution/engine.d.cts +14 -0
  55. package/components/execution/engine.d.cts.map +1 -1
  56. package/components/execution/engine.d.ts +14 -0
  57. package/components/execution/engine.d.ts.map +1 -1
  58. package/components/execution/engine.js +232 -27
  59. package/components/execution/engine.js.map +1 -1
  60. package/components/execution/lazyOps.cjs +64 -0
  61. package/components/execution/lazyOps.cjs.map +1 -0
  62. package/components/execution/lazyOps.d.cts +42 -0
  63. package/components/execution/lazyOps.d.cts.map +1 -0
  64. package/components/execution/lazyOps.d.ts +42 -0
  65. package/components/execution/lazyOps.d.ts.map +1 -0
  66. package/components/execution/lazyOps.js +63 -0
  67. package/components/execution/lazyOps.js.map +1 -0
  68. package/components/execution/otel/middleware.d.cts +6 -3
  69. package/components/execution/otel/middleware.d.cts.map +1 -1
  70. package/components/execution/otel/middleware.d.ts +6 -3
  71. package/components/execution/otel/middleware.d.ts.map +1 -1
  72. package/components/middleware/middleware.cjs.map +1 -1
  73. package/components/middleware/middleware.d.cts +1 -1
  74. package/components/middleware/middleware.d.cts.map +1 -1
  75. package/components/middleware/middleware.d.ts +1 -1
  76. package/components/middleware/middleware.d.ts.map +1 -1
  77. package/components/middleware/middleware.js.map +1 -1
  78. package/components/middleware/utils.cjs +1 -0
  79. package/components/middleware/utils.cjs.map +1 -1
  80. package/components/middleware/utils.js +1 -0
  81. package/components/middleware/utils.js.map +1 -1
  82. package/components/realtime/types.d.cts +4 -4
  83. package/components/realtime/types.d.cts.map +1 -1
  84. package/components/realtime/types.d.ts +4 -4
  85. package/components/realtime/types.d.ts.map +1 -1
  86. package/components/triggers/typeHelpers.cjs.map +1 -1
  87. package/components/triggers/typeHelpers.d.cts +11 -0
  88. package/components/triggers/typeHelpers.d.cts.map +1 -1
  89. package/components/triggers/typeHelpers.d.ts +11 -0
  90. package/components/triggers/typeHelpers.d.ts.map +1 -1
  91. package/components/triggers/typeHelpers.js.map +1 -1
  92. package/experimental.cjs +3 -0
  93. package/experimental.d.cts +2 -1
  94. package/experimental.d.ts +2 -1
  95. package/experimental.js +2 -1
  96. package/helpers/consts.cjs +6 -0
  97. package/helpers/consts.cjs.map +1 -1
  98. package/helpers/consts.d.cts +6 -0
  99. package/helpers/consts.d.cts.map +1 -1
  100. package/helpers/consts.d.ts +6 -0
  101. package/helpers/consts.d.ts.map +1 -1
  102. package/helpers/consts.js +6 -0
  103. package/helpers/consts.js.map +1 -1
  104. package/helpers/functions.cjs +1 -0
  105. package/helpers/functions.cjs.map +1 -1
  106. package/helpers/functions.js +1 -0
  107. package/helpers/functions.js.map +1 -1
  108. package/helpers/marker.cjs +21 -0
  109. package/helpers/marker.cjs.map +1 -0
  110. package/helpers/marker.d.cts +12 -0
  111. package/helpers/marker.d.cts.map +1 -0
  112. package/helpers/marker.d.ts +12 -0
  113. package/helpers/marker.d.ts.map +1 -0
  114. package/helpers/marker.js +19 -0
  115. package/helpers/marker.js.map +1 -0
  116. package/package.json +2 -2
  117. package/proto/src/components/connect/protobuf/connect.cjs +11 -2
  118. package/proto/src/components/connect/protobuf/connect.cjs.map +1 -1
  119. package/proto/src/components/connect/protobuf/connect.js +11 -2
  120. package/proto/src/components/connect/protobuf/connect.js.map +1 -1
  121. package/types.cjs +2 -0
  122. package/types.cjs.map +1 -1
  123. package/types.d.cts +52 -18
  124. package/types.d.cts.map +1 -1
  125. package/types.d.ts +52 -18
  126. package/types.d.ts.map +1 -1
  127. package/types.js +2 -0
  128. package/types.js.map +1 -1
  129. package/version.cjs +1 -1
  130. package/version.cjs.map +1 -1
  131. package/version.d.cts +1 -1
  132. package/version.d.ts +1 -1
  133. package/version.js +1 -1
  134. package/version.js.map +1 -1
@@ -0,0 +1,64 @@
1
+ const require_types = require('../../types.cjs');
2
+
3
+ //#region src/components/execution/lazyOps.ts
4
+ /**
5
+ * Buffer for opcode-only sync ops (e.g. `DeferAdd`). These ops need to be
6
+ * buffered until the next outbound wire message (e.g. checkpointing a
7
+ * `step.run`).
8
+ *
9
+ * The engine owns shipping. This helper owns the buffer.
10
+ */
11
+ var LazyOps = class {
12
+ buffer = [];
13
+ pushedIds = /* @__PURE__ */ new Set();
14
+ /**
15
+ * Number of ops waiting to ship.
16
+ */
17
+ get length() {
18
+ return this.buffer.length;
19
+ }
20
+ /**
21
+ * Whether an op with this hashed id has been pushed in this execution
22
+ * (whether or not it has since been drained).
23
+ */
24
+ hasId(id) {
25
+ return this.pushedIds.has(id);
26
+ }
27
+ /**
28
+ * Take ownership of buffered ops and clear the buffer. Callers ship them on
29
+ * whichever wire message comes next.
30
+ */
31
+ drain() {
32
+ if (this.buffer.length === 0) return [];
33
+ const ops = this.buffer;
34
+ this.buffer = [];
35
+ return ops;
36
+ }
37
+ /**
38
+ * Buffer an op for later shipment.
39
+ */
40
+ push(op) {
41
+ this.buffer.push(op);
42
+ this.pushedIds.add(op.id);
43
+ }
44
+ /**
45
+ * Record that an id has been observed in this execution without buffering
46
+ * an op for it. Used to consume a `priorDefers` replay match so that
47
+ * subsequent encounters of the same id surface as duplicates.
48
+ */
49
+ markSeen(id) {
50
+ this.pushedIds.add(id);
51
+ }
52
+ };
53
+ /**
54
+ * True when a step being registered is an opcode-only sync op (no local
55
+ * handler, sync mode).
56
+ */
57
+ function isLazyOp(opts, opId) {
58
+ return !opts?.fn && opId.mode === require_types.StepMode.Sync;
59
+ }
60
+
61
+ //#endregion
62
+ exports.LazyOps = LazyOps;
63
+ exports.isLazyOp = isLazyOp;
64
+ //# sourceMappingURL=lazyOps.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazyOps.cjs","names":["StepMode"],"sources":["../../../src/components/execution/lazyOps.ts"],"sourcesContent":["import { type OutgoingOp, StepMode } from \"../../types.ts\";\nimport type { MatchOpFn, StepToolOptions } from \"../InngestStepTools.ts\";\n\n/**\n * Buffer for opcode-only sync ops (e.g. `DeferAdd`). These ops need to be\n * buffered until the next outbound wire message (e.g. checkpointing a\n * `step.run`).\n *\n * The engine owns shipping. This helper owns the buffer.\n */\nexport class LazyOps {\n private buffer: OutgoingOp[] = [];\n\n // Tracks every id pushed during this execution, including those already\n // drained. `buffer` alone can't answer \"have we seen this id?\" once a\n // checkpoint ships its contents, so duplicates that straddle a drain would\n // otherwise slip through.\n private pushedIds: Set<string> = new Set();\n\n /**\n * Number of ops waiting to ship.\n */\n get length(): number {\n return this.buffer.length;\n }\n\n /**\n * Whether an op with this hashed id has been pushed in this execution\n * (whether or not it has since been drained).\n */\n hasId(id: string): boolean {\n return this.pushedIds.has(id);\n }\n\n /**\n * Take ownership of buffered ops and clear the buffer. Callers ship them on\n * whichever wire message comes next.\n */\n drain(): OutgoingOp[] {\n if (this.buffer.length === 0) {\n return [];\n }\n const ops = this.buffer;\n this.buffer = [];\n return ops;\n }\n\n /**\n * Buffer an op for later shipment.\n */\n push(op: OutgoingOp): void {\n this.buffer.push(op);\n this.pushedIds.add(op.id);\n }\n\n /**\n * Record that an id has been observed in this execution without buffering\n * an op for it. Used to consume a `priorDefers` replay match so that\n * subsequent encounters of the same id surface as duplicates.\n */\n markSeen(id: string): void {\n this.pushedIds.add(id);\n }\n}\n\n/**\n * True when a step being registered is an opcode-only sync op (no local\n * handler, sync mode).\n */\nexport function isLazyOp(\n opts: StepToolOptions | undefined,\n opId: ReturnType<MatchOpFn>,\n): boolean {\n return !opts?.fn && opId.mode === StepMode.Sync;\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,UAAb,MAAqB;CACnB,AAAQ,SAAuB,EAAE;CAMjC,AAAQ,4BAAyB,IAAI,KAAK;;;;CAK1C,IAAI,SAAiB;AACnB,SAAO,KAAK,OAAO;;;;;;CAOrB,MAAM,IAAqB;AACzB,SAAO,KAAK,UAAU,IAAI,GAAG;;;;;;CAO/B,QAAsB;AACpB,MAAI,KAAK,OAAO,WAAW,EACzB,QAAO,EAAE;EAEX,MAAM,MAAM,KAAK;AACjB,OAAK,SAAS,EAAE;AAChB,SAAO;;;;;CAMT,KAAK,IAAsB;AACzB,OAAK,OAAO,KAAK,GAAG;AACpB,OAAK,UAAU,IAAI,GAAG,GAAG;;;;;;;CAQ3B,SAAS,IAAkB;AACzB,OAAK,UAAU,IAAI,GAAG;;;;;;;AAQ1B,SAAgB,SACd,MACA,MACS;AACT,QAAO,CAAC,MAAM,MAAM,KAAK,SAASA,uBAAS"}
@@ -0,0 +1,42 @@
1
+ import { OutgoingOp } from "../../types.cjs";
2
+
3
+ //#region src/components/execution/lazyOps.d.ts
4
+
5
+ /**
6
+ * Buffer for opcode-only sync ops (e.g. `DeferAdd`). These ops need to be
7
+ * buffered until the next outbound wire message (e.g. checkpointing a
8
+ * `step.run`).
9
+ *
10
+ * The engine owns shipping. This helper owns the buffer.
11
+ */
12
+ declare class LazyOps {
13
+ private buffer;
14
+ private pushedIds;
15
+ /**
16
+ * Number of ops waiting to ship.
17
+ */
18
+ get length(): number;
19
+ /**
20
+ * Whether an op with this hashed id has been pushed in this execution
21
+ * (whether or not it has since been drained).
22
+ */
23
+ hasId(id: string): boolean;
24
+ /**
25
+ * Take ownership of buffered ops and clear the buffer. Callers ship them on
26
+ * whichever wire message comes next.
27
+ */
28
+ drain(): OutgoingOp[];
29
+ /**
30
+ * Buffer an op for later shipment.
31
+ */
32
+ push(op: OutgoingOp): void;
33
+ /**
34
+ * Record that an id has been observed in this execution without buffering
35
+ * an op for it. Used to consume a `priorDefers` replay match so that
36
+ * subsequent encounters of the same id surface as duplicates.
37
+ */
38
+ markSeen(id: string): void;
39
+ }
40
+ //#endregion
41
+ export { LazyOps };
42
+ //# sourceMappingURL=lazyOps.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazyOps.d.cts","names":[],"sources":["../../../src/components/execution/lazyOps.ts"],"sourcesContent":[],"mappings":";;;;;AAUA;;;;;;cAAa,OAAA;;;;;;;;;;;;;;;;WA4BF;;;;WAYA"}
@@ -0,0 +1,42 @@
1
+ import { OutgoingOp } from "../../types.js";
2
+
3
+ //#region src/components/execution/lazyOps.d.ts
4
+
5
+ /**
6
+ * Buffer for opcode-only sync ops (e.g. `DeferAdd`). These ops need to be
7
+ * buffered until the next outbound wire message (e.g. checkpointing a
8
+ * `step.run`).
9
+ *
10
+ * The engine owns shipping. This helper owns the buffer.
11
+ */
12
+ declare class LazyOps {
13
+ private buffer;
14
+ private pushedIds;
15
+ /**
16
+ * Number of ops waiting to ship.
17
+ */
18
+ get length(): number;
19
+ /**
20
+ * Whether an op with this hashed id has been pushed in this execution
21
+ * (whether or not it has since been drained).
22
+ */
23
+ hasId(id: string): boolean;
24
+ /**
25
+ * Take ownership of buffered ops and clear the buffer. Callers ship them on
26
+ * whichever wire message comes next.
27
+ */
28
+ drain(): OutgoingOp[];
29
+ /**
30
+ * Buffer an op for later shipment.
31
+ */
32
+ push(op: OutgoingOp): void;
33
+ /**
34
+ * Record that an id has been observed in this execution without buffering
35
+ * an op for it. Used to consume a `priorDefers` replay match so that
36
+ * subsequent encounters of the same id surface as duplicates.
37
+ */
38
+ markSeen(id: string): void;
39
+ }
40
+ //#endregion
41
+ export { LazyOps };
42
+ //# sourceMappingURL=lazyOps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazyOps.d.ts","names":[],"sources":["../../../src/components/execution/lazyOps.ts"],"sourcesContent":[],"mappings":";;;;;AAUA;;;;;;cAAa,OAAA;;;;;;;;;;;;;;;;WA4BF;;;;WAYA"}
@@ -0,0 +1,63 @@
1
+ import { StepMode } from "../../types.js";
2
+
3
+ //#region src/components/execution/lazyOps.ts
4
+ /**
5
+ * Buffer for opcode-only sync ops (e.g. `DeferAdd`). These ops need to be
6
+ * buffered until the next outbound wire message (e.g. checkpointing a
7
+ * `step.run`).
8
+ *
9
+ * The engine owns shipping. This helper owns the buffer.
10
+ */
11
+ var LazyOps = class {
12
+ buffer = [];
13
+ pushedIds = /* @__PURE__ */ new Set();
14
+ /**
15
+ * Number of ops waiting to ship.
16
+ */
17
+ get length() {
18
+ return this.buffer.length;
19
+ }
20
+ /**
21
+ * Whether an op with this hashed id has been pushed in this execution
22
+ * (whether or not it has since been drained).
23
+ */
24
+ hasId(id) {
25
+ return this.pushedIds.has(id);
26
+ }
27
+ /**
28
+ * Take ownership of buffered ops and clear the buffer. Callers ship them on
29
+ * whichever wire message comes next.
30
+ */
31
+ drain() {
32
+ if (this.buffer.length === 0) return [];
33
+ const ops = this.buffer;
34
+ this.buffer = [];
35
+ return ops;
36
+ }
37
+ /**
38
+ * Buffer an op for later shipment.
39
+ */
40
+ push(op) {
41
+ this.buffer.push(op);
42
+ this.pushedIds.add(op.id);
43
+ }
44
+ /**
45
+ * Record that an id has been observed in this execution without buffering
46
+ * an op for it. Used to consume a `priorDefers` replay match so that
47
+ * subsequent encounters of the same id surface as duplicates.
48
+ */
49
+ markSeen(id) {
50
+ this.pushedIds.add(id);
51
+ }
52
+ };
53
+ /**
54
+ * True when a step being registered is an opcode-only sync op (no local
55
+ * handler, sync mode).
56
+ */
57
+ function isLazyOp(opts, opId) {
58
+ return !opts?.fn && opId.mode === StepMode.Sync;
59
+ }
60
+
61
+ //#endregion
62
+ export { LazyOps, isLazyOp };
63
+ //# sourceMappingURL=lazyOps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazyOps.js","names":[],"sources":["../../../src/components/execution/lazyOps.ts"],"sourcesContent":["import { type OutgoingOp, StepMode } from \"../../types.ts\";\nimport type { MatchOpFn, StepToolOptions } from \"../InngestStepTools.ts\";\n\n/**\n * Buffer for opcode-only sync ops (e.g. `DeferAdd`). These ops need to be\n * buffered until the next outbound wire message (e.g. checkpointing a\n * `step.run`).\n *\n * The engine owns shipping. This helper owns the buffer.\n */\nexport class LazyOps {\n private buffer: OutgoingOp[] = [];\n\n // Tracks every id pushed during this execution, including those already\n // drained. `buffer` alone can't answer \"have we seen this id?\" once a\n // checkpoint ships its contents, so duplicates that straddle a drain would\n // otherwise slip through.\n private pushedIds: Set<string> = new Set();\n\n /**\n * Number of ops waiting to ship.\n */\n get length(): number {\n return this.buffer.length;\n }\n\n /**\n * Whether an op with this hashed id has been pushed in this execution\n * (whether or not it has since been drained).\n */\n hasId(id: string): boolean {\n return this.pushedIds.has(id);\n }\n\n /**\n * Take ownership of buffered ops and clear the buffer. Callers ship them on\n * whichever wire message comes next.\n */\n drain(): OutgoingOp[] {\n if (this.buffer.length === 0) {\n return [];\n }\n const ops = this.buffer;\n this.buffer = [];\n return ops;\n }\n\n /**\n * Buffer an op for later shipment.\n */\n push(op: OutgoingOp): void {\n this.buffer.push(op);\n this.pushedIds.add(op.id);\n }\n\n /**\n * Record that an id has been observed in this execution without buffering\n * an op for it. Used to consume a `priorDefers` replay match so that\n * subsequent encounters of the same id surface as duplicates.\n */\n markSeen(id: string): void {\n this.pushedIds.add(id);\n }\n}\n\n/**\n * True when a step being registered is an opcode-only sync op (no local\n * handler, sync mode).\n */\nexport function isLazyOp(\n opts: StepToolOptions | undefined,\n opId: ReturnType<MatchOpFn>,\n): boolean {\n return !opts?.fn && opId.mode === StepMode.Sync;\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,UAAb,MAAqB;CACnB,AAAQ,SAAuB,EAAE;CAMjC,AAAQ,4BAAyB,IAAI,KAAK;;;;CAK1C,IAAI,SAAiB;AACnB,SAAO,KAAK,OAAO;;;;;;CAOrB,MAAM,IAAqB;AACzB,SAAO,KAAK,UAAU,IAAI,GAAG;;;;;;CAO/B,QAAsB;AACpB,MAAI,KAAK,OAAO,WAAW,EACzB,QAAO,EAAE;EAEX,MAAM,MAAM,KAAK;AACjB,OAAK,SAAS,EAAE;AAChB,SAAO;;;;;CAMT,KAAK,IAAsB;AACzB,OAAK,OAAO,KAAK,GAAG;AACpB,OAAK,UAAU,IAAI,GAAG,GAAG;;;;;;;CAQ3B,SAAS,IAAkB;AACzB,OAAK,UAAU,IAAI,GAAG;;;;;;;AAQ1B,SAAgB,SACd,MACA,MACS;AACT,QAAO,CAAC,MAAM,MAAM,KAAK,SAAS,SAAS"}
@@ -8,7 +8,7 @@ import { Middleware } from "../../middleware/middleware.cjs";
8
8
  import { Realtime } from "../../realtime/types.cjs";
9
9
  import { EventType } from "../../triggers/triggers.cjs";
10
10
  import { InngestFunction } from "../../InngestFunction.cjs";
11
- import { ClientOptions, EventPayload, InvocationResult, InvokeTargetFunctionDefinition, JsonError, SendEventBaseOutput, SendEventOutput, StepOptionsOrId, TimeStr, TimeStrBatch, TriggerEventFromFunction } from "../../../types.cjs";
11
+ import { ClientOptions, DeferFn, EventPayload, InvocationResult, InvokeTargetFunctionDefinition, JsonError, SendEventBaseOutput, SendEventOutput, StepOptionsOrId, TimeStr, TimeStrBatch, TriggerEventFromFunction } from "../../../types.cjs";
12
12
  import { GetFunctionOutputRaw, Inngest } from "../../Inngest.cjs";
13
13
  import { Behaviour, Instrumentations } from "./util.cjs";
14
14
  import * as _standard_schema_spec0 from "@standard-schema/spec";
@@ -72,8 +72,6 @@ declare const extendedTracesMiddleware: ({
72
72
  ctx: {
73
73
  tracer: _opentelemetry_api0.Tracer;
74
74
  event: Simplify<EventPayload>;
75
- events: AsTuple<Simplify<EventPayload>>;
76
- runId: string;
77
75
  step: {
78
76
  sendEvent: (idOrOptions: StepOptionsOrId, payload: SendEventPayload) => Promise<SendEventOutput<ClientOptions>>;
79
77
  waitForSignal: <TData>(idOrOptions: StepOptionsOrId, opts: {
@@ -155,6 +153,11 @@ declare const extendedTracesMiddleware: ({
155
153
  }) => InvocationResult<Jsonify<GetFunctionOutputRaw<TFunction>>>;
156
154
  fetch: StepFetch;
157
155
  };
156
+ defer: DeferFn;
157
+ events: AsTuple<Simplify<EventPayload>>;
158
+ runId: string;
159
+ requestId?: string | undefined;
160
+ jobId?: string | undefined;
158
161
  group: ReturnType<typeof createGroupTools>;
159
162
  attempt: number;
160
163
  maxAttempts?: number | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.cts","names":[],"sources":["../../../../src/components/execution/otel/middleware.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;UA6BiB,+BAAA;;;;;;;;;;;;;EAAA,SAAA,CAAA,EAaH,SAbG;EAA+B;;;;;AAwChD;;kBAAyC,CAAA,EAlBpB,gBAkBoB;;;;;;;UA6GO,CAAA,EAvHnC,YAuHmC;;;;;;;;;cA7GnC;;;;IAIV;;;;;;;gCAyGQ,UAAA,CAAW;;gBAA0B,mBAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAWI,EAAA,CAAA,EAAA,MAAA;gBAAe,EAAA,CAAA,EAAA,MAAA;gBAAA,CAAA,CAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YApCb,SAAA,WAAA,CAAA,EAAA,MAAA,GAAA,MAAA,GAAA;cAAc,6BAAA,EAAA,mBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoC3B,UAAA,CAAW,kBAAe,QAAA,UAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;KApCxB,UAAA,CAAW"}
1
+ {"version":3,"file":"middleware.d.cts","names":[],"sources":["../../../../src/components/execution/otel/middleware.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;UA6BiB,+BAAA;;;;;;;;;;;;;EAAA,SAAA,CAAA,EAaH,SAbG;EAA+B;;;;;AAwChD;;kBAAyC,CAAA,EAlBpB,gBAkBoB;;;;;;;UA6GO,CAAA,EAvHnC,YAuHmC;;;;;;;;;cA7GnC;;;;IAIV;;;;;;;gCAyGQ,UAAA,CAAW;;gBAA0B,mBAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAWI,SAAA,OAAA,CAAA,EAAA,MAAA,GAAA,SAAA;cAAe,SAAA,MAAA,EAAA,CAAA,GAAA,IAAA,EAAA,CAAA,IAAA,SAAA,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,SAAA,EAAA,OAAA,GAAA;gBAAA,EAAA,CAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YApCb,CAAA,GAAA,SAAA;YAAc,SAAA,aAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoC3B,UAAA,CAAW,kBAAe,QAAA,UAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;KApCxB,UAAA,CAAW"}
@@ -8,7 +8,7 @@ import { Middleware } from "../../middleware/middleware.js";
8
8
  import { Realtime } from "../../realtime/types.js";
9
9
  import { EventType } from "../../triggers/triggers.js";
10
10
  import { InngestFunction } from "../../InngestFunction.js";
11
- import { ClientOptions, EventPayload, InvocationResult, InvokeTargetFunctionDefinition, JsonError, SendEventBaseOutput, SendEventOutput, StepOptionsOrId, TimeStr, TimeStrBatch, TriggerEventFromFunction } from "../../../types.js";
11
+ import { ClientOptions, DeferFn, EventPayload, InvocationResult, InvokeTargetFunctionDefinition, JsonError, SendEventBaseOutput, SendEventOutput, StepOptionsOrId, TimeStr, TimeStrBatch, TriggerEventFromFunction } from "../../../types.js";
12
12
  import { GetFunctionOutputRaw, Inngest } from "../../Inngest.js";
13
13
  import { Behaviour, Instrumentations } from "./util.js";
14
14
  import * as _opentelemetry_api0 from "@opentelemetry/api";
@@ -72,8 +72,6 @@ declare const extendedTracesMiddleware: ({
72
72
  ctx: {
73
73
  tracer: _opentelemetry_api0.Tracer;
74
74
  event: Simplify<EventPayload>;
75
- events: AsTuple<Simplify<EventPayload>>;
76
- runId: string;
77
75
  step: {
78
76
  sendEvent: (idOrOptions: StepOptionsOrId, payload: SendEventPayload) => Promise<SendEventOutput<ClientOptions>>;
79
77
  waitForSignal: <TData>(idOrOptions: StepOptionsOrId, opts: {
@@ -155,6 +153,11 @@ declare const extendedTracesMiddleware: ({
155
153
  }) => InvocationResult<Jsonify<GetFunctionOutputRaw<TFunction>>>;
156
154
  fetch: StepFetch;
157
155
  };
156
+ defer: DeferFn;
157
+ events: AsTuple<Simplify<EventPayload>>;
158
+ runId: string;
159
+ requestId?: string | undefined;
160
+ jobId?: string | undefined;
158
161
  group: ReturnType<typeof createGroupTools>;
159
162
  attempt: number;
160
163
  maxAttempts?: number | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","names":[],"sources":["../../../../src/components/execution/otel/middleware.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;UA6BiB,+BAAA;;;;;;;;;;;;;EAAA,SAAA,CAAA,EAaH,SAbG;EAA+B;;;;;AAwChD;;kBAAyC,CAAA,EAlBpB,gBAkBoB;;;;;;;UA6GO,CAAA,EAvHnC,YAuHmC;;;;;;;;;cA7GnC;;;;IAIV;;;;;;;gCAyGQ,UAAA,CAAW;;gBAA0B,mBAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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UAAA,CAAW,kBAAe,QAAA,UAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;KApCxB,UAAA,CAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.cjs","names":[],"sources":["../../../src/components/middleware/middleware.ts"],"sourcesContent":["import type { Jsonify } from \"../../helpers/jsonify.ts\";\nimport type { MaybePromise } from \"../../helpers/types.ts\";\nimport type {\n Context,\n EventPayload,\n JsonError,\n SendEventBaseOutput,\n StepOptions,\n} from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { InngestFunction } from \"../InngestFunction.ts\";\nimport type { createStepTools } from \"../InngestStepTools.ts\";\nimport type { OpenStringUnion } from \"./types.ts\";\n\n/**\n * Namespace containing middleware-related types and base class.\n */\nexport namespace Middleware {\n /**\n * Base interface for output transformers. Extend this and override `Out` to\n * create custom transformers. This is necessary because TypeScript doesn't\n * support higher-kinded types.\n *\n * @example\n * ```ts\n * interface BooleanToStringTransform extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends boolean ? string : this[\"In\"];\n * }\n * ```\n */\n export type StaticTransform = {\n In: unknown;\n Out: unknown;\n };\n\n /**\n * Default transform. Applies the same transform as `JSON.stringify`.\n */\n export interface DefaultStaticTransform extends StaticTransform {\n Out: Jsonify<this[\"In\"]>;\n }\n\n /**\n * The step tools available to middleware for extending step functionality.\n * This is the same type as `step` in the function handler context.\n */\n export type StepTools = ReturnType<typeof createStepTools<Inngest.Any>>;\n\n /**\n * The argument passed to `transformSendEvent`.\n */\n export type TransformSendEventArgs = {\n events: EventPayload<Record<string, unknown>>[];\n readonly fn: DeepReadonly<InngestFunction.Any> | null;\n };\n\n /**\n * The argument passed to `transformStepInput`.\n */\n export type TransformStepInputArgs = {\n readonly fn: DeepReadonly<InngestFunction.Any>;\n readonly stepInfo: Readonly<\n Pick<StepInfo, \"hashedId\" | \"memoized\" | \"stepType\">\n >;\n stepOptions: StepOptions;\n input: unknown[];\n };\n\n /** The argument passed to `wrapStepHandler`. */\n export type WrapStepHandlerArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n stepInfo: StepInfo;\n }>;\n\n /**\n * A single memoized step entry received in `transformFunctionInput`.\n */\n type MemoizedStep =\n | { type: \"data\"; data: unknown }\n | { type: \"error\"; error: JsonError }\n | { type: \"input\"; input: unknown };\n\n /**\n * Memoized step state keyed by hashed step ID.\n */\n type MemoizedSteps = Record<string, MemoizedStep>;\n\n /**\n * The argument passed to `transformFunctionInput`.\n */\n export type TransformFunctionInputArgs = {\n ctx: Context.Any;\n readonly fn: DeepReadonly<InngestFunction.Any>;\n steps: MemoizedSteps;\n };\n\n /**\n * The argument passed to the static `onRegister` hook.\n */\n export type OnRegisterArgs = Readonly<{\n client: Inngest.Any;\n fn: InngestFunction.Any | null;\n }>;\n\n /**\n * Information about the incoming HTTP request that triggered this execution.\n */\n export type Request = {\n body: () => Promise<unknown>;\n headers: Readonly<Record<string, string>>;\n method: string;\n url: URL;\n };\n\n /** The argument passed to `wrapFunctionHandler`. */\n export type WrapFunctionHandlerArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n }>;\n\n /** The argument passed to `wrapRequest`. */\n export type WrapRequestArgs = DeepReadonly<{\n fn: InngestFunction.Any | null;\n next: () => Promise<Response>;\n requestArgs: readonly unknown[];\n requestInfo: Request;\n runId: string;\n }>;\n\n /** The argument passed to `wrapSendEvent`. */\n export type WrapSendEventArgs = DeepReadonly<{\n events: EventPayload<Record<string, unknown>>[];\n fn: InngestFunction.Any | null;\n next: () => Promise<SendEventBaseOutput>;\n }>;\n\n /** The argument passed to `wrapStep`. */\n export type WrapStepArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The shape of the HTTP response returned by the middleware chain.\n * This is what `next()` resolves with inside `wrapRequest`.\n */\n export type Response = {\n body: string;\n headers: Record<string, string>;\n status: number;\n };\n\n /**\n * The argument passed to `onMemoizationEnd`.\n */\n export type OnMemoizationEndArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n }>;\n\n /**\n * The argument passed to `onStepStart`.\n */\n export type OnStepStartArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onStepError`.\n */\n export type OnStepErrorArgs = DeepReadonly<{\n ctx: Context.Any;\n error: Error;\n fn: InngestFunction.Any;\n\n /**\n * Whether this is the final attempt for the step, meaning retries are\n * exhausted or the error is non-retriable. When `false`, the step will be\n * retried.\n */\n isFinalAttempt: boolean;\n\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onStepComplete`.\n */\n export type OnStepCompleteArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n output: unknown;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onRunStart`.\n */\n export type OnRunStartArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n }>;\n\n /**\n * The argument passed to `onRunComplete`.\n */\n export type OnRunCompleteArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n output: unknown;\n }>;\n\n /**\n * The argument passed to `onRunError`.\n */\n export type OnRunErrorArgs = DeepReadonly<{\n ctx: Context.Any;\n error: Error;\n fn: InngestFunction.Any;\n\n /**\n * Whether this is the final attempt for the function, meaning retries are\n * exhausted or the error is non-retriable. When `false`, the function will\n * be retried.\n */\n isFinalAttempt: boolean;\n }>;\n\n /**\n * The type of step. This union may be extended in the future, and will not be\n * considered a breaking change.\n */\n export type StepType = OpenStringUnion<\n | \"ai.infer\"\n | \"ai.wrap\"\n | \"fetch\"\n | \"group.experiment\"\n | \"invoke\"\n | \"realtime.publish\"\n | \"run\"\n | \"sendEvent\"\n | \"sleep\"\n | \"waitForEvent\"\n >;\n\n export type StepInfo = {\n /**\n * Unique ID for the step. This is a hash of the user-defined step ID,\n * including the implicit index if the user-defined ID is not unique.\n */\n hashedId: string;\n\n /**\n * The arguments passed to the step function, if any. For `step.run()`,\n * these are the arguments after the id and handler function.\n */\n input?: unknown[];\n\n /**\n * Whether the step result is being retrieved from memoized state (true)\n * or being executed fresh (false).\n */\n memoized: boolean;\n\n /**\n * Based on the first argument passed to the `step` method.\n */\n options: StepOptions;\n\n stepType: StepType;\n };\n\n /**\n * Base class for creating middleware. Extend this class to create custom\n * middleware with hooks for step execution.\n */\n // @privateRemark\n // Methods are nullish instead of noops as a performance optimization. This is\n // primarily because of `wrapStep`. Each defined `wrapStep` method adds 1 more\n // promise to the chain for each step. This chain runs every time the step\n // completes/errors (even when memoized).\n export abstract class BaseMiddleware {\n readonly client: Inngest.Any;\n\n /**\n * Used to identify the middleware instance in logs. Uniqueness is not\n * required, though using multiple middleware with the same ID in the same\n * app may cause confusion when debugging.\n */\n abstract readonly id: string;\n\n /**\n * Declare this to statically specify how function return types are\n * transformed. By default, the function return type is Jsonified.\n *\n * Must match the same structure as `StaticTransform` to imitate\n * higher-kinded types.\n *\n * @example\n * ```ts\n * interface PreserveDate extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends Date ? Date : Jsonify<this[\"In\"]>;\n * }\n *\n * class MyMiddleware extends Middleware.BaseMiddleware {\n * declare functionOutputTransform: PreserveDate;\n * }\n * ```\n *\n * @default Middleware.DefaultStaticTransform (e.g. Date -> string)\n */\n declare functionOutputTransform: DefaultStaticTransform;\n\n /**\n * Declare this to statically specify how step output types are transformed.\n * By default, the step output type is Jsonified.\n *\n * Must match the same structure as `StaticTransform` to imitate\n * higher-kinded types.\n *\n * @example\n * ```ts\n * interface PreserveDate extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends Date ? Date : Jsonify<this[\"In\"]>;\n * }\n *\n * class MyMiddleware extends Middleware.BaseMiddleware {\n * declare stepOutputTransform: PreserveDate;\n * }\n * ```\n *\n * @default Middleware.DefaultStaticTransform (e.g. Date -> string)\n */\n declare stepOutputTransform: DefaultStaticTransform;\n\n constructor({ client }: { client: Inngest.Any }) {\n this.client = client;\n }\n\n /**\n * Called when the middleware class is added to an Inngest client or Inngest\n * function. Use this for one-time setup that needs a reference to the\n * client instance (e.g. registering processors, setting feature flags).\n *\n * Do not mutate arguments.\n */\n static onRegister?(args: Middleware.OnRegisterArgs): void;\n\n /**\n * Called 1 time per request, after memoization completes.\n *\n * If all memoized steps have been resolved/rejected, then this hook calls.\n * This is at the top of the function handler when there are 0 memoized\n * steps.\n *\n * If a new step is found before resolving/rejecting all memoized steps,\n * then this calls.\n *\n * Do not mutate arguments.\n */\n onMemoizationEnd?(arg: Middleware.OnMemoizationEndArgs): MaybePromise<void>;\n\n /**\n * Called when the run completes successfully. Does NOT call when the run\n * errors: `onRunError` calls instead.\n *\n * Do not mutate arguments.\n */\n onRunComplete?(arg: Middleware.OnRunCompleteArgs): MaybePromise<void>;\n\n /**\n * Called when the function throws an error.\n *\n * Do not mutate arguments.\n */\n onRunError?(arg: Middleware.OnRunErrorArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per run on the very first request (0 memoized steps,\n * attempt 0). Does NOT call on subsequent requests where steps are being\n * replayed.\n *\n * Do not mutate arguments.\n */\n onRunStart?(arg: Middleware.OnRunStartArgs): MaybePromise<void>;\n\n /**\n * Called when a step successfully completes. Only called for `step.run`\n * and `step.sendEvent`. Never called for memoized step outputs. Does NOT\n * call when the step errors: `onStepError` calls instead.\n *\n * Do not mutate arguments.\n */\n onStepComplete?(arg: Middleware.OnStepCompleteArgs): MaybePromise<void>;\n\n /**\n * Called each time a step errors. Only called for `step.run` and\n * `step.sendEvent`. Never called for memoized errors.\n *\n * Do not mutate arguments.\n */\n onStepError?(arg: Middleware.OnStepErrorArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per step before running its handler. Only called for\n * `step.run` and `step.sendEvent`.\n *\n * Do not mutate arguments.\n */\n onStepStart?(arg: Middleware.OnStepStartArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per request (likely multiple times per run). Return the\n * (potentially modified) arg object.\n *\n * Use cases:\n * - Dependency injection.\n * - Deserialize events before passing it to the function handler.\n *\n * Do not mutate arguments.\n */\n // @privateRemark\n // This hook exists because `wrapFunctionHandler` can't be used for the\n // transformation's static type inference. For example, if the user added\n // `ctx.db` in `wrapFunctionHandler` then the static types wouldn't show\n // `ctx.db` in the function handler.\n transformFunctionInput?(\n arg: Middleware.TransformFunctionInputArgs,\n ): MaybePromise<Middleware.TransformFunctionInputArgs>;\n\n /**\n * Called when sending events. This is either `step.sendEvent` or\n * `client.send`. Return the (potentially modified) arg object.\n *\n * Use cases:\n * - Serialize event data before sending it to the Inngest Server.\n *\n * Do not mutate arguments.\n */\n transformSendEvent?(\n arg: Middleware.TransformSendEventArgs,\n ): MaybePromise<Middleware.TransformSendEventArgs>;\n\n /**\n * Called 1 time per step per request (likely multiple times per step).\n * Return the (potentially modified) arg object.\n *\n * Use cases:\n * - Modify step options (e.g. the step ID).\n * - Modify step input args.\n *\n * Do not mutate arguments.\n */\n // @privateRemark\n // Step input transformation could happen in `wrapStep`, but we chose not to\n // for the following reasons:\n // 1. `wrapStep` may have a negative performance impact under certain\n // workloads.\n // 2. `wrapStep` is a little more complicated to use.\n // 3. Since `transformFunctionInput` must exist, having this hook\n // establishes a consistent pattern for input transformation.\n transformStepInput?(\n arg: TransformStepInputArgs,\n ): MaybePromise<TransformStepInputArgs>;\n\n /**\n * Called 1 time per request.\n *\n * Use cases:\n * - AsyncLocalStorage context.\n * - Function-level output/error transformation.\n * - Prepend/append steps around the function handler.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n *\n * **Important:** `next()` only resolves when the function completes. On\n * requests where a fresh step is discovered, control flow is interrupted\n * and `next()` never resolves.\n */\n wrapFunctionHandler?(args: WrapFunctionHandlerArgs): Promise<unknown>;\n\n /**\n * Called 1 time per request.\n *\n * Use cases:\n * - Custom auth.\n * - Expose request data to the Inngest function handler.\n * - Metrics.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n wrapRequest?(args: WrapRequestArgs): Promise<Response>;\n\n /**\n * Called each time events are sent (either `client.send` or\n * `step.sendEvent`).\n *\n * Use cases:\n * - Backup events (e.g. blob store) when they fail to send.\n * - Metrics.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n wrapSendEvent?(args: WrapSendEventArgs): Promise<SendEventBaseOutput>;\n\n /**\n * Called 1 time per step per request. Called for all step kinds. Depending\n * on your use case, you may want `wrapStepHandler` instead.\n *\n * Use cases:\n * - Deserialize step output before returning it to the function handler.\n * - Handle step failure errors (after exhausting retries).\n * - Prepend/append steps around a step.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n *\n * NOTE: `next()` only resolves when the step completes/fails. On requests\n * where a fresh step is discovered, control flow is interrupted and\n * `next()` never resolves.\n */\n wrapStep?(args: WrapStepArgs): Promise<unknown>;\n\n /**\n * Called 1 time per step attempt. Wraps the step's handler. Only called for\n * `step.run` and `step.sendEvent`. Use this to modify the handler's\n * returned output or thrown error before it's sent to the Inngest Server.\n *\n * Use cases:\n * - Serialize step output before sending it to the Inngest Server.\n * - Handle step attempt errors (before exhausting retries).\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n // @privateRemark\n // This hook exists because of checkpointing. For serialization middleware\n // to work with checkpointing, we need to both:\n // 1. Serialize the step output before sending it to the Inngest Server.\n // 2. Deserialize the step output before returning it to the function handler.\n //\n // We initially solved this by calling `wrapStep` twice per step per\n // request. But this breaks the \"prepend with step\" logic since we'd\n // encounter the prepended step twice; this caused us to run the prepended\n // step twice.\n //\n // Now that we have `wrapStepHandler`, it can be responsible for\n // serialization and `wrapStep` can be responsible for deserialization.\n wrapStepHandler?(args: WrapStepHandlerArgs): Promise<unknown>;\n }\n\n /**\n * A no-arg constructor for a BaseMiddleware subclass. Used in client and\n * function options so that fresh instances are created per-request.\n */\n export type Class = (new (args: {\n client: Inngest.Any;\n }) => BaseMiddleware) & {\n // Static methods aren't captured by `new () => ...`, so we repeat it here.\n onRegister?(arg: OnRegisterArgs): void;\n };\n}\n\ntype DeepReadonly<T> = T extends (infer U)[]\n ? readonly DeepReadonly<U>[]\n : // Do not make functions readonly, since that leads to weird stuff like not\n // being able to call `.catch()` on the returned promise.\n T extends Function\n ? T\n : // Do not recurse into these types. If that happens, then the resulting\n // type will not be compatible with the original type\n T extends Date | RegExp | Error | Map<unknown, unknown> | Set<unknown>\n ? Readonly<T>\n : T extends object\n ? { readonly [K in keyof T]: DeepReadonly<T[K]> }\n : T;\n"],"mappings":";;;;CAgSS,MAAe,eAAe;EACnC,AAAS;EAqDT,YAAY,EAAE,UAAmC;AAC/C,QAAK,SAAS"}
1
+ {"version":3,"file":"middleware.cjs","names":[],"sources":["../../../src/components/middleware/middleware.ts"],"sourcesContent":["import type { Jsonify } from \"../../helpers/jsonify.ts\";\nimport type { MaybePromise } from \"../../helpers/types.ts\";\nimport type {\n Context,\n EventPayload,\n JsonError,\n SendEventBaseOutput,\n StepOptions,\n} from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { InngestFunction } from \"../InngestFunction.ts\";\nimport type { createStepTools } from \"../InngestStepTools.ts\";\nimport type { OpenStringUnion } from \"./types.ts\";\n\n/**\n * Namespace containing middleware-related types and base class.\n */\nexport namespace Middleware {\n /**\n * Base interface for output transformers. Extend this and override `Out` to\n * create custom transformers. This is necessary because TypeScript doesn't\n * support higher-kinded types.\n *\n * @example\n * ```ts\n * interface BooleanToStringTransform extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends boolean ? string : this[\"In\"];\n * }\n * ```\n */\n export type StaticTransform = {\n In: unknown;\n Out: unknown;\n };\n\n /**\n * Default transform. Applies the same transform as `JSON.stringify`.\n */\n export interface DefaultStaticTransform extends StaticTransform {\n Out: Jsonify<this[\"In\"]>;\n }\n\n /**\n * The step tools available to middleware for extending step functionality.\n * This is the same type as `step` in the function handler context.\n */\n export type StepTools = ReturnType<typeof createStepTools<Inngest.Any>>;\n\n /**\n * The argument passed to `transformSendEvent`.\n */\n export type TransformSendEventArgs = {\n events: EventPayload<Record<string, unknown>>[];\n readonly fn: DeepReadonly<InngestFunction.Any> | null;\n };\n\n /**\n * The argument passed to `transformStepInput`.\n */\n export type TransformStepInputArgs = {\n readonly fn: DeepReadonly<InngestFunction.Any>;\n readonly stepInfo: Readonly<\n Pick<StepInfo, \"hashedId\" | \"memoized\" | \"stepType\">\n >;\n stepOptions: StepOptions;\n input: unknown[];\n };\n\n /** The argument passed to `wrapStepHandler`. */\n export type WrapStepHandlerArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n stepInfo: StepInfo;\n }>;\n\n /**\n * A single memoized step entry received in `transformFunctionInput`.\n */\n type MemoizedStep =\n | { type: \"data\"; data: unknown }\n | { type: \"error\"; error: JsonError }\n | { type: \"input\"; input: unknown };\n\n /**\n * Memoized step state keyed by hashed step ID.\n */\n type MemoizedSteps = Record<string, MemoizedStep>;\n\n /**\n * The argument passed to `transformFunctionInput`.\n */\n export type TransformFunctionInputArgs = {\n ctx: Context.Any;\n readonly fn: DeepReadonly<InngestFunction.Any>;\n steps: MemoizedSteps;\n };\n\n /**\n * The argument passed to the static `onRegister` hook.\n */\n export type OnRegisterArgs = Readonly<{\n client: Inngest.Any;\n fn: InngestFunction.Any | null;\n }>;\n\n /**\n * Information about the incoming HTTP request that triggered this execution.\n */\n export type Request = {\n body: () => Promise<unknown>;\n headers: Readonly<Record<string, string>>;\n method: string;\n url: URL;\n };\n\n /** The argument passed to `wrapFunctionHandler`. */\n export type WrapFunctionHandlerArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n }>;\n\n /** The argument passed to `wrapRequest`. */\n export type WrapRequestArgs = DeepReadonly<{\n fn: InngestFunction.Any | null;\n next: () => Promise<Response>;\n requestArgs: readonly unknown[];\n requestInfo: Request;\n runId: string;\n }>;\n\n /** The argument passed to `wrapSendEvent`. */\n export type WrapSendEventArgs = DeepReadonly<{\n events: EventPayload<Record<string, unknown>>[];\n fn: InngestFunction.Any | null;\n next: () => Promise<SendEventBaseOutput>;\n }>;\n\n /** The argument passed to `wrapStep`. */\n export type WrapStepArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The shape of the HTTP response returned by the middleware chain.\n * This is what `next()` resolves with inside `wrapRequest`.\n */\n export type Response = {\n body: string;\n headers: Record<string, string>;\n status: number;\n };\n\n /**\n * The argument passed to `onMemoizationEnd`.\n */\n export type OnMemoizationEndArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n }>;\n\n /**\n * The argument passed to `onStepStart`.\n */\n export type OnStepStartArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onStepError`.\n */\n export type OnStepErrorArgs = DeepReadonly<{\n ctx: Context.Any;\n error: Error;\n fn: InngestFunction.Any;\n\n /**\n * Whether this is the final attempt for the step, meaning retries are\n * exhausted or the error is non-retriable. When `false`, the step will be\n * retried.\n */\n isFinalAttempt: boolean;\n\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onStepComplete`.\n */\n export type OnStepCompleteArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n output: unknown;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onRunStart`.\n */\n export type OnRunStartArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n }>;\n\n /**\n * The argument passed to `onRunComplete`.\n */\n export type OnRunCompleteArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n output: unknown;\n }>;\n\n /**\n * The argument passed to `onRunError`.\n */\n export type OnRunErrorArgs = DeepReadonly<{\n ctx: Context.Any;\n error: Error;\n fn: InngestFunction.Any;\n\n /**\n * Whether this is the final attempt for the function, meaning retries are\n * exhausted or the error is non-retriable. When `false`, the function will\n * be retried.\n */\n isFinalAttempt: boolean;\n }>;\n\n /**\n * The type of step. This union may be extended in the future, and will not be\n * considered a breaking change.\n */\n export type StepType = OpenStringUnion<\n | \"ai.infer\"\n | \"ai.wrap\"\n | \"fetch\"\n | \"group.experiment\"\n | \"invoke\"\n | \"realtime.publish\"\n | \"run\"\n | \"sendEvent\"\n | \"sleep\"\n | \"waitForEvent\"\n | \"waitForSignal\"\n >;\n\n export type StepInfo = {\n /**\n * Unique ID for the step. This is a hash of the user-defined step ID,\n * including the implicit index if the user-defined ID is not unique.\n */\n hashedId: string;\n\n /**\n * The arguments passed to the step function, if any. For `step.run()`,\n * these are the arguments after the id and handler function.\n */\n input?: unknown[];\n\n /**\n * Whether the step result is being retrieved from memoized state (true)\n * or being executed fresh (false).\n */\n memoized: boolean;\n\n /**\n * Based on the first argument passed to the `step` method.\n */\n options: StepOptions;\n\n stepType: StepType;\n };\n\n /**\n * Base class for creating middleware. Extend this class to create custom\n * middleware with hooks for step execution.\n */\n // @privateRemark\n // Methods are nullish instead of noops as a performance optimization. This is\n // primarily because of `wrapStep`. Each defined `wrapStep` method adds 1 more\n // promise to the chain for each step. This chain runs every time the step\n // completes/errors (even when memoized).\n export abstract class BaseMiddleware {\n readonly client: Inngest.Any;\n\n /**\n * Used to identify the middleware instance in logs. Uniqueness is not\n * required, though using multiple middleware with the same ID in the same\n * app may cause confusion when debugging.\n */\n abstract readonly id: string;\n\n /**\n * Declare this to statically specify how function return types are\n * transformed. By default, the function return type is Jsonified.\n *\n * Must match the same structure as `StaticTransform` to imitate\n * higher-kinded types.\n *\n * @example\n * ```ts\n * interface PreserveDate extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends Date ? Date : Jsonify<this[\"In\"]>;\n * }\n *\n * class MyMiddleware extends Middleware.BaseMiddleware {\n * declare functionOutputTransform: PreserveDate;\n * }\n * ```\n *\n * @default Middleware.DefaultStaticTransform (e.g. Date -> string)\n */\n declare functionOutputTransform: DefaultStaticTransform;\n\n /**\n * Declare this to statically specify how step output types are transformed.\n * By default, the step output type is Jsonified.\n *\n * Must match the same structure as `StaticTransform` to imitate\n * higher-kinded types.\n *\n * @example\n * ```ts\n * interface PreserveDate extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends Date ? Date : Jsonify<this[\"In\"]>;\n * }\n *\n * class MyMiddleware extends Middleware.BaseMiddleware {\n * declare stepOutputTransform: PreserveDate;\n * }\n * ```\n *\n * @default Middleware.DefaultStaticTransform (e.g. Date -> string)\n */\n declare stepOutputTransform: DefaultStaticTransform;\n\n constructor({ client }: { client: Inngest.Any }) {\n this.client = client;\n }\n\n /**\n * Called when the middleware class is added to an Inngest client or Inngest\n * function. Use this for one-time setup that needs a reference to the\n * client instance (e.g. registering processors, setting feature flags).\n *\n * Do not mutate arguments.\n */\n static onRegister?(args: Middleware.OnRegisterArgs): void;\n\n /**\n * Called 1 time per request, after memoization completes.\n *\n * If all memoized steps have been resolved/rejected, then this hook calls.\n * This is at the top of the function handler when there are 0 memoized\n * steps.\n *\n * If a new step is found before resolving/rejecting all memoized steps,\n * then this calls.\n *\n * Do not mutate arguments.\n */\n onMemoizationEnd?(arg: Middleware.OnMemoizationEndArgs): MaybePromise<void>;\n\n /**\n * Called when the run completes successfully. Does NOT call when the run\n * errors: `onRunError` calls instead.\n *\n * Do not mutate arguments.\n */\n onRunComplete?(arg: Middleware.OnRunCompleteArgs): MaybePromise<void>;\n\n /**\n * Called when the function throws an error.\n *\n * Do not mutate arguments.\n */\n onRunError?(arg: Middleware.OnRunErrorArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per run on the very first request (0 memoized steps,\n * attempt 0). Does NOT call on subsequent requests where steps are being\n * replayed.\n *\n * Do not mutate arguments.\n */\n onRunStart?(arg: Middleware.OnRunStartArgs): MaybePromise<void>;\n\n /**\n * Called when a step successfully completes. Only called for `step.run`\n * and `step.sendEvent`. Never called for memoized step outputs. Does NOT\n * call when the step errors: `onStepError` calls instead.\n *\n * Do not mutate arguments.\n */\n onStepComplete?(arg: Middleware.OnStepCompleteArgs): MaybePromise<void>;\n\n /**\n * Called each time a step errors. Only called for `step.run` and\n * `step.sendEvent`. Never called for memoized errors.\n *\n * Do not mutate arguments.\n */\n onStepError?(arg: Middleware.OnStepErrorArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per step before running its handler. Only called for\n * `step.run` and `step.sendEvent`.\n *\n * Do not mutate arguments.\n */\n onStepStart?(arg: Middleware.OnStepStartArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per request (likely multiple times per run). Return the\n * (potentially modified) arg object.\n *\n * Use cases:\n * - Dependency injection.\n * - Deserialize events before passing it to the function handler.\n *\n * Do not mutate arguments.\n */\n // @privateRemark\n // This hook exists because `wrapFunctionHandler` can't be used for the\n // transformation's static type inference. For example, if the user added\n // `ctx.db` in `wrapFunctionHandler` then the static types wouldn't show\n // `ctx.db` in the function handler.\n transformFunctionInput?(\n arg: Middleware.TransformFunctionInputArgs,\n ): MaybePromise<Middleware.TransformFunctionInputArgs>;\n\n /**\n * Called when sending events. This is either `step.sendEvent` or\n * `client.send`. Return the (potentially modified) arg object.\n *\n * Use cases:\n * - Serialize event data before sending it to the Inngest Server.\n *\n * Do not mutate arguments.\n */\n transformSendEvent?(\n arg: Middleware.TransformSendEventArgs,\n ): MaybePromise<Middleware.TransformSendEventArgs>;\n\n /**\n * Called 1 time per step per request (likely multiple times per step).\n * Return the (potentially modified) arg object.\n *\n * Use cases:\n * - Modify step options (e.g. the step ID).\n * - Modify step input args.\n *\n * Do not mutate arguments.\n */\n // @privateRemark\n // Step input transformation could happen in `wrapStep`, but we chose not to\n // for the following reasons:\n // 1. `wrapStep` may have a negative performance impact under certain\n // workloads.\n // 2. `wrapStep` is a little more complicated to use.\n // 3. Since `transformFunctionInput` must exist, having this hook\n // establishes a consistent pattern for input transformation.\n transformStepInput?(\n arg: TransformStepInputArgs,\n ): MaybePromise<TransformStepInputArgs>;\n\n /**\n * Called 1 time per request.\n *\n * Use cases:\n * - AsyncLocalStorage context.\n * - Function-level output/error transformation.\n * - Prepend/append steps around the function handler.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n *\n * **Important:** `next()` only resolves when the function completes. On\n * requests where a fresh step is discovered, control flow is interrupted\n * and `next()` never resolves.\n */\n wrapFunctionHandler?(args: WrapFunctionHandlerArgs): Promise<unknown>;\n\n /**\n * Called 1 time per request.\n *\n * Use cases:\n * - Custom auth.\n * - Expose request data to the Inngest function handler.\n * - Metrics.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n wrapRequest?(args: WrapRequestArgs): Promise<Response>;\n\n /**\n * Called each time events are sent (either `client.send` or\n * `step.sendEvent`).\n *\n * Use cases:\n * - Backup events (e.g. blob store) when they fail to send.\n * - Metrics.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n wrapSendEvent?(args: WrapSendEventArgs): Promise<SendEventBaseOutput>;\n\n /**\n * Called 1 time per step per request. Called for all step kinds. Depending\n * on your use case, you may want `wrapStepHandler` instead.\n *\n * Use cases:\n * - Deserialize step output before returning it to the function handler.\n * - Handle step failure errors (after exhausting retries).\n * - Prepend/append steps around a step.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n *\n * NOTE: `next()` only resolves when the step completes/fails. On requests\n * where a fresh step is discovered, control flow is interrupted and\n * `next()` never resolves.\n */\n wrapStep?(args: WrapStepArgs): Promise<unknown>;\n\n /**\n * Called 1 time per step attempt. Wraps the step's handler. Only called for\n * `step.run` and `step.sendEvent`. Use this to modify the handler's\n * returned output or thrown error before it's sent to the Inngest Server.\n *\n * Use cases:\n * - Serialize step output before sending it to the Inngest Server.\n * - Handle step attempt errors (before exhausting retries).\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n // @privateRemark\n // This hook exists because of checkpointing. For serialization middleware\n // to work with checkpointing, we need to both:\n // 1. Serialize the step output before sending it to the Inngest Server.\n // 2. Deserialize the step output before returning it to the function handler.\n //\n // We initially solved this by calling `wrapStep` twice per step per\n // request. But this breaks the \"prepend with step\" logic since we'd\n // encounter the prepended step twice; this caused us to run the prepended\n // step twice.\n //\n // Now that we have `wrapStepHandler`, it can be responsible for\n // serialization and `wrapStep` can be responsible for deserialization.\n wrapStepHandler?(args: WrapStepHandlerArgs): Promise<unknown>;\n }\n\n /**\n * A no-arg constructor for a BaseMiddleware subclass. Used in client and\n * function options so that fresh instances are created per-request.\n */\n export type Class = (new (args: {\n client: Inngest.Any;\n }) => BaseMiddleware) & {\n // Static methods aren't captured by `new () => ...`, so we repeat it here.\n onRegister?(arg: OnRegisterArgs): void;\n };\n}\n\ntype DeepReadonly<T> = T extends (infer U)[]\n ? readonly DeepReadonly<U>[]\n : // Do not make functions readonly, since that leads to weird stuff like not\n // being able to call `.catch()` on the returned promise.\n T extends Function\n ? T\n : // Do not recurse into these types. If that happens, then the resulting\n // type will not be compatible with the original type\n T extends Date | RegExp | Error | Map<unknown, unknown> | Set<unknown>\n ? Readonly<T>\n : T extends object\n ? { readonly [K in keyof T]: DeepReadonly<T[K]> }\n : T;\n"],"mappings":";;;;CAiSS,MAAe,eAAe;EACnC,AAAS;EAqDT,YAAY,EAAE,UAAmC;AAC/C,QAAK,SAAS"}
@@ -211,7 +211,7 @@ declare namespace Middleware {
211
211
  * The type of step. This union may be extended in the future, and will not be
212
212
  * considered a breaking change.
213
213
  */
214
- export type StepType = OpenStringUnion<"ai.infer" | "ai.wrap" | "fetch" | "group.experiment" | "invoke" | "realtime.publish" | "run" | "sendEvent" | "sleep" | "waitForEvent">;
214
+ export type StepType = OpenStringUnion<"ai.infer" | "ai.wrap" | "fetch" | "group.experiment" | "invoke" | "realtime.publish" | "run" | "sendEvent" | "sleep" | "waitForEvent" | "waitForSignal">;
215
215
  export type StepInfo = {
216
216
  /**
217
217
  * Unique ID for the step. This is a hash of the user-defined step ID,
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.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AkB;;;;;;;sBAQ7B,UAAA,CAAW,kBAAkB;;;;;;;;;;;iCAkBxC,UAAA,CAAW,6BACf,aAAa,UAAA,CAAW;;;;;;;;;;6BAYpB,UAAA,CAAW,yBACf,aAAa,UAAA,CAAW;;;;;;;;;;;6BAqBpB,yBACJ,aAAa;;;;;;;;;;;;;;;+BAgBW,0BAA0B;;;;;;;;;;;uBAYlC,kBAAkB,QAAQ;;;;;;;;;;;yBAYxB,oBAAoB,QAAQ;;;;;;;;;;;;;;;;oBAiBjC,eAAe;;;;;;;;;;;;2BA0BR,sBAAsB;;;;;;;YAQrC,OAAA,CAAQ;QACZ;qBAEa;;;;KAIhB,kBAAkB,iCACV,aAAa,OAGtB,UAAU,WACR,IAGA,UAAU,OAAO,SAAS,QAAQ,wBAAwB,eACxD,SAAS,KACT,0CACyB,IAAI,aAAa,EAAE,QAC1C"}
@@ -211,7 +211,7 @@ declare namespace Middleware {
211
211
  * The type of step. This union may be extended in the future, and will not be
212
212
  * considered a breaking change.
213
213
  */
214
- export type StepType = OpenStringUnion<"ai.infer" | "ai.wrap" | "fetch" | "group.experiment" | "invoke" | "realtime.publish" | "run" | "sendEvent" | "sleep" | "waitForEvent">;
214
+ export type StepType = OpenStringUnion<"ai.infer" | "ai.wrap" | "fetch" | "group.experiment" | "invoke" | "realtime.publish" | "run" | "sendEvent" | "sleep" | "waitForEvent" | "waitForSignal">;
215
215
  export type StepInfo = {
216
216
  /**
217
217
  * Unique ID for the step. This is a hash of the user-defined step ID,
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","names":[],"sources":["../../../src/components/middleware/middleware.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;AAiBA;AAA2B,kBAAV,UAAA,CAAU;;;;;;;;;;;;;SA6CrB,KAAA,eAAA,GAAA;IADiB,EAAA,EAAA,OAAA;IAGN,GAAA,EAAA,OAAA;;;;;SAKmB,UAAA,sBAAA,SA/Bc,eA+Bd,CAAA;IAYN,GAAA,EA1CrB,OA0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;;;;yBAYxB,oBAAoB,QAAQ;;;;;;;;;;;;;;;;oBAiBjC,eAAe;;;;;;;;;;;;2BA0BR,sBAAsB;;;;;;;YAQrC,OAAA,CAAQ;QACZ;qBAEa;;;;KAIhB,kBAAkB,iCACV,aAAa,OAGtB,UAAU,WACR,IAGA,UAAU,OAAO,SAAS,QAAQ,wBAAwB,eACxD,SAAS,KACT,0CACyB,IAAI,aAAa,EAAE,QAC1C"}
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","names":[],"sources":["../../../src/components/middleware/middleware.ts"],"sourcesContent":["import type { Jsonify } from \"../../helpers/jsonify.ts\";\nimport type { MaybePromise } from \"../../helpers/types.ts\";\nimport type {\n Context,\n EventPayload,\n JsonError,\n SendEventBaseOutput,\n StepOptions,\n} from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { InngestFunction } from \"../InngestFunction.ts\";\nimport type { createStepTools } from \"../InngestStepTools.ts\";\nimport type { OpenStringUnion } from \"./types.ts\";\n\n/**\n * Namespace containing middleware-related types and base class.\n */\nexport namespace Middleware {\n /**\n * Base interface for output transformers. Extend this and override `Out` to\n * create custom transformers. This is necessary because TypeScript doesn't\n * support higher-kinded types.\n *\n * @example\n * ```ts\n * interface BooleanToStringTransform extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends boolean ? string : this[\"In\"];\n * }\n * ```\n */\n export type StaticTransform = {\n In: unknown;\n Out: unknown;\n };\n\n /**\n * Default transform. Applies the same transform as `JSON.stringify`.\n */\n export interface DefaultStaticTransform extends StaticTransform {\n Out: Jsonify<this[\"In\"]>;\n }\n\n /**\n * The step tools available to middleware for extending step functionality.\n * This is the same type as `step` in the function handler context.\n */\n export type StepTools = ReturnType<typeof createStepTools<Inngest.Any>>;\n\n /**\n * The argument passed to `transformSendEvent`.\n */\n export type TransformSendEventArgs = {\n events: EventPayload<Record<string, unknown>>[];\n readonly fn: DeepReadonly<InngestFunction.Any> | null;\n };\n\n /**\n * The argument passed to `transformStepInput`.\n */\n export type TransformStepInputArgs = {\n readonly fn: DeepReadonly<InngestFunction.Any>;\n readonly stepInfo: Readonly<\n Pick<StepInfo, \"hashedId\" | \"memoized\" | \"stepType\">\n >;\n stepOptions: StepOptions;\n input: unknown[];\n };\n\n /** The argument passed to `wrapStepHandler`. */\n export type WrapStepHandlerArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n stepInfo: StepInfo;\n }>;\n\n /**\n * A single memoized step entry received in `transformFunctionInput`.\n */\n type MemoizedStep =\n | { type: \"data\"; data: unknown }\n | { type: \"error\"; error: JsonError }\n | { type: \"input\"; input: unknown };\n\n /**\n * Memoized step state keyed by hashed step ID.\n */\n type MemoizedSteps = Record<string, MemoizedStep>;\n\n /**\n * The argument passed to `transformFunctionInput`.\n */\n export type TransformFunctionInputArgs = {\n ctx: Context.Any;\n readonly fn: DeepReadonly<InngestFunction.Any>;\n steps: MemoizedSteps;\n };\n\n /**\n * The argument passed to the static `onRegister` hook.\n */\n export type OnRegisterArgs = Readonly<{\n client: Inngest.Any;\n fn: InngestFunction.Any | null;\n }>;\n\n /**\n * Information about the incoming HTTP request that triggered this execution.\n */\n export type Request = {\n body: () => Promise<unknown>;\n headers: Readonly<Record<string, string>>;\n method: string;\n url: URL;\n };\n\n /** The argument passed to `wrapFunctionHandler`. */\n export type WrapFunctionHandlerArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n }>;\n\n /** The argument passed to `wrapRequest`. */\n export type WrapRequestArgs = DeepReadonly<{\n fn: InngestFunction.Any | null;\n next: () => Promise<Response>;\n requestArgs: readonly unknown[];\n requestInfo: Request;\n runId: string;\n }>;\n\n /** The argument passed to `wrapSendEvent`. */\n export type WrapSendEventArgs = DeepReadonly<{\n events: EventPayload<Record<string, unknown>>[];\n fn: InngestFunction.Any | null;\n next: () => Promise<SendEventBaseOutput>;\n }>;\n\n /** The argument passed to `wrapStep`. */\n export type WrapStepArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The shape of the HTTP response returned by the middleware chain.\n * This is what `next()` resolves with inside `wrapRequest`.\n */\n export type Response = {\n body: string;\n headers: Record<string, string>;\n status: number;\n };\n\n /**\n * The argument passed to `onMemoizationEnd`.\n */\n export type OnMemoizationEndArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n }>;\n\n /**\n * The argument passed to `onStepStart`.\n */\n export type OnStepStartArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onStepError`.\n */\n export type OnStepErrorArgs = DeepReadonly<{\n ctx: Context.Any;\n error: Error;\n fn: InngestFunction.Any;\n\n /**\n * Whether this is the final attempt for the step, meaning retries are\n * exhausted or the error is non-retriable. When `false`, the step will be\n * retried.\n */\n isFinalAttempt: boolean;\n\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onStepComplete`.\n */\n export type OnStepCompleteArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n output: unknown;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onRunStart`.\n */\n export type OnRunStartArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n }>;\n\n /**\n * The argument passed to `onRunComplete`.\n */\n export type OnRunCompleteArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n output: unknown;\n }>;\n\n /**\n * The argument passed to `onRunError`.\n */\n export type OnRunErrorArgs = DeepReadonly<{\n ctx: Context.Any;\n error: Error;\n fn: InngestFunction.Any;\n\n /**\n * Whether this is the final attempt for the function, meaning retries are\n * exhausted or the error is non-retriable. When `false`, the function will\n * be retried.\n */\n isFinalAttempt: boolean;\n }>;\n\n /**\n * The type of step. This union may be extended in the future, and will not be\n * considered a breaking change.\n */\n export type StepType = OpenStringUnion<\n | \"ai.infer\"\n | \"ai.wrap\"\n | \"fetch\"\n | \"group.experiment\"\n | \"invoke\"\n | \"realtime.publish\"\n | \"run\"\n | \"sendEvent\"\n | \"sleep\"\n | \"waitForEvent\"\n >;\n\n export type StepInfo = {\n /**\n * Unique ID for the step. This is a hash of the user-defined step ID,\n * including the implicit index if the user-defined ID is not unique.\n */\n hashedId: string;\n\n /**\n * The arguments passed to the step function, if any. For `step.run()`,\n * these are the arguments after the id and handler function.\n */\n input?: unknown[];\n\n /**\n * Whether the step result is being retrieved from memoized state (true)\n * or being executed fresh (false).\n */\n memoized: boolean;\n\n /**\n * Based on the first argument passed to the `step` method.\n */\n options: StepOptions;\n\n stepType: StepType;\n };\n\n /**\n * Base class for creating middleware. Extend this class to create custom\n * middleware with hooks for step execution.\n */\n // @privateRemark\n // Methods are nullish instead of noops as a performance optimization. This is\n // primarily because of `wrapStep`. Each defined `wrapStep` method adds 1 more\n // promise to the chain for each step. This chain runs every time the step\n // completes/errors (even when memoized).\n export abstract class BaseMiddleware {\n readonly client: Inngest.Any;\n\n /**\n * Used to identify the middleware instance in logs. Uniqueness is not\n * required, though using multiple middleware with the same ID in the same\n * app may cause confusion when debugging.\n */\n abstract readonly id: string;\n\n /**\n * Declare this to statically specify how function return types are\n * transformed. By default, the function return type is Jsonified.\n *\n * Must match the same structure as `StaticTransform` to imitate\n * higher-kinded types.\n *\n * @example\n * ```ts\n * interface PreserveDate extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends Date ? Date : Jsonify<this[\"In\"]>;\n * }\n *\n * class MyMiddleware extends Middleware.BaseMiddleware {\n * declare functionOutputTransform: PreserveDate;\n * }\n * ```\n *\n * @default Middleware.DefaultStaticTransform (e.g. Date -> string)\n */\n declare functionOutputTransform: DefaultStaticTransform;\n\n /**\n * Declare this to statically specify how step output types are transformed.\n * By default, the step output type is Jsonified.\n *\n * Must match the same structure as `StaticTransform` to imitate\n * higher-kinded types.\n *\n * @example\n * ```ts\n * interface PreserveDate extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends Date ? Date : Jsonify<this[\"In\"]>;\n * }\n *\n * class MyMiddleware extends Middleware.BaseMiddleware {\n * declare stepOutputTransform: PreserveDate;\n * }\n * ```\n *\n * @default Middleware.DefaultStaticTransform (e.g. Date -> string)\n */\n declare stepOutputTransform: DefaultStaticTransform;\n\n constructor({ client }: { client: Inngest.Any }) {\n this.client = client;\n }\n\n /**\n * Called when the middleware class is added to an Inngest client or Inngest\n * function. Use this for one-time setup that needs a reference to the\n * client instance (e.g. registering processors, setting feature flags).\n *\n * Do not mutate arguments.\n */\n static onRegister?(args: Middleware.OnRegisterArgs): void;\n\n /**\n * Called 1 time per request, after memoization completes.\n *\n * If all memoized steps have been resolved/rejected, then this hook calls.\n * This is at the top of the function handler when there are 0 memoized\n * steps.\n *\n * If a new step is found before resolving/rejecting all memoized steps,\n * then this calls.\n *\n * Do not mutate arguments.\n */\n onMemoizationEnd?(arg: Middleware.OnMemoizationEndArgs): MaybePromise<void>;\n\n /**\n * Called when the run completes successfully. Does NOT call when the run\n * errors: `onRunError` calls instead.\n *\n * Do not mutate arguments.\n */\n onRunComplete?(arg: Middleware.OnRunCompleteArgs): MaybePromise<void>;\n\n /**\n * Called when the function throws an error.\n *\n * Do not mutate arguments.\n */\n onRunError?(arg: Middleware.OnRunErrorArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per run on the very first request (0 memoized steps,\n * attempt 0). Does NOT call on subsequent requests where steps are being\n * replayed.\n *\n * Do not mutate arguments.\n */\n onRunStart?(arg: Middleware.OnRunStartArgs): MaybePromise<void>;\n\n /**\n * Called when a step successfully completes. Only called for `step.run`\n * and `step.sendEvent`. Never called for memoized step outputs. Does NOT\n * call when the step errors: `onStepError` calls instead.\n *\n * Do not mutate arguments.\n */\n onStepComplete?(arg: Middleware.OnStepCompleteArgs): MaybePromise<void>;\n\n /**\n * Called each time a step errors. Only called for `step.run` and\n * `step.sendEvent`. Never called for memoized errors.\n *\n * Do not mutate arguments.\n */\n onStepError?(arg: Middleware.OnStepErrorArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per step before running its handler. Only called for\n * `step.run` and `step.sendEvent`.\n *\n * Do not mutate arguments.\n */\n onStepStart?(arg: Middleware.OnStepStartArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per request (likely multiple times per run). Return the\n * (potentially modified) arg object.\n *\n * Use cases:\n * - Dependency injection.\n * - Deserialize events before passing it to the function handler.\n *\n * Do not mutate arguments.\n */\n // @privateRemark\n // This hook exists because `wrapFunctionHandler` can't be used for the\n // transformation's static type inference. For example, if the user added\n // `ctx.db` in `wrapFunctionHandler` then the static types wouldn't show\n // `ctx.db` in the function handler.\n transformFunctionInput?(\n arg: Middleware.TransformFunctionInputArgs,\n ): MaybePromise<Middleware.TransformFunctionInputArgs>;\n\n /**\n * Called when sending events. This is either `step.sendEvent` or\n * `client.send`. Return the (potentially modified) arg object.\n *\n * Use cases:\n * - Serialize event data before sending it to the Inngest Server.\n *\n * Do not mutate arguments.\n */\n transformSendEvent?(\n arg: Middleware.TransformSendEventArgs,\n ): MaybePromise<Middleware.TransformSendEventArgs>;\n\n /**\n * Called 1 time per step per request (likely multiple times per step).\n * Return the (potentially modified) arg object.\n *\n * Use cases:\n * - Modify step options (e.g. the step ID).\n * - Modify step input args.\n *\n * Do not mutate arguments.\n */\n // @privateRemark\n // Step input transformation could happen in `wrapStep`, but we chose not to\n // for the following reasons:\n // 1. `wrapStep` may have a negative performance impact under certain\n // workloads.\n // 2. `wrapStep` is a little more complicated to use.\n // 3. Since `transformFunctionInput` must exist, having this hook\n // establishes a consistent pattern for input transformation.\n transformStepInput?(\n arg: TransformStepInputArgs,\n ): MaybePromise<TransformStepInputArgs>;\n\n /**\n * Called 1 time per request.\n *\n * Use cases:\n * - AsyncLocalStorage context.\n * - Function-level output/error transformation.\n * - Prepend/append steps around the function handler.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n *\n * **Important:** `next()` only resolves when the function completes. On\n * requests where a fresh step is discovered, control flow is interrupted\n * and `next()` never resolves.\n */\n wrapFunctionHandler?(args: WrapFunctionHandlerArgs): Promise<unknown>;\n\n /**\n * Called 1 time per request.\n *\n * Use cases:\n * - Custom auth.\n * - Expose request data to the Inngest function handler.\n * - Metrics.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n wrapRequest?(args: WrapRequestArgs): Promise<Response>;\n\n /**\n * Called each time events are sent (either `client.send` or\n * `step.sendEvent`).\n *\n * Use cases:\n * - Backup events (e.g. blob store) when they fail to send.\n * - Metrics.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n wrapSendEvent?(args: WrapSendEventArgs): Promise<SendEventBaseOutput>;\n\n /**\n * Called 1 time per step per request. Called for all step kinds. Depending\n * on your use case, you may want `wrapStepHandler` instead.\n *\n * Use cases:\n * - Deserialize step output before returning it to the function handler.\n * - Handle step failure errors (after exhausting retries).\n * - Prepend/append steps around a step.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n *\n * NOTE: `next()` only resolves when the step completes/fails. On requests\n * where a fresh step is discovered, control flow is interrupted and\n * `next()` never resolves.\n */\n wrapStep?(args: WrapStepArgs): Promise<unknown>;\n\n /**\n * Called 1 time per step attempt. Wraps the step's handler. Only called for\n * `step.run` and `step.sendEvent`. Use this to modify the handler's\n * returned output or thrown error before it's sent to the Inngest Server.\n *\n * Use cases:\n * - Serialize step output before sending it to the Inngest Server.\n * - Handle step attempt errors (before exhausting retries).\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n // @privateRemark\n // This hook exists because of checkpointing. For serialization middleware\n // to work with checkpointing, we need to both:\n // 1. Serialize the step output before sending it to the Inngest Server.\n // 2. Deserialize the step output before returning it to the function handler.\n //\n // We initially solved this by calling `wrapStep` twice per step per\n // request. But this breaks the \"prepend with step\" logic since we'd\n // encounter the prepended step twice; this caused us to run the prepended\n // step twice.\n //\n // Now that we have `wrapStepHandler`, it can be responsible for\n // serialization and `wrapStep` can be responsible for deserialization.\n wrapStepHandler?(args: WrapStepHandlerArgs): Promise<unknown>;\n }\n\n /**\n * A no-arg constructor for a BaseMiddleware subclass. Used in client and\n * function options so that fresh instances are created per-request.\n */\n export type Class = (new (args: {\n client: Inngest.Any;\n }) => BaseMiddleware) & {\n // Static methods aren't captured by `new () => ...`, so we repeat it here.\n onRegister?(arg: OnRegisterArgs): void;\n };\n}\n\ntype DeepReadonly<T> = T extends (infer U)[]\n ? readonly DeepReadonly<U>[]\n : // Do not make functions readonly, since that leads to weird stuff like not\n // being able to call `.catch()` on the returned promise.\n T extends Function\n ? T\n : // Do not recurse into these types. If that happens, then the resulting\n // type will not be compatible with the original type\n T extends Date | RegExp | Error | Map<unknown, unknown> | Set<unknown>\n ? Readonly<T>\n : T extends object\n ? { readonly [K in keyof T]: DeepReadonly<T[K]> }\n : T;\n"],"mappings":";;;CAgSS,MAAe,eAAe;EACnC,AAAS;EAqDT,YAAY,EAAE,UAAmC;AAC/C,QAAK,SAAS"}
1
+ {"version":3,"file":"middleware.js","names":[],"sources":["../../../src/components/middleware/middleware.ts"],"sourcesContent":["import type { Jsonify } from \"../../helpers/jsonify.ts\";\nimport type { MaybePromise } from \"../../helpers/types.ts\";\nimport type {\n Context,\n EventPayload,\n JsonError,\n SendEventBaseOutput,\n StepOptions,\n} from \"../../types.ts\";\nimport type { Inngest } from \"../Inngest.ts\";\nimport type { InngestFunction } from \"../InngestFunction.ts\";\nimport type { createStepTools } from \"../InngestStepTools.ts\";\nimport type { OpenStringUnion } from \"./types.ts\";\n\n/**\n * Namespace containing middleware-related types and base class.\n */\nexport namespace Middleware {\n /**\n * Base interface for output transformers. Extend this and override `Out` to\n * create custom transformers. This is necessary because TypeScript doesn't\n * support higher-kinded types.\n *\n * @example\n * ```ts\n * interface BooleanToStringTransform extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends boolean ? string : this[\"In\"];\n * }\n * ```\n */\n export type StaticTransform = {\n In: unknown;\n Out: unknown;\n };\n\n /**\n * Default transform. Applies the same transform as `JSON.stringify`.\n */\n export interface DefaultStaticTransform extends StaticTransform {\n Out: Jsonify<this[\"In\"]>;\n }\n\n /**\n * The step tools available to middleware for extending step functionality.\n * This is the same type as `step` in the function handler context.\n */\n export type StepTools = ReturnType<typeof createStepTools<Inngest.Any>>;\n\n /**\n * The argument passed to `transformSendEvent`.\n */\n export type TransformSendEventArgs = {\n events: EventPayload<Record<string, unknown>>[];\n readonly fn: DeepReadonly<InngestFunction.Any> | null;\n };\n\n /**\n * The argument passed to `transformStepInput`.\n */\n export type TransformStepInputArgs = {\n readonly fn: DeepReadonly<InngestFunction.Any>;\n readonly stepInfo: Readonly<\n Pick<StepInfo, \"hashedId\" | \"memoized\" | \"stepType\">\n >;\n stepOptions: StepOptions;\n input: unknown[];\n };\n\n /** The argument passed to `wrapStepHandler`. */\n export type WrapStepHandlerArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n stepInfo: StepInfo;\n }>;\n\n /**\n * A single memoized step entry received in `transformFunctionInput`.\n */\n type MemoizedStep =\n | { type: \"data\"; data: unknown }\n | { type: \"error\"; error: JsonError }\n | { type: \"input\"; input: unknown };\n\n /**\n * Memoized step state keyed by hashed step ID.\n */\n type MemoizedSteps = Record<string, MemoizedStep>;\n\n /**\n * The argument passed to `transformFunctionInput`.\n */\n export type TransformFunctionInputArgs = {\n ctx: Context.Any;\n readonly fn: DeepReadonly<InngestFunction.Any>;\n steps: MemoizedSteps;\n };\n\n /**\n * The argument passed to the static `onRegister` hook.\n */\n export type OnRegisterArgs = Readonly<{\n client: Inngest.Any;\n fn: InngestFunction.Any | null;\n }>;\n\n /**\n * Information about the incoming HTTP request that triggered this execution.\n */\n export type Request = {\n body: () => Promise<unknown>;\n headers: Readonly<Record<string, string>>;\n method: string;\n url: URL;\n };\n\n /** The argument passed to `wrapFunctionHandler`. */\n export type WrapFunctionHandlerArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n }>;\n\n /** The argument passed to `wrapRequest`. */\n export type WrapRequestArgs = DeepReadonly<{\n fn: InngestFunction.Any | null;\n next: () => Promise<Response>;\n requestArgs: readonly unknown[];\n requestInfo: Request;\n runId: string;\n }>;\n\n /** The argument passed to `wrapSendEvent`. */\n export type WrapSendEventArgs = DeepReadonly<{\n events: EventPayload<Record<string, unknown>>[];\n fn: InngestFunction.Any | null;\n next: () => Promise<SendEventBaseOutput>;\n }>;\n\n /** The argument passed to `wrapStep`. */\n export type WrapStepArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n next: () => Promise<unknown>;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The shape of the HTTP response returned by the middleware chain.\n * This is what `next()` resolves with inside `wrapRequest`.\n */\n export type Response = {\n body: string;\n headers: Record<string, string>;\n status: number;\n };\n\n /**\n * The argument passed to `onMemoizationEnd`.\n */\n export type OnMemoizationEndArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n }>;\n\n /**\n * The argument passed to `onStepStart`.\n */\n export type OnStepStartArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onStepError`.\n */\n export type OnStepErrorArgs = DeepReadonly<{\n ctx: Context.Any;\n error: Error;\n fn: InngestFunction.Any;\n\n /**\n * Whether this is the final attempt for the step, meaning retries are\n * exhausted or the error is non-retriable. When `false`, the step will be\n * retried.\n */\n isFinalAttempt: boolean;\n\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onStepComplete`.\n */\n export type OnStepCompleteArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n output: unknown;\n stepInfo: StepInfo;\n }>;\n\n /**\n * The argument passed to `onRunStart`.\n */\n export type OnRunStartArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n }>;\n\n /**\n * The argument passed to `onRunComplete`.\n */\n export type OnRunCompleteArgs = DeepReadonly<{\n ctx: Context.Any;\n fn: InngestFunction.Any;\n output: unknown;\n }>;\n\n /**\n * The argument passed to `onRunError`.\n */\n export type OnRunErrorArgs = DeepReadonly<{\n ctx: Context.Any;\n error: Error;\n fn: InngestFunction.Any;\n\n /**\n * Whether this is the final attempt for the function, meaning retries are\n * exhausted or the error is non-retriable. When `false`, the function will\n * be retried.\n */\n isFinalAttempt: boolean;\n }>;\n\n /**\n * The type of step. This union may be extended in the future, and will not be\n * considered a breaking change.\n */\n export type StepType = OpenStringUnion<\n | \"ai.infer\"\n | \"ai.wrap\"\n | \"fetch\"\n | \"group.experiment\"\n | \"invoke\"\n | \"realtime.publish\"\n | \"run\"\n | \"sendEvent\"\n | \"sleep\"\n | \"waitForEvent\"\n | \"waitForSignal\"\n >;\n\n export type StepInfo = {\n /**\n * Unique ID for the step. This is a hash of the user-defined step ID,\n * including the implicit index if the user-defined ID is not unique.\n */\n hashedId: string;\n\n /**\n * The arguments passed to the step function, if any. For `step.run()`,\n * these are the arguments after the id and handler function.\n */\n input?: unknown[];\n\n /**\n * Whether the step result is being retrieved from memoized state (true)\n * or being executed fresh (false).\n */\n memoized: boolean;\n\n /**\n * Based on the first argument passed to the `step` method.\n */\n options: StepOptions;\n\n stepType: StepType;\n };\n\n /**\n * Base class for creating middleware. Extend this class to create custom\n * middleware with hooks for step execution.\n */\n // @privateRemark\n // Methods are nullish instead of noops as a performance optimization. This is\n // primarily because of `wrapStep`. Each defined `wrapStep` method adds 1 more\n // promise to the chain for each step. This chain runs every time the step\n // completes/errors (even when memoized).\n export abstract class BaseMiddleware {\n readonly client: Inngest.Any;\n\n /**\n * Used to identify the middleware instance in logs. Uniqueness is not\n * required, though using multiple middleware with the same ID in the same\n * app may cause confusion when debugging.\n */\n abstract readonly id: string;\n\n /**\n * Declare this to statically specify how function return types are\n * transformed. By default, the function return type is Jsonified.\n *\n * Must match the same structure as `StaticTransform` to imitate\n * higher-kinded types.\n *\n * @example\n * ```ts\n * interface PreserveDate extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends Date ? Date : Jsonify<this[\"In\"]>;\n * }\n *\n * class MyMiddleware extends Middleware.BaseMiddleware {\n * declare functionOutputTransform: PreserveDate;\n * }\n * ```\n *\n * @default Middleware.DefaultStaticTransform (e.g. Date -> string)\n */\n declare functionOutputTransform: DefaultStaticTransform;\n\n /**\n * Declare this to statically specify how step output types are transformed.\n * By default, the step output type is Jsonified.\n *\n * Must match the same structure as `StaticTransform` to imitate\n * higher-kinded types.\n *\n * @example\n * ```ts\n * interface PreserveDate extends Middleware.StaticTransform {\n * Out: this[\"In\"] extends Date ? Date : Jsonify<this[\"In\"]>;\n * }\n *\n * class MyMiddleware extends Middleware.BaseMiddleware {\n * declare stepOutputTransform: PreserveDate;\n * }\n * ```\n *\n * @default Middleware.DefaultStaticTransform (e.g. Date -> string)\n */\n declare stepOutputTransform: DefaultStaticTransform;\n\n constructor({ client }: { client: Inngest.Any }) {\n this.client = client;\n }\n\n /**\n * Called when the middleware class is added to an Inngest client or Inngest\n * function. Use this for one-time setup that needs a reference to the\n * client instance (e.g. registering processors, setting feature flags).\n *\n * Do not mutate arguments.\n */\n static onRegister?(args: Middleware.OnRegisterArgs): void;\n\n /**\n * Called 1 time per request, after memoization completes.\n *\n * If all memoized steps have been resolved/rejected, then this hook calls.\n * This is at the top of the function handler when there are 0 memoized\n * steps.\n *\n * If a new step is found before resolving/rejecting all memoized steps,\n * then this calls.\n *\n * Do not mutate arguments.\n */\n onMemoizationEnd?(arg: Middleware.OnMemoizationEndArgs): MaybePromise<void>;\n\n /**\n * Called when the run completes successfully. Does NOT call when the run\n * errors: `onRunError` calls instead.\n *\n * Do not mutate arguments.\n */\n onRunComplete?(arg: Middleware.OnRunCompleteArgs): MaybePromise<void>;\n\n /**\n * Called when the function throws an error.\n *\n * Do not mutate arguments.\n */\n onRunError?(arg: Middleware.OnRunErrorArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per run on the very first request (0 memoized steps,\n * attempt 0). Does NOT call on subsequent requests where steps are being\n * replayed.\n *\n * Do not mutate arguments.\n */\n onRunStart?(arg: Middleware.OnRunStartArgs): MaybePromise<void>;\n\n /**\n * Called when a step successfully completes. Only called for `step.run`\n * and `step.sendEvent`. Never called for memoized step outputs. Does NOT\n * call when the step errors: `onStepError` calls instead.\n *\n * Do not mutate arguments.\n */\n onStepComplete?(arg: Middleware.OnStepCompleteArgs): MaybePromise<void>;\n\n /**\n * Called each time a step errors. Only called for `step.run` and\n * `step.sendEvent`. Never called for memoized errors.\n *\n * Do not mutate arguments.\n */\n onStepError?(arg: Middleware.OnStepErrorArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per step before running its handler. Only called for\n * `step.run` and `step.sendEvent`.\n *\n * Do not mutate arguments.\n */\n onStepStart?(arg: Middleware.OnStepStartArgs): MaybePromise<void>;\n\n /**\n * Called 1 time per request (likely multiple times per run). Return the\n * (potentially modified) arg object.\n *\n * Use cases:\n * - Dependency injection.\n * - Deserialize events before passing it to the function handler.\n *\n * Do not mutate arguments.\n */\n // @privateRemark\n // This hook exists because `wrapFunctionHandler` can't be used for the\n // transformation's static type inference. For example, if the user added\n // `ctx.db` in `wrapFunctionHandler` then the static types wouldn't show\n // `ctx.db` in the function handler.\n transformFunctionInput?(\n arg: Middleware.TransformFunctionInputArgs,\n ): MaybePromise<Middleware.TransformFunctionInputArgs>;\n\n /**\n * Called when sending events. This is either `step.sendEvent` or\n * `client.send`. Return the (potentially modified) arg object.\n *\n * Use cases:\n * - Serialize event data before sending it to the Inngest Server.\n *\n * Do not mutate arguments.\n */\n transformSendEvent?(\n arg: Middleware.TransformSendEventArgs,\n ): MaybePromise<Middleware.TransformSendEventArgs>;\n\n /**\n * Called 1 time per step per request (likely multiple times per step).\n * Return the (potentially modified) arg object.\n *\n * Use cases:\n * - Modify step options (e.g. the step ID).\n * - Modify step input args.\n *\n * Do not mutate arguments.\n */\n // @privateRemark\n // Step input transformation could happen in `wrapStep`, but we chose not to\n // for the following reasons:\n // 1. `wrapStep` may have a negative performance impact under certain\n // workloads.\n // 2. `wrapStep` is a little more complicated to use.\n // 3. Since `transformFunctionInput` must exist, having this hook\n // establishes a consistent pattern for input transformation.\n transformStepInput?(\n arg: TransformStepInputArgs,\n ): MaybePromise<TransformStepInputArgs>;\n\n /**\n * Called 1 time per request.\n *\n * Use cases:\n * - AsyncLocalStorage context.\n * - Function-level output/error transformation.\n * - Prepend/append steps around the function handler.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n *\n * **Important:** `next()` only resolves when the function completes. On\n * requests where a fresh step is discovered, control flow is interrupted\n * and `next()` never resolves.\n */\n wrapFunctionHandler?(args: WrapFunctionHandlerArgs): Promise<unknown>;\n\n /**\n * Called 1 time per request.\n *\n * Use cases:\n * - Custom auth.\n * - Expose request data to the Inngest function handler.\n * - Metrics.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n wrapRequest?(args: WrapRequestArgs): Promise<Response>;\n\n /**\n * Called each time events are sent (either `client.send` or\n * `step.sendEvent`).\n *\n * Use cases:\n * - Backup events (e.g. blob store) when they fail to send.\n * - Metrics.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n wrapSendEvent?(args: WrapSendEventArgs): Promise<SendEventBaseOutput>;\n\n /**\n * Called 1 time per step per request. Called for all step kinds. Depending\n * on your use case, you may want `wrapStepHandler` instead.\n *\n * Use cases:\n * - Deserialize step output before returning it to the function handler.\n * - Handle step failure errors (after exhausting retries).\n * - Prepend/append steps around a step.\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n *\n * NOTE: `next()` only resolves when the step completes/fails. On requests\n * where a fresh step is discovered, control flow is interrupted and\n * `next()` never resolves.\n */\n wrapStep?(args: WrapStepArgs): Promise<unknown>;\n\n /**\n * Called 1 time per step attempt. Wraps the step's handler. Only called for\n * `step.run` and `step.sendEvent`. Use this to modify the handler's\n * returned output or thrown error before it's sent to the Inngest Server.\n *\n * Use cases:\n * - Serialize step output before sending it to the Inngest Server.\n * - Handle step attempt errors (before exhausting retries).\n *\n * Must call `next()` to continue processing. Do not mutate arguments.\n */\n // @privateRemark\n // This hook exists because of checkpointing. For serialization middleware\n // to work with checkpointing, we need to both:\n // 1. Serialize the step output before sending it to the Inngest Server.\n // 2. Deserialize the step output before returning it to the function handler.\n //\n // We initially solved this by calling `wrapStep` twice per step per\n // request. But this breaks the \"prepend with step\" logic since we'd\n // encounter the prepended step twice; this caused us to run the prepended\n // step twice.\n //\n // Now that we have `wrapStepHandler`, it can be responsible for\n // serialization and `wrapStep` can be responsible for deserialization.\n wrapStepHandler?(args: WrapStepHandlerArgs): Promise<unknown>;\n }\n\n /**\n * A no-arg constructor for a BaseMiddleware subclass. Used in client and\n * function options so that fresh instances are created per-request.\n */\n export type Class = (new (args: {\n client: Inngest.Any;\n }) => BaseMiddleware) & {\n // Static methods aren't captured by `new () => ...`, so we repeat it here.\n onRegister?(arg: OnRegisterArgs): void;\n };\n}\n\ntype DeepReadonly<T> = T extends (infer U)[]\n ? readonly DeepReadonly<U>[]\n : // Do not make functions readonly, since that leads to weird stuff like not\n // being able to call `.catch()` on the returned promise.\n T extends Function\n ? T\n : // Do not recurse into these types. If that happens, then the resulting\n // type will not be compatible with the original type\n T extends Date | RegExp | Error | Map<unknown, unknown> | Set<unknown>\n ? Readonly<T>\n : T extends object\n ? { readonly [K in keyof T]: DeepReadonly<T[K]> }\n : T;\n"],"mappings":";;;CAiSS,MAAe,eAAe;EACnC,AAAS;EAqDT,YAAY,EAAE,UAAmC;AAC/C,QAAK,SAAS"}
@@ -66,6 +66,7 @@ function stepTypeFromOpCode(op, opts, logger) {
66
66
  if (opts?.type === "group.experiment") return "group.experiment";
67
67
  } else if (op === require_types.StepOpCode.Sleep) return "sleep";
68
68
  else if (op === require_types.StepOpCode.WaitForEvent) return "waitForEvent";
69
+ else if (op === require_types.StepOpCode.WaitForSignal) return "waitForSignal";
69
70
  logger.warn({
70
71
  op,
71
72
  type: opts?.type