inngest 2.7.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/api/api.js +4 -4
- package/api/schema.d.ts +54 -6
- package/api/schema.d.ts.map +1 -1
- package/api/schema.js +17 -7
- package/api/schema.js.map +1 -1
- package/cloudflare.d.ts +6 -3
- package/cloudflare.d.ts.map +1 -1
- package/cloudflare.js +19 -41
- package/cloudflare.js.map +1 -1
- package/components/EventSchemas.d.ts +1 -12
- package/components/EventSchemas.d.ts.map +1 -1
- package/components/EventSchemas.js.map +1 -1
- package/components/Inngest.d.ts +44 -57
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +47 -26
- package/components/Inngest.js.map +1 -1
- package/components/InngestCommHandler.d.ts +156 -198
- package/components/InngestCommHandler.d.ts.map +1 -1
- package/components/InngestCommHandler.js +311 -305
- package/components/InngestCommHandler.js.map +1 -1
- package/components/InngestFunction.d.ts +9 -82
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +21 -413
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestMiddleware.d.ts +37 -26
- package/components/InngestMiddleware.d.ts.map +1 -1
- package/components/InngestMiddleware.js +1 -3
- package/components/InngestMiddleware.js.map +1 -1
- package/components/InngestStepTools.d.ts +69 -37
- package/components/InngestStepTools.d.ts.map +1 -1
- package/components/InngestStepTools.js +34 -95
- package/components/InngestStepTools.js.map +1 -1
- package/components/NonRetriableError.d.ts.map +1 -1
- package/components/NonRetriableError.js +1 -0
- package/components/NonRetriableError.js.map +1 -1
- package/components/RetryAfterError.d.ts +38 -0
- package/components/RetryAfterError.d.ts.map +1 -0
- package/components/RetryAfterError.js +42 -0
- package/components/RetryAfterError.js.map +1 -0
- package/components/execution/InngestExecution.d.ts +72 -0
- package/components/execution/InngestExecution.d.ts.map +1 -0
- package/components/execution/InngestExecution.js +23 -0
- package/components/execution/InngestExecution.js.map +1 -0
- package/components/execution/v0.d.ts +114 -0
- package/components/execution/v0.d.ts.map +1 -0
- package/components/execution/v0.js +394 -0
- package/components/execution/v0.js.map +1 -0
- package/components/execution/v1.d.ts +88 -0
- package/components/execution/v1.d.ts.map +1 -0
- package/components/execution/v1.js +673 -0
- package/components/execution/v1.js.map +1 -0
- package/deno/fresh.d.ts +3 -3
- package/deno/fresh.d.ts.map +1 -1
- package/deno/fresh.js +17 -38
- package/deno/fresh.js.map +1 -1
- package/digitalocean.d.ts +5 -5
- package/digitalocean.d.ts.map +1 -1
- package/digitalocean.js +14 -46
- package/digitalocean.js.map +1 -1
- package/edge.d.ts +5 -5
- package/edge.d.ts.map +1 -1
- package/edge.js +16 -38
- package/edge.js.map +1 -1
- package/express.d.ts +7 -3
- package/express.d.ts.map +1 -1
- package/express.js +38 -45
- package/express.js.map +1 -1
- package/fastify.d.ts +8 -3
- package/fastify.d.ts.map +1 -1
- package/fastify.js +37 -47
- package/fastify.js.map +1 -1
- package/h3.d.ts +4 -3
- package/h3.d.ts.map +1 -1
- package/h3.js +18 -45
- package/h3.js.map +1 -1
- package/helpers/ServerTiming.d.ts.map +1 -1
- package/helpers/ServerTiming.js +2 -1
- package/helpers/ServerTiming.js.map +1 -1
- package/helpers/consts.d.ts +23 -9
- package/helpers/consts.d.ts.map +1 -1
- package/helpers/consts.js +31 -13
- package/helpers/consts.js.map +1 -1
- package/helpers/devserver.d.ts +0 -34
- package/helpers/devserver.d.ts.map +1 -1
- package/helpers/devserver.js.map +1 -1
- package/helpers/env.d.ts +14 -6
- package/helpers/env.d.ts.map +1 -1
- package/helpers/env.js +4 -4
- package/helpers/env.js.map +1 -1
- package/helpers/errors.d.ts +37 -2
- package/helpers/errors.d.ts.map +1 -1
- package/helpers/errors.js +66 -15
- package/helpers/errors.js.map +1 -1
- package/helpers/functions.d.ts +52 -5
- package/helpers/functions.d.ts.map +1 -1
- package/helpers/functions.js +121 -22
- package/helpers/functions.js.map +1 -1
- package/helpers/promises.d.ts +45 -0
- package/helpers/promises.d.ts.map +1 -1
- package/helpers/promises.js +69 -1
- package/helpers/promises.js.map +1 -1
- package/helpers/strings.d.ts +6 -1
- package/helpers/strings.d.ts.map +1 -1
- package/helpers/strings.js +7 -2
- package/helpers/strings.js.map +1 -1
- package/helpers/types.d.ts +5 -17
- package/helpers/types.d.ts.map +1 -1
- package/index.d.ts +4 -2
- package/index.d.ts.map +1 -1
- package/index.js +5 -1
- package/index.js.map +1 -1
- package/lambda.d.ts +10 -8
- package/lambda.d.ts.map +1 -1
- package/lambda.js +48 -72
- package/lambda.js.map +1 -1
- package/next.d.ts +11 -5
- package/next.d.ts.map +1 -1
- package/next.js +84 -103
- package/next.js.map +1 -1
- package/nuxt.d.ts +3 -3
- package/nuxt.d.ts.map +1 -1
- package/nuxt.js +5 -6
- package/nuxt.js.map +1 -1
- package/package.json +5 -4
- package/redwood.d.ts +4 -3
- package/redwood.d.ts.map +1 -1
- package/redwood.js +22 -48
- package/redwood.js.map +1 -1
- package/remix.d.ts +7 -5
- package/remix.d.ts.map +1 -1
- package/remix.js +15 -36
- package/remix.js.map +1 -1
- package/types.d.ts +126 -220
- package/types.d.ts.map +1 -1
- package/types.js +24 -45
- package/types.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/helpers/scalar.d.ts +0 -8
- package/helpers/scalar.d.ts.map +0 -1
- package/helpers/scalar.js +0 -19
- package/helpers/scalar.js.map +0 -1
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { type Simplify } from "type-fest";
|
|
2
2
|
import { type Await, type MaybePromise, type ObjectAssign, type PartialK } from "../helpers/types";
|
|
3
|
-
import { type BaseContext, type ClientOptions, type EventPayload, type IncomingOp, type MiddlewareStack, type OutgoingOp } from "../types";
|
|
4
|
-
import { type
|
|
5
|
-
import { type
|
|
3
|
+
import { type BaseContext, type ClientOptions, type EventPayload, type IncomingOp, type MiddlewareStack, type OutgoingOp, type SendEventBaseOutput } from "../types";
|
|
4
|
+
import { type AnyInngest } from "./Inngest";
|
|
5
|
+
import { type AnyInngestFunction } from "./InngestFunction";
|
|
6
6
|
/**
|
|
7
7
|
* A middleware that can be registered with Inngest to hook into various
|
|
8
8
|
* lifecycles of the SDK and affect input and output of Inngest functionality.
|
|
9
9
|
*
|
|
10
|
-
* TODO Add docs and shortlink.
|
|
11
|
-
*
|
|
12
10
|
* See {@link https://innge.st/middleware}
|
|
13
11
|
*
|
|
14
12
|
* @example
|
|
@@ -18,7 +16,7 @@ import { type InngestFunction } from "./InngestFunction";
|
|
|
18
16
|
* middleware: [
|
|
19
17
|
* new InngestMiddleware({
|
|
20
18
|
* name: "My Middleware",
|
|
21
|
-
*
|
|
19
|
+
* init: () => {
|
|
22
20
|
* // ...
|
|
23
21
|
* }
|
|
24
22
|
* })
|
|
@@ -61,6 +59,7 @@ type PromisifiedFunctionRecord<TRecord extends Record<string, (arg: any) => any>
|
|
|
61
59
|
[K in keyof TRecord]: (...args: Parameters<TRecord[K]>) => Promise<Parameters<TRecord[K]>[0]>;
|
|
62
60
|
}>, keyof FnsWithSameInputAsOutput<TRecord>>;
|
|
63
61
|
export type RunHookStack = PromisifiedFunctionRecord<Await<MiddlewareRegisterReturn["onFunctionRun"]>>;
|
|
62
|
+
export type SendEventHookStack = PromisifiedFunctionRecord<Await<MiddlewareRegisterReturn["onSendEvent"]>>;
|
|
64
63
|
/**
|
|
65
64
|
* Given some middleware and an entrypoint, runs the initializer for the given
|
|
66
65
|
* `key` and returns functions that will pass arguments through a stack of each
|
|
@@ -180,9 +179,6 @@ export type MiddlewareRegisterReturn = {
|
|
|
180
179
|
* The `output` hook is called after the event has been sent to Inngest.
|
|
181
180
|
* This is where you can perform any final actions after the event has
|
|
182
181
|
* been sent to Inngest and can modify the output the SDK sees.
|
|
183
|
-
*
|
|
184
|
-
* TODO This needs to be a result object that we spread into, not just some
|
|
185
|
-
* unknown value.
|
|
186
182
|
*/
|
|
187
183
|
transformOutput?: MiddlewareSendEventOutput;
|
|
188
184
|
}>;
|
|
@@ -193,17 +189,13 @@ export type MiddlewareRegisterReturn = {
|
|
|
193
189
|
export type MiddlewareRegisterFn = (ctx: {
|
|
194
190
|
/**
|
|
195
191
|
* The client this middleware is being registered on.
|
|
196
|
-
*
|
|
197
|
-
* TODO This should not use `any`, but the generic type expected.
|
|
198
192
|
*/
|
|
199
|
-
client:
|
|
193
|
+
client: AnyInngest;
|
|
200
194
|
/**
|
|
201
195
|
* If defined, this middleware has been applied directly to an Inngest
|
|
202
196
|
* function rather than on the client.
|
|
203
|
-
*
|
|
204
|
-
* TODO This should not use `any`, but the generic type expected.
|
|
205
197
|
*/
|
|
206
|
-
fn?:
|
|
198
|
+
fn?: AnyInngestFunction;
|
|
207
199
|
}) => MaybePromise<MiddlewareRegisterReturn>;
|
|
208
200
|
/**
|
|
209
201
|
* A blank, no-op hook that passes nothing and expects nothing in return.
|
|
@@ -221,17 +213,15 @@ type MiddlewareRunArgs = Readonly<{
|
|
|
221
213
|
* The context object that will be passed to the function. This contains
|
|
222
214
|
* event data, some contextual data such as the run's ID, and step tooling.
|
|
223
215
|
*/
|
|
224
|
-
ctx: Record<string, unknown> & Readonly<BaseContext<ClientOptions, string
|
|
216
|
+
ctx: Record<string, unknown> & Readonly<BaseContext<ClientOptions, string>>;
|
|
225
217
|
/**
|
|
226
218
|
* The step data that will be passed to the function.
|
|
227
219
|
*/
|
|
228
|
-
steps: Readonly<
|
|
220
|
+
steps: Readonly<IncomingOp>[];
|
|
229
221
|
/**
|
|
230
222
|
* The function that is being executed.
|
|
231
|
-
*
|
|
232
|
-
* TODO This should not use `any`, but the generic type expected.
|
|
233
223
|
*/
|
|
234
|
-
fn:
|
|
224
|
+
fn: AnyInngestFunction;
|
|
235
225
|
}>;
|
|
236
226
|
/**
|
|
237
227
|
* The specific arguments sent to the `run` hook when an execution has begun.
|
|
@@ -258,11 +248,11 @@ type MiddlewareRunInput = (ctx: MiddlewareRunArgs) => MaybePromise<{
|
|
|
258
248
|
steps?: Pick<IncomingOp, "data">[];
|
|
259
249
|
} | void>;
|
|
260
250
|
/**
|
|
261
|
-
* Arguments
|
|
251
|
+
* Arguments for the SendEventInput hook
|
|
262
252
|
*
|
|
263
253
|
* @internal
|
|
264
254
|
*/
|
|
265
|
-
type
|
|
255
|
+
type MiddlewareSendEventInputArgs = Readonly<{
|
|
266
256
|
payloads: ReadonlyArray<EventPayload>;
|
|
267
257
|
}>;
|
|
268
258
|
/**
|
|
@@ -271,23 +261,33 @@ type MiddlewareSendEventArgs = Readonly<{
|
|
|
271
261
|
*
|
|
272
262
|
* @internal
|
|
273
263
|
*/
|
|
274
|
-
type MiddlewareSendEventInput = (ctx:
|
|
264
|
+
type MiddlewareSendEventInput = (ctx: MiddlewareSendEventInputArgs) => MaybePromise<{
|
|
275
265
|
payloads?: EventPayload[];
|
|
276
266
|
} | void>;
|
|
267
|
+
/**
|
|
268
|
+
* Arguments for the SendEventOutput hook
|
|
269
|
+
*
|
|
270
|
+
* @internal
|
|
271
|
+
*/
|
|
272
|
+
type MiddlewareSendEventOutputArgs = {
|
|
273
|
+
result: Readonly<SendEventBaseOutput>;
|
|
274
|
+
};
|
|
277
275
|
/**
|
|
278
276
|
* The shape of an `output` hook within a `sendEvent`, optionally returning a
|
|
279
277
|
* change to the result value.
|
|
280
278
|
*/
|
|
281
|
-
type MiddlewareSendEventOutput = (ctx:
|
|
279
|
+
type MiddlewareSendEventOutput = (ctx: MiddlewareSendEventOutputArgs) => MaybePromise<{
|
|
280
|
+
result?: Record<string, unknown>;
|
|
281
|
+
} | void>;
|
|
282
282
|
/**
|
|
283
283
|
* @internal
|
|
284
284
|
*/
|
|
285
285
|
type MiddlewareRunOutput = (ctx: {
|
|
286
286
|
result: Readonly<Pick<OutgoingOp, "error" | "data">>;
|
|
287
287
|
step?: Readonly<Omit<OutgoingOp, "id">>;
|
|
288
|
-
}) => {
|
|
288
|
+
}) => MaybePromise<{
|
|
289
289
|
result?: Partial<Pick<OutgoingOp, "data">>;
|
|
290
|
-
} | void
|
|
290
|
+
} | void>;
|
|
291
291
|
/**
|
|
292
292
|
* @internal
|
|
293
293
|
*/
|
|
@@ -299,6 +299,17 @@ type GetMiddlewareRunInputMutation<TMiddleware extends InngestMiddleware<Middlew
|
|
|
299
299
|
/**
|
|
300
300
|
* @internal
|
|
301
301
|
*/
|
|
302
|
+
type GetMiddlewareSendEventOutputMutation<TMiddleware extends InngestMiddleware<MiddlewareOptions>> = TMiddleware extends InngestMiddleware<infer TOpts> ? TOpts["init"] extends MiddlewareRegisterFn ? Await<Await<Await<TOpts["init"]>["onSendEvent"]>["transformOutput"]> extends {
|
|
303
|
+
result: infer TResult;
|
|
304
|
+
} ? {
|
|
305
|
+
[K in keyof TResult]: TResult[K];
|
|
306
|
+
} : {} : {} : {};
|
|
307
|
+
/**
|
|
308
|
+
* @internal
|
|
309
|
+
*/
|
|
310
|
+
export type MiddlewareStackSendEventOutputMutation<TContext, TMiddleware extends MiddlewareStack> = ObjectAssign<{
|
|
311
|
+
[K in keyof TMiddleware]: GetMiddlewareSendEventOutputMutation<TMiddleware[K]>;
|
|
312
|
+
}, TContext>;
|
|
302
313
|
export type ExtendWithMiddleware<TMiddlewareStacks extends MiddlewareStack[], TContext = {}> = ObjectAssign<{
|
|
303
314
|
[K in keyof TMiddlewareStacks]: MiddlewareStackRunInputMutation<{}, TMiddlewareStacks[K]>;
|
|
304
315
|
}, TContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestMiddleware.d.ts","sourceRoot":"","sources":["../../src/components/InngestMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EACL,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK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CAAsC,CAChD,QAAQ,EACR,WAAW,SAAS,eAAe,IACjC,YAAY,CACd;KACG,CAAC,IAAI,MAAM,WAAW,GAAG,oCAAoC,CAC5D,WAAW,CAAC,CAAC,CAAC,CACf;CACF,EACD,QAAQ,CACT,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAC9B,iBAAiB,SAAS,eAAe,EAAE,EAE3C,QAAQ,GAAG,EAAE,IACX,YAAY,CACd;KACG,CAAC,IAAI,MAAM,iBAAiB,GAAG,+BAA+B,CAE7D,EAAE,EACF,iBAAiB,CAAC,CAAC,CAAC,CACrB;CACF,EACD,QAAQ,CACT,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,CACzC,QAAQ,EACR,WAAW,SAAS,eAAe,IACjC,YAAY,CACd;KACG,CAAC,IAAI,MAAM,WAAW,GAAG,6BAA6B,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CACxE,EACD,QAAQ,CACT,CAAC"}
|
|
@@ -6,8 +6,6 @@ const functions_1 = require("../helpers/functions");
|
|
|
6
6
|
* A middleware that can be registered with Inngest to hook into various
|
|
7
7
|
* lifecycles of the SDK and affect input and output of Inngest functionality.
|
|
8
8
|
*
|
|
9
|
-
* TODO Add docs and shortlink.
|
|
10
|
-
*
|
|
11
9
|
* See {@link https://innge.st/middleware}
|
|
12
10
|
*
|
|
13
11
|
* @example
|
|
@@ -17,7 +15,7 @@ const functions_1 = require("../helpers/functions");
|
|
|
17
15
|
* middleware: [
|
|
18
16
|
* new InngestMiddleware({
|
|
19
17
|
* name: "My Middleware",
|
|
20
|
-
*
|
|
18
|
+
* init: () => {
|
|
21
19
|
* // ...
|
|
22
20
|
* }
|
|
23
21
|
* })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestMiddleware.js","sourceRoot":"","sources":["../../src/components/InngestMiddleware.ts"],"names":[],"mappings":";;;AACA,oDAA0D;
|
|
1
|
+
{"version":3,"file":"InngestMiddleware.js","sourceRoot":"","sources":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AAI,CAAC,IAAI,CAAmB,CAAC;QAErD,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;YAC1B,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAEtB,MAAM,iBAAiB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,iBAAiB,EAAE;gBACrB,GAAG,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;aACtC;YAED,MAAM,SAAS,GAAG,UAAU,CAAC,GAA8B,CAEtB,CAAC;YAEtC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAA,qBAAS,EAAC,GAAG,EAAE,SAAS,CAAqB,CAAC;SAC1D;KACF;IAED,0EAA0E;IAC1E,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAChC,MAAM,GAAG,GAAG,CAAqB,CAAC;QAElC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAA,mBAAO,EAChB,GAAG,CAAC,GAAG,CAAoC,CACb,CAAC;KAClC;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAhGW,QAAA,YAAY,gBAgGvB"}
|
|
@@ -1,14 +1,62 @@
|
|
|
1
1
|
import { type Jsonify } from "type-fest";
|
|
2
|
-
import { type ObjectPaths, type SendEventPayload } from "../helpers/types";
|
|
3
|
-
import {
|
|
2
|
+
import { type ExclusiveKeys, type ObjectPaths, type ParametersExceptFirst, type SendEventPayload } from "../helpers/types";
|
|
3
|
+
import { type ClientOptions, type EventPayload, type HashedOp, type SendEventOutput, type StepOptions, type StepOptionsOrId } from "../types";
|
|
4
4
|
import { type EventsFromOpts, type Inngest } from "./Inngest";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export interface FoundStep extends HashedOp {
|
|
6
|
+
hashedId: string;
|
|
7
7
|
fn?: (...args: unknown[]) => unknown;
|
|
8
8
|
fulfilled: boolean;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
handled: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a boolean representing whether or not the step was handled on this
|
|
12
|
+
* invocation.
|
|
13
|
+
*/
|
|
14
|
+
handle: () => boolean;
|
|
11
15
|
}
|
|
16
|
+
export type MatchOpFn<T extends (...args: unknown[]) => Promise<unknown> = (...args: unknown[]) => Promise<unknown>> = (stepOptions: StepOptions,
|
|
17
|
+
/**
|
|
18
|
+
* Arguments passed by the user.
|
|
19
|
+
*/
|
|
20
|
+
...args: ParametersExceptFirst<T>) => Omit<HashedOp, "data" | "error">;
|
|
21
|
+
export type StepHandler = (info: {
|
|
22
|
+
matchOp: MatchOpFn;
|
|
23
|
+
opts?: StepToolOptions;
|
|
24
|
+
args: [StepOptionsOrId, ...unknown[]];
|
|
25
|
+
}) => Promise<unknown>;
|
|
26
|
+
export interface StepToolOptions<T extends (...args: unknown[]) => Promise<unknown> = (...args: unknown[]) => Promise<unknown>> {
|
|
27
|
+
/**
|
|
28
|
+
* Optionally, we can also provide a function that will be called when
|
|
29
|
+
* Inngest tells us to run this operation.
|
|
30
|
+
*
|
|
31
|
+
* If this function is defined, the first time the tool is used it will
|
|
32
|
+
* report the desired operation (including options) to the Inngest. Inngest
|
|
33
|
+
* will then call back to the function to tell it to run the step and then
|
|
34
|
+
* retrieve data.
|
|
35
|
+
*
|
|
36
|
+
* We do this in order to allow functionality such as per-step retries; this
|
|
37
|
+
* gives the SDK the opportunity to tell Inngest what it wants to do before
|
|
38
|
+
* it does it.
|
|
39
|
+
*
|
|
40
|
+
* This function is passed the arguments passed by the user. It will be run
|
|
41
|
+
* when we receive an operation matching this one that does not contain a
|
|
42
|
+
* `data` property.
|
|
43
|
+
*/
|
|
44
|
+
fn?: (...args: Parameters<T>) => unknown;
|
|
45
|
+
/**
|
|
46
|
+
* If `true` and we have detected that this is a non-step function, the
|
|
47
|
+
* provided `fn` will be called and the result returned immediately
|
|
48
|
+
* instead of being executed later.
|
|
49
|
+
*
|
|
50
|
+
* If no `fn` is provided to the tool, this will throw the same error as
|
|
51
|
+
* if this setting was `false`.
|
|
52
|
+
*/
|
|
53
|
+
nonStepExecuteInline?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export declare const getStepOptions: (options: StepOptionsOrId) => StepOptions;
|
|
56
|
+
/**
|
|
57
|
+
* Suffix used to namespace steps that are automatically indexed.
|
|
58
|
+
*/
|
|
59
|
+
export declare const STEP_INDEXING_SUFFIX = ":";
|
|
12
60
|
/**
|
|
13
61
|
* Create a new set of step function tools ready to be used in a step function.
|
|
14
62
|
* This function should be run and a fresh set of tools provided every time a
|
|
@@ -17,7 +65,7 @@ export interface TickOp extends HashedOp {
|
|
|
17
65
|
* An op stack (function state) is passed in as well as some mutable properties
|
|
18
66
|
* that the tools can use to submit a new op.
|
|
19
67
|
*/
|
|
20
|
-
export declare const createStepTools: <TOpts extends ClientOptions, Events extends EventsFromOpts<TOpts>, TriggeringEvent extends keyof Events & string>(client: Inngest<TOpts>,
|
|
68
|
+
export declare const createStepTools: <TOpts extends ClientOptions, Events extends EventsFromOpts<TOpts>, TriggeringEvent extends keyof Events & string>(client: Inngest<TOpts>, stepHandler: StepHandler) => {
|
|
21
69
|
/**
|
|
22
70
|
* Send one or many events to Inngest. Should always be used in place of
|
|
23
71
|
* `inngest.send()` to ensure that the event send is successfully retried
|
|
@@ -43,7 +91,11 @@ export declare const createStepTools: <TOpts extends ClientOptions, Events exten
|
|
|
43
91
|
*
|
|
44
92
|
* Returns a promise that will resolve once the event has been sent.
|
|
45
93
|
*/
|
|
46
|
-
sendEvent: <Payload extends SendEventPayload<EventsFromOpts<TOpts>>>(
|
|
94
|
+
sendEvent: <Payload extends SendEventPayload<EventsFromOpts<TOpts>>>(idOrOptions: StepOptionsOrId, payload: Payload) => Promise<import("type-fest").Simplify<import("type-fest").Simplify<Omit<Omit<import("../types").SendEventBaseOutput, never> & import("type-fest").Simplify<Omit<{}, never> | (Omit<{}, never> & {})>, keyof import("../helpers/types").ObjectAssign<NonNullable<TOpts["middleware"]> extends infer T extends import("../types").MiddlewareStack ? { [K in keyof T]: NonNullable<TOpts["middleware"]>[K] extends infer T_1 ? T_1 extends NonNullable<TOpts["middleware"]>[K] ? T_1 extends import("./InngestMiddleware").InngestMiddleware<infer TOpts_1 extends import("./InngestMiddleware").MiddlewareOptions> ? TOpts_1["init"] extends import("./InngestMiddleware").MiddlewareRegisterFn ? import("../helpers/types").Await<import("../helpers/types").Await<import("../helpers/types").Await<TOpts_1["init"]>["onSendEvent"]>["transformOutput"]> extends {
|
|
95
|
+
result: infer TResult;
|
|
96
|
+
} ? { [K_1 in keyof TResult]: TResult[K_1]; } : {} : {} : {} : never : never; } : never, {}>> & import("../helpers/types").ObjectAssign<NonNullable<TOpts["middleware"]> extends infer T_2 extends import("../types").MiddlewareStack ? { [K in keyof T_2]: NonNullable<TOpts["middleware"]>[K] extends infer T_3 ? T_3 extends NonNullable<TOpts["middleware"]>[K] ? T_3 extends import("./InngestMiddleware").InngestMiddleware<infer TOpts_1 extends import("./InngestMiddleware").MiddlewareOptions> ? TOpts_1["init"] extends import("./InngestMiddleware").MiddlewareRegisterFn ? import("../helpers/types").Await<import("../helpers/types").Await<import("../helpers/types").Await<TOpts_1["init"]>["onSendEvent"]>["transformOutput"]> extends {
|
|
97
|
+
result: infer TResult;
|
|
98
|
+
} ? { [K_1 in keyof TResult]: TResult[K_1]; } : {} : {} : {} : never : never; } : never, {}>>>>;
|
|
47
99
|
/**
|
|
48
100
|
* Wait for a particular event to be received before continuing. When the
|
|
49
101
|
* event is received, it will be returned.
|
|
@@ -53,11 +105,7 @@ export declare const createStepTools: <TOpts extends ClientOptions, Events exten
|
|
|
53
105
|
* events, or to only wait a maximum amount of time before giving up and
|
|
54
106
|
* returning `null` instead of any event data.
|
|
55
107
|
*/
|
|
56
|
-
waitForEvent: <IncomingEvent extends
|
|
57
|
-
if?: undefined;
|
|
58
|
-
}) | ((IncomingEvent extends keyof Events ? WaitForEventOpts<Events[TriggeringEvent], Events[IncomingEvent]> : IncomingEvent extends EventPayload ? WaitForEventOpts<Events[TriggeringEvent], IncomingEvent> : never) & {
|
|
59
|
-
match?: undefined;
|
|
60
|
-
})) => Promise<IncomingEvent extends keyof Events ? Events[IncomingEvent] | null : IncomingEvent | null>;
|
|
108
|
+
waitForEvent: <IncomingEvent extends keyof Events & string>(idOrOptions: StepOptionsOrId, opts: WaitForEventOpts<Events, TriggeringEvent, IncomingEvent>) => Promise<IncomingEvent extends keyof Events ? Events[IncomingEvent] | null : IncomingEvent | null>;
|
|
61
109
|
/**
|
|
62
110
|
* Use this tool to run business logic. Each call to `run` will be retried
|
|
63
111
|
* individually, meaning you can compose complex workflows that safely
|
|
@@ -70,7 +118,7 @@ export declare const createStepTools: <TOpts extends ClientOptions, Events exten
|
|
|
70
118
|
* of the `run` tool, meaning you can return and reason about return data
|
|
71
119
|
* for next steps.
|
|
72
120
|
*/
|
|
73
|
-
run: <
|
|
121
|
+
run: <T_4 extends () => unknown>(idOrOptions: StepOptionsOrId, fn: T_4) => Promise<Jsonify<T_4 extends () => Promise<infer U> ? Awaited<U extends void ? null : U> : ReturnType<T_4> extends void ? null : ReturnType<T_4>>>;
|
|
74
122
|
/**
|
|
75
123
|
* Wait a specified amount of time before continuing.
|
|
76
124
|
*
|
|
@@ -81,20 +129,21 @@ export declare const createStepTools: <TOpts extends ClientOptions, Events exten
|
|
|
81
129
|
*
|
|
82
130
|
* To wait until a particular date, use `sleepUntil` instead.
|
|
83
131
|
*/
|
|
84
|
-
sleep: (time: number | string
|
|
132
|
+
sleep: (idOrOptions: StepOptionsOrId, time: number | string) => Promise<void>;
|
|
85
133
|
/**
|
|
86
134
|
* Wait until a particular date before continuing by passing a `Date`.
|
|
87
135
|
*
|
|
88
136
|
* To wait for a particular amount of time from now, always use `sleep`
|
|
89
137
|
* instead.
|
|
90
138
|
*/
|
|
91
|
-
sleepUntil: (time: Date | string
|
|
139
|
+
sleepUntil: (idOrOptions: StepOptionsOrId, time: Date | string) => Promise<void>;
|
|
92
140
|
};
|
|
93
141
|
/**
|
|
94
142
|
* A set of optional parameters given to a `waitForEvent` call to control how
|
|
95
143
|
* the event is handled.
|
|
96
144
|
*/
|
|
97
|
-
|
|
145
|
+
type WaitForEventOpts<Events extends Record<string, EventPayload>, TriggeringEvent extends keyof Events, IncomingEvent extends keyof Events> = {
|
|
146
|
+
event: IncomingEvent;
|
|
98
147
|
/**
|
|
99
148
|
* The step function will wait for the event for a maximum of this time, at
|
|
100
149
|
* which point the event will be returned as `null` instead of any event data.
|
|
@@ -106,6 +155,7 @@ interface WaitForEventOpts<TriggeringEvent extends EventPayload, IncomingEvent e
|
|
|
106
155
|
* {@link https://npm.im/ms}
|
|
107
156
|
*/
|
|
108
157
|
timeout: number | string | Date;
|
|
158
|
+
} & ExclusiveKeys<{
|
|
109
159
|
/**
|
|
110
160
|
* If provided, the step function will wait for the incoming event to match
|
|
111
161
|
* particular criteria. If the event does not match, it will be ignored and
|
|
@@ -127,7 +177,7 @@ interface WaitForEventOpts<TriggeringEvent extends EventPayload, IncomingEvent e
|
|
|
127
177
|
*
|
|
128
178
|
* {@link https://www.inngest.com/docs/functions/expressions}
|
|
129
179
|
*/
|
|
130
|
-
match?: ObjectPaths<TriggeringEvent> & ObjectPaths<IncomingEvent>;
|
|
180
|
+
match?: ObjectPaths<Events[TriggeringEvent]> & ObjectPaths<Events[IncomingEvent]>;
|
|
131
181
|
/**
|
|
132
182
|
* If provided, the step function will wait for the incoming event to match
|
|
133
183
|
* the given condition. If the event does not match, it will be ignored and
|
|
@@ -141,24 +191,6 @@ interface WaitForEventOpts<TriggeringEvent extends EventPayload, IncomingEvent e
|
|
|
141
191
|
* {@link https://www.inngest.com/docs/functions/expressions}
|
|
142
192
|
*/
|
|
143
193
|
if?: string;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* An operation ready to hash to be used to memoise step function progress.
|
|
147
|
-
*
|
|
148
|
-
* @internal
|
|
149
|
-
*/
|
|
150
|
-
export type UnhashedOp = {
|
|
151
|
-
name: string;
|
|
152
|
-
op: StepOpCode;
|
|
153
|
-
opts: Record<string, unknown> | null;
|
|
154
|
-
parent: string | null;
|
|
155
|
-
pos?: number;
|
|
156
|
-
};
|
|
157
|
-
/**
|
|
158
|
-
* Exported for testing.
|
|
159
|
-
*/
|
|
160
|
-
export declare const _internals: {
|
|
161
|
-
hashData: (op: UnhashedOp) => string;
|
|
162
|
-
};
|
|
194
|
+
}, "match", "if">;
|
|
163
195
|
export {};
|
|
164
196
|
//# sourceMappingURL=InngestStepTools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestStepTools.d.ts","sourceRoot":"","sources":["../../src/components/InngestStepTools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InngestStepTools.d.ts","sourceRoot":"","sources":["../../src/components/InngestStepTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9D,MAAM,WAAW,SAAU,SAAQ,QAAQ;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,MAAM,EAAE,MAAM,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,SA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;yBAGc,eAAe,QAKtB,MAAM,GAAG,MAAM,KAClB,QAAQ,IAAI,CAAC;IAcpB;;;;;OAKG;8BAGc,eAAe,QAKtB,IAAI,GAAG,MAAM,KAChB,QAAQ,IAAI,CAAC;CAgCvB,CAAC;AAEF;;;GAGG;AACH,KAAK,gBAAgB,CACnB,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAC3C,eAAe,SAAS,MAAM,MAAM,EACpC,aAAa,SAAS,MAAM,MAAM,IAChC;IACF,KAAK,EAAE,aAAa,CAAC;IAErB;;;;;;;;;OASG;IACH,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACjC,GAAG,aAAa,CACf;IACE;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,GAC1C,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IAErC;;;;;;;;;;;OAWG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,EACD,OAAO,EACP,IAAI,CACL,CAAC"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const canonicalize_1 = __importDefault(require("canonicalize"));
|
|
8
|
-
const hash_js_1 = require("hash.js");
|
|
9
|
-
const errors_1 = require("../helpers/errors");
|
|
3
|
+
exports.createStepTools = exports.STEP_INDEXING_SUFFIX = exports.getStepOptions = void 0;
|
|
10
4
|
const strings_1 = require("../helpers/strings");
|
|
11
5
|
const types_1 = require("../types");
|
|
12
|
-
const
|
|
6
|
+
const getStepOptions = (options) => {
|
|
7
|
+
if (typeof options === "string") {
|
|
8
|
+
return { id: options };
|
|
9
|
+
}
|
|
10
|
+
return options;
|
|
11
|
+
};
|
|
12
|
+
exports.getStepOptions = getStepOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Suffix used to namespace steps that are automatically indexed.
|
|
15
|
+
*/
|
|
16
|
+
exports.STEP_INDEXING_SUFFIX = ":";
|
|
13
17
|
/**
|
|
14
18
|
* Create a new set of step function tools ready to be used in a step function.
|
|
15
19
|
* This function should be run and a fresh set of tools provided every time a
|
|
@@ -18,42 +22,7 @@ const NonRetriableError_1 = require("./NonRetriableError");
|
|
|
18
22
|
* An op stack (function state) is passed in as well as some mutable properties
|
|
19
23
|
* that the tools can use to submit a new op.
|
|
20
24
|
*/
|
|
21
|
-
const createStepTools = (client,
|
|
22
|
-
// Start referencing everything
|
|
23
|
-
state.tickOps = state.allFoundOps;
|
|
24
|
-
/**
|
|
25
|
-
* Create a unique hash of an operation using only a subset of the operation's
|
|
26
|
-
* properties; will never use `data` and will guarantee the order of the
|
|
27
|
-
* object so we don't rely on individual tools for that.
|
|
28
|
-
*
|
|
29
|
-
* If the operation already contains an ID, the current ID will be used
|
|
30
|
-
* instead, so that users can provide their own IDs.
|
|
31
|
-
*/
|
|
32
|
-
const hashOp = (
|
|
33
|
-
/**
|
|
34
|
-
* The op to generate a hash from. We only use a subset of the op's
|
|
35
|
-
* properties when creating the hash.
|
|
36
|
-
*/
|
|
37
|
-
op) => {
|
|
38
|
-
var _a, _b, _c, _d;
|
|
39
|
-
/**
|
|
40
|
-
* If the op already has an ID, we don't need to generate one. This allows
|
|
41
|
-
* users to specify their own IDs.
|
|
42
|
-
*/
|
|
43
|
-
if (op.id) {
|
|
44
|
-
return op;
|
|
45
|
-
}
|
|
46
|
-
const obj = {
|
|
47
|
-
parent: (_b = (_a = state.currentOp) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null,
|
|
48
|
-
op: op.op,
|
|
49
|
-
name: op.name,
|
|
50
|
-
opts: (_c = op.opts) !== null && _c !== void 0 ? _c : null,
|
|
51
|
-
};
|
|
52
|
-
const collisionHash = exports._internals.hashData(obj);
|
|
53
|
-
const pos = (state.tickOpHashes[collisionHash] =
|
|
54
|
-
((_d = state.tickOpHashes[collisionHash]) !== null && _d !== void 0 ? _d : -1) + 1);
|
|
55
|
-
return Object.assign(Object.assign({}, op), { id: exports._internals.hashData(Object.assign({ pos }, obj)) });
|
|
56
|
-
};
|
|
25
|
+
const createStepTools = (client, stepHandler) => {
|
|
57
26
|
/**
|
|
58
27
|
* A local helper used to create tools that can be used to submit an op.
|
|
59
28
|
*
|
|
@@ -72,30 +41,9 @@ const createStepTools = (client, state) => {
|
|
|
72
41
|
* Most simple tools will likely only need to define this.
|
|
73
42
|
*/
|
|
74
43
|
matchOp, opts) => {
|
|
75
|
-
return ((...args) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return Promise.resolve(opts.fn(...args));
|
|
79
|
-
}
|
|
80
|
-
throw new NonRetriableError_1.NonRetriableError((0, errors_1.functionStoppedRunningErr)(errors_1.ErrCode.STEP_USED_AFTER_ASYNC));
|
|
81
|
-
}
|
|
82
|
-
if (state.executingStep) {
|
|
83
|
-
throw new NonRetriableError_1.NonRetriableError((0, errors_1.prettyError)({
|
|
84
|
-
whatHappened: "Your function was stopped from running",
|
|
85
|
-
why: "We detected that you have nested `step.*` tooling.",
|
|
86
|
-
consequences: "Nesting `step.*` tooling is not supported.",
|
|
87
|
-
stack: true,
|
|
88
|
-
toFixNow: "Make sure you're not using `step.*` tooling inside of other `step.*` tooling. If you need to compose steps together, you can create a new async function and call it from within your step function, or use promise chaining.",
|
|
89
|
-
otherwise: "For more information on step functions with Inngest, see https://www.inngest.com/docs/functions/multi-step",
|
|
90
|
-
code: errors_1.ErrCode.NESTING_STEPS,
|
|
91
|
-
}));
|
|
92
|
-
}
|
|
93
|
-
state.hasUsedTools = true;
|
|
94
|
-
const opId = hashOp(matchOp(...args));
|
|
95
|
-
return new Promise((resolve, reject) => {
|
|
96
|
-
state.tickOps[opId.id] = Object.assign(Object.assign(Object.assign({}, opId), ((opts === null || opts === void 0 ? void 0 : opts.fn) ? { fn: () => { var _a; return (_a = opts.fn) === null || _a === void 0 ? void 0 : _a.call(opts, ...args); } } : {})), { resolve,
|
|
97
|
-
reject, fulfilled: false });
|
|
98
|
-
});
|
|
44
|
+
return (async (...args) => {
|
|
45
|
+
const parsedArgs = args;
|
|
46
|
+
return stepHandler({ args: parsedArgs, matchOp, opts });
|
|
99
47
|
});
|
|
100
48
|
};
|
|
101
49
|
/**
|
|
@@ -130,15 +78,16 @@ const createStepTools = (client, state) => {
|
|
|
130
78
|
*
|
|
131
79
|
* Returns a promise that will resolve once the event has been sent.
|
|
132
80
|
*/
|
|
133
|
-
sendEvent: createTool((
|
|
81
|
+
sendEvent: createTool(({ id, name }) => {
|
|
134
82
|
return {
|
|
135
|
-
id
|
|
83
|
+
id,
|
|
136
84
|
op: types_1.StepOpCode.StepPlanned,
|
|
137
85
|
name: "sendEvent",
|
|
86
|
+
displayName: name !== null && name !== void 0 ? name : id,
|
|
138
87
|
};
|
|
139
88
|
}, {
|
|
140
89
|
nonStepExecuteInline: true,
|
|
141
|
-
fn: (payload) => {
|
|
90
|
+
fn: (idOrOptions, payload) => {
|
|
142
91
|
return client.send(payload);
|
|
143
92
|
},
|
|
144
93
|
}),
|
|
@@ -151,22 +100,15 @@ const createStepTools = (client, state) => {
|
|
|
151
100
|
* events, or to only wait a maximum amount of time before giving up and
|
|
152
101
|
* returning `null` instead of any event data.
|
|
153
102
|
*/
|
|
154
|
-
waitForEvent: createTool((
|
|
155
|
-
/**
|
|
156
|
-
* The event name to wait for.
|
|
157
|
-
*/
|
|
158
|
-
event,
|
|
103
|
+
waitForEvent: createTool(({ id, name },
|
|
159
104
|
/**
|
|
160
105
|
* Options to control the event we're waiting for.
|
|
161
106
|
*/
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
163
107
|
opts) => {
|
|
164
108
|
const matchOpts = {
|
|
165
109
|
timeout: (0, strings_1.timeStr)(typeof opts === "string" ? opts : opts.timeout),
|
|
166
110
|
};
|
|
167
|
-
let id;
|
|
168
111
|
if (typeof opts !== "string") {
|
|
169
|
-
id = opts === null || opts === void 0 ? void 0 : opts.id;
|
|
170
112
|
if (opts === null || opts === void 0 ? void 0 : opts.match) {
|
|
171
113
|
matchOpts.if = `event.${opts.match} == async.${opts.match}`;
|
|
172
114
|
}
|
|
@@ -177,8 +119,9 @@ const createStepTools = (client, state) => {
|
|
|
177
119
|
return {
|
|
178
120
|
id,
|
|
179
121
|
op: types_1.StepOpCode.WaitForEvent,
|
|
180
|
-
name: event,
|
|
122
|
+
name: opts.event,
|
|
181
123
|
opts: matchOpts,
|
|
124
|
+
displayName: name !== null && name !== void 0 ? name : id,
|
|
182
125
|
};
|
|
183
126
|
}),
|
|
184
127
|
/**
|
|
@@ -193,13 +136,14 @@ const createStepTools = (client, state) => {
|
|
|
193
136
|
* of the `run` tool, meaning you can return and reason about return data
|
|
194
137
|
* for next steps.
|
|
195
138
|
*/
|
|
196
|
-
run: createTool((
|
|
139
|
+
run: createTool(({ id, name }) => {
|
|
197
140
|
return {
|
|
198
|
-
id
|
|
141
|
+
id,
|
|
199
142
|
op: types_1.StepOpCode.StepPlanned,
|
|
200
|
-
name,
|
|
143
|
+
name: id,
|
|
144
|
+
displayName: name !== null && name !== void 0 ? name : id,
|
|
201
145
|
};
|
|
202
|
-
}, { fn: (
|
|
146
|
+
}, { fn: (stepOptions, fn) => fn() }),
|
|
203
147
|
/**
|
|
204
148
|
* Wait a specified amount of time before continuing.
|
|
205
149
|
*
|
|
@@ -210,15 +154,16 @@ const createStepTools = (client, state) => {
|
|
|
210
154
|
*
|
|
211
155
|
* To wait until a particular date, use `sleepUntil` instead.
|
|
212
156
|
*/
|
|
213
|
-
sleep: createTool((
|
|
157
|
+
sleep: createTool(({ id, name }, time) => {
|
|
214
158
|
/**
|
|
215
159
|
* The presence of this operation in the returned stack indicates that the
|
|
216
160
|
* sleep is over and we should continue execution.
|
|
217
161
|
*/
|
|
218
162
|
return {
|
|
219
|
-
id
|
|
163
|
+
id,
|
|
220
164
|
op: types_1.StepOpCode.Sleep,
|
|
221
165
|
name: (0, strings_1.timeStr)(time),
|
|
166
|
+
displayName: name !== null && name !== void 0 ? name : id,
|
|
222
167
|
};
|
|
223
168
|
}),
|
|
224
169
|
/**
|
|
@@ -227,7 +172,7 @@ const createStepTools = (client, state) => {
|
|
|
227
172
|
* To wait for a particular amount of time from now, always use `sleep`
|
|
228
173
|
* instead.
|
|
229
174
|
*/
|
|
230
|
-
sleepUntil: createTool((
|
|
175
|
+
sleepUntil: createTool(({ id, name }, time) => {
|
|
231
176
|
const date = typeof time === "string" ? new Date(time) : time;
|
|
232
177
|
/**
|
|
233
178
|
* The presence of this operation in the returned stack indicates that the
|
|
@@ -235,9 +180,10 @@ const createStepTools = (client, state) => {
|
|
|
235
180
|
*/
|
|
236
181
|
try {
|
|
237
182
|
return {
|
|
238
|
-
id
|
|
183
|
+
id,
|
|
239
184
|
op: types_1.StepOpCode.Sleep,
|
|
240
185
|
name: date.toISOString(),
|
|
186
|
+
displayName: name !== null && name !== void 0 ? name : id,
|
|
241
187
|
};
|
|
242
188
|
}
|
|
243
189
|
catch (err) {
|
|
@@ -255,11 +201,4 @@ const createStepTools = (client, state) => {
|
|
|
255
201
|
return tools;
|
|
256
202
|
};
|
|
257
203
|
exports.createStepTools = createStepTools;
|
|
258
|
-
const hashData = (op) => {
|
|
259
|
-
return (0, hash_js_1.sha1)().update((0, canonicalize_1.default)(op)).digest("hex");
|
|
260
|
-
};
|
|
261
|
-
/**
|
|
262
|
-
* Exported for testing.
|
|
263
|
-
*/
|
|
264
|
-
exports._internals = { hashData };
|
|
265
204
|
//# sourceMappingURL=InngestStepTools.js.map
|