inngest 0.7.0 → 0.7.1
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/cloudflare.js +1 -1
- package/cloudflare.js.map +1 -1
- package/components/Inngest.d.ts +45 -5
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +12 -3
- package/components/Inngest.js.map +1 -1
- package/components/InngestFunction.d.ts +22 -4
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +112 -30
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestStepTools.d.ts +126 -0
- package/components/InngestStepTools.d.ts.map +1 -0
- package/components/InngestStepTools.js +287 -0
- package/components/InngestStepTools.js.map +1 -0
- package/express.d.ts.map +1 -1
- package/express.js +20 -10
- package/express.js.map +1 -1
- package/helpers/func.d.ts +13 -3
- package/helpers/func.d.ts.map +1 -1
- package/helpers/func.js +29 -4
- package/helpers/func.js.map +1 -1
- package/helpers/strings.d.ts +8 -0
- package/helpers/strings.d.ts.map +1 -1
- package/helpers/strings.js +60 -1
- package/helpers/strings.js.map +1 -1
- package/helpers/types.d.ts +26 -0
- package/helpers/types.d.ts.map +1 -1
- package/index.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/landing.d.ts +1 -1
- package/landing.d.ts.map +1 -1
- package/landing.js +1 -1
- package/landing.js.map +1 -1
- package/next.js +1 -1
- package/next.js.map +1 -1
- package/package.json +7 -3
- package/redwood.js +1 -1
- package/redwood.js.map +1 -1
- package/remix.js +1 -1
- package/remix.js.map +1 -1
- package/types.d.ts +127 -11
- package/types.d.ts.map +1 -1
- package/types.js +11 -0
- package/types.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/components/InngestStep.d.ts +0 -15
- package/components/InngestStep.d.ts.map +0 -1
- package/components/InngestStep.js +0 -37
- package/components/InngestStep.js.map +0 -1
package/cloudflare.js
CHANGED
|
@@ -34,7 +34,7 @@ class CloudflareCommHandler extends express_1.InngestCommHandler {
|
|
|
34
34
|
switch (req.method) {
|
|
35
35
|
case "GET": {
|
|
36
36
|
const showLandingPage = this.shouldShowLandingPage(env[consts_1.envKeys.LandingPage]);
|
|
37
|
-
if (!showLandingPage)
|
|
37
|
+
if (this._isProd || !showLandingPage)
|
|
38
38
|
break;
|
|
39
39
|
if (isIntrospection) {
|
|
40
40
|
const introspection = Object.assign(Object.assign({}, this.registerBody(reqUrl)), { devServerURL: (0, devserver_1.devServerUrl)(env[consts_1.envKeys.DevServerUrl]).href, hasSigningKey: Boolean(this.signingKey) });
|
package/cloudflare.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../src/cloudflare.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,uCAImB;AACnB,6CAAsD;AACtD,mDAAmD;AACnD,uCAAoC;AAGpC,MAAM,qBAAsB,SAAQ,4BAAkB;IAAtD;;QACqB,kBAAa,GAAG,kBAAkB,CAAC;IA4GxD,CAAC;IA1GiB,aAAa;QAC3B,OAAO,KAAK,EAAE,EACZ,OAAO,EAAE,GAAG,EACZ,GAAG,GAIJ,EAAqB,EAAE;YACtB,MAAM,OAAO,GAAG,EAAE,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YAE7D,IAAI,MAAW,CAAC;YAChB,IAAI,eAAwB,CAAC;YAE7B,IAAI;gBACF,MAAM,GAAG,IAAI,CAAC,MAAM,CAClB,GAAG,CAAC,GAAG,EACP,WAAW,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAC3C,CAAC;gBAEF,eAAe,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,kBAAS,CAAC,UAAU,CAAC,CAAC;gBAChE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,kBAAS,CAAC,UAAU,CAAC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CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;4BACjD,MAAM,EAAE,OAAO,CAAC,MAAM;4BACtB,OAAO;yBACR,CAAC,CAAC;qBACJ;oBAED,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;wBAChD,MAAM,EAAE,OAAO,CAAC,MAAM;wBACtB,OAAO;qBACR,CAAC,CAAC;iBACJ;aACF;YAED,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QACtD,CAAC,CAAC;IACJ,CAAC;CACF;AAED;;;;;GAKG;AACI,MAAM,KAAK,GAAiB,CAAC,aAAa,EAAE,GAAG,EAAE,IAAI,EAAO,EAAE;IACnE,OAAO,IAAA,eAAY,EACjB,IAAI,qBAAqB,CAAC,aAAa,EAAE,GAAG,kBAC1C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAC1B,IAAI,EACP,CACH,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,KAAK,SAOhB"}
|
package/components/Inngest.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PartialK, SendEventPayload, SingleOrArray } from "../helpers/types";
|
|
2
|
-
import type { ClientOptions, EventPayload, FunctionOptions,
|
|
2
|
+
import type { ClientOptions, EventPayload, FunctionOptions, MultiStepFn, SingleStepFn } from "../types";
|
|
3
3
|
import { InngestFunction } from "./InngestFunction";
|
|
4
4
|
/**
|
|
5
5
|
* A client used to interact with the Inngest API by sending or reacting to
|
|
@@ -120,11 +120,51 @@ export declare class Inngest<Events extends Record<string, EventPayload>> {
|
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
122
|
send<Payload extends SendEventPayload<Events>>(payload: Payload): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Given an event to listen to, run the given step function when that event is
|
|
125
|
+
* seen.
|
|
126
|
+
*
|
|
127
|
+
* These can be used to build multi-step, serverless workflows with delays,
|
|
128
|
+
* conditional logic, and coordination between events.
|
|
129
|
+
*/
|
|
130
|
+
createStepFunction<Event extends keyof Events, Name extends string, Fn extends MultiStepFn<Events, Event, Name, "step">>(
|
|
131
|
+
/**
|
|
132
|
+
* The name of this function as it will appear in the Inngst Cloud UI.
|
|
133
|
+
*/
|
|
134
|
+
name: Name,
|
|
135
|
+
/**
|
|
136
|
+
* The event to listen for.
|
|
137
|
+
*/
|
|
138
|
+
event: Event,
|
|
139
|
+
/**
|
|
140
|
+
* The step function flow to run when the event is received.
|
|
141
|
+
*/
|
|
142
|
+
fn: Fn): InngestFunction<Events>;
|
|
143
|
+
/**
|
|
144
|
+
* Given an event to listen to, run the given step function when that event is
|
|
145
|
+
* seen.
|
|
146
|
+
*
|
|
147
|
+
* These can be used to build multi-step, serverless workflows with delays,
|
|
148
|
+
* conditional logic, and coordination between events.
|
|
149
|
+
*/
|
|
150
|
+
createStepFunction<Event extends keyof Events, Opts extends FunctionOptions, Fn extends MultiStepFn<Events, Event, Opts extends FunctionOptions ? Opts["name"] : string, "step">>(
|
|
151
|
+
/**
|
|
152
|
+
* Options for this Inngest function - useful for defining a custom ID.
|
|
153
|
+
*/
|
|
154
|
+
opts: Opts,
|
|
155
|
+
/**
|
|
156
|
+
* The event to listen for.
|
|
157
|
+
*/
|
|
158
|
+
event: Event,
|
|
159
|
+
/**
|
|
160
|
+
* The function to run when the event is received.
|
|
161
|
+
*/
|
|
162
|
+
fn: Fn): InngestFunction<Events>;
|
|
123
163
|
/**
|
|
124
164
|
* Given an event to listen to, run the given function when that event is
|
|
125
165
|
* seen.
|
|
126
166
|
*/
|
|
127
|
-
createFunction<Event extends keyof Events, Name extends string, Fn extends
|
|
167
|
+
createFunction<Event extends keyof Events, Name extends string, Fn extends SingleStepFn<Events[Event], Name, "step">>(
|
|
128
168
|
/**
|
|
129
169
|
* The name of this function as it will appear in the Inngst Cloud UI.
|
|
130
170
|
*/
|
|
@@ -141,7 +181,7 @@ export declare class Inngest<Events extends Record<string, EventPayload>> {
|
|
|
141
181
|
* Given an event to listen to, run the given function when that event is
|
|
142
182
|
* seen.
|
|
143
183
|
*/
|
|
144
|
-
createFunction<Event extends keyof Events, Opts extends FunctionOptions, Fn extends
|
|
184
|
+
createFunction<Event extends keyof Events, Opts extends FunctionOptions, Fn extends SingleStepFn<Events[Event], Opts extends FunctionOptions ? Opts["name"] : string, "step">>(
|
|
145
185
|
/**
|
|
146
186
|
* Options for this Inngest function - useful for defining a custom ID.
|
|
147
187
|
*/
|
|
@@ -176,7 +216,7 @@ export declare class Inngest<Events extends Record<string, EventPayload>> {
|
|
|
176
216
|
/**
|
|
177
217
|
* The function to run.
|
|
178
218
|
*/
|
|
179
|
-
fn:
|
|
219
|
+
fn: SingleStepFn<null, Name, "step">): InngestFunction<Events>;
|
|
180
220
|
/**
|
|
181
221
|
* Run the given `fn` at a specified time or on a schedule given by `cron`.
|
|
182
222
|
*/
|
|
@@ -199,6 +239,6 @@ export declare class Inngest<Events extends Record<string, EventPayload>> {
|
|
|
199
239
|
/**
|
|
200
240
|
* The function to run.
|
|
201
241
|
*/
|
|
202
|
-
fn:
|
|
242
|
+
fn: SingleStepFn<null, Opts extends FunctionOptions ? Opts["name"] : string, "step">): InngestFunction<Events>;
|
|
203
243
|
}
|
|
204
244
|
//# sourceMappingURL=Inngest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,QAAQ,EACR,gBAAgB,EAChB,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":"AAGA,OAAO,KA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CAAC,IAAI,SAAS,MAAM;IAChD;;OAEG;IACH,IAAI,EAAE,IAAI;IAEV;;;;;;;;;OASG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,EAAE,EAAE,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,GACnC,eAAe,CAAC,MAAM,CAAC;IAC1B;;OAEG;IACI,uBAAuB,CAAC,IAAI,SAAS,eAAe;IACzD;;OAEG;IACH,IAAI,EAAE,IAAI;IAEV;;;;;;;;;OASG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,EAAE,EAAE,YAAY,CACd,IAAI,EACJ,IAAI,SAAS,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,EACpD,MAAM,CACP,GACA,eAAe,CAAC,MAAM,CAAC;CAuB3B"}
|
package/components/Inngest.js
CHANGED
|
@@ -12,7 +12,6 @@ const devserver_1 = require("../helpers/devserver");
|
|
|
12
12
|
const env_1 = require("../helpers/env");
|
|
13
13
|
const version_1 = require("../version");
|
|
14
14
|
const InngestFunction_1 = require("./InngestFunction");
|
|
15
|
-
const InngestStep_1 = require("./InngestStep");
|
|
16
15
|
/**
|
|
17
16
|
* A client used to interact with the Inngest API by sending or reacting to
|
|
18
17
|
* events.
|
|
@@ -131,18 +130,28 @@ class Inngest {
|
|
|
131
130
|
}
|
|
132
131
|
throw await __classPrivateFieldGet(this, _Inngest_instances, "m", _Inngest_getResponseError).call(this, response);
|
|
133
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Given an event to listen to, run the given step function when that event is
|
|
135
|
+
* seen.
|
|
136
|
+
*
|
|
137
|
+
* These can be used to build multi-step, serverless workflows with delays,
|
|
138
|
+
* conditional logic, and coordination between events.
|
|
139
|
+
*/
|
|
140
|
+
createStepFunction(nameOrOpts, event, fn) {
|
|
141
|
+
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { event: event }, fn);
|
|
142
|
+
}
|
|
134
143
|
/**
|
|
135
144
|
* Given an event to listen to, run the given function when that event is
|
|
136
145
|
* seen.
|
|
137
146
|
*/
|
|
138
147
|
createFunction(nameOrOpts, event, fn) {
|
|
139
|
-
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { event: event },
|
|
148
|
+
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { event: event }, fn);
|
|
140
149
|
}
|
|
141
150
|
/**
|
|
142
151
|
* Run the given `fn` at a specified time or on a schedule given by `cron`.
|
|
143
152
|
*/
|
|
144
153
|
createScheduledFunction(nameOrOpts, cron, fn) {
|
|
145
|
-
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { cron },
|
|
154
|
+
return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { cron }, fn);
|
|
146
155
|
}
|
|
147
156
|
}
|
|
148
157
|
exports.Inngest = Inngest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inngest.js","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA4C;AAC5C,oDAAwE;AACxE,wCAAsE;
|
|
1
|
+
{"version":3,"file":"Inngest.js","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA4C;AAC5C,oDAAwE;AACxE,wCAAsE;AActE,wCAAqC;AACrC,uDAAoD;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,OAAO;IAwBlB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,YAAY,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,GAAG,iBAAiB,GACpB;;QACd,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;SACzE;QAED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AC,sBAAsB,QAAQ,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventPayload, FunctionOptions, FunctionTrigger
|
|
1
|
+
import { EventPayload, FunctionOptions, FunctionTrigger } from "../types";
|
|
2
2
|
/**
|
|
3
3
|
* A stateless Inngest function, wrapping up function configuration and any
|
|
4
4
|
* in-memory steps to run when triggered.
|
|
@@ -10,6 +10,7 @@ import { EventPayload, FunctionOptions, FunctionTrigger, Steps } from "../types"
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class InngestFunction<Events extends Record<string, EventPayload>> {
|
|
12
12
|
#private;
|
|
13
|
+
static stepId: string;
|
|
13
14
|
/**
|
|
14
15
|
* A stateless Inngest function, wrapping up function configuration and any
|
|
15
16
|
* in-memory steps to run when triggered.
|
|
@@ -21,7 +22,7 @@ export declare class InngestFunction<Events extends Record<string, EventPayload>
|
|
|
21
22
|
/**
|
|
22
23
|
* Options
|
|
23
24
|
*/
|
|
24
|
-
opts: FunctionOptions, trigger: FunctionTrigger<keyof Events>,
|
|
25
|
+
opts: FunctionOptions, trigger: FunctionTrigger<keyof Events>, fn: (...args: any[]) => any);
|
|
25
26
|
/**
|
|
26
27
|
* The generated or given ID for this function.
|
|
27
28
|
*/
|
|
@@ -35,8 +36,25 @@ export declare class InngestFunction<Events extends Record<string, EventPayload>
|
|
|
35
36
|
*/
|
|
36
37
|
private getConfig;
|
|
37
38
|
/**
|
|
38
|
-
* Run
|
|
39
|
+
* Run this function, optionally providing an op stack to pass as state.
|
|
40
|
+
*
|
|
41
|
+
* It is a `private` method to prevent users from being exposed to it
|
|
42
|
+
* directly, but ensuring it is available to the generated handler.
|
|
43
|
+
*
|
|
44
|
+
* For a single-step function that doesn't use any step tooling, this will
|
|
45
|
+
* await the result of the function given to this instance of
|
|
46
|
+
* `InngestFunction` and return the data and a boolean indicating that the
|
|
47
|
+
* function is complete and should not be called again.
|
|
48
|
+
*
|
|
49
|
+
* For a multi-step function, also try to await the result of the function
|
|
50
|
+
* given to this instance of `InngestFunction`, though will check whether an
|
|
51
|
+
* op has been submitted for use (or a Promise is pending, such as a step
|
|
52
|
+
* running) after the function has completed.
|
|
53
|
+
*
|
|
54
|
+
* In both cases, an unknown error (i.e. anything except a
|
|
55
|
+
* `StepFlowInterrupt` error) will bubble up to the caller, meaning the caller
|
|
56
|
+
* must handle what to do with the error.
|
|
39
57
|
*/
|
|
40
|
-
private
|
|
58
|
+
private runFn;
|
|
41
59
|
}
|
|
42
60
|
//# sourceMappingURL=InngestFunction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestFunction.d.ts","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EAEZ,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"InngestFunction.d.ts","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EAEZ,eAAe,EACf,eAAe,EAIhB,MAAM,UAAU,CAAC;AAGlB;;;;;;;;GAQG;AACH,qBAAa,eAAe,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;;IACtE,MAAM,CAAC,MAAM,SAAU;IAMvB;;;;;;OAMG;;IAED;;OAEG;IACH,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,eAAe,CAAC,MAAM,MAAM,CAAC,EACtC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG;IAO7B;;OAEG;IACI,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM;IAQzB;;OAEG;IACH,IAAW,IAAI,WAEd;IAED;;OAEG;IACH,OAAO,CAAC,SAAS;IAiCjB;;;;;;;;;;;;;;;;;;;OAmBG;YACW,KAAK;CA+FpB"}
|
|
@@ -10,11 +10,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _InngestFunction_instances, _InngestFunction_opts, _InngestFunction_trigger,
|
|
13
|
+
var _InngestFunction_instances, _InngestFunction_opts, _InngestFunction_trigger, _InngestFunction_fn, _InngestFunction_generateId;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.InngestFunction = void 0;
|
|
16
16
|
const consts_1 = require("../helpers/consts");
|
|
17
17
|
const strings_1 = require("../helpers/strings");
|
|
18
|
+
const InngestStepTools_1 = require("./InngestStepTools");
|
|
18
19
|
/**
|
|
19
20
|
* A stateless Inngest function, wrapping up function configuration and any
|
|
20
21
|
* in-memory steps to run when triggered.
|
|
@@ -36,14 +37,14 @@ class InngestFunction {
|
|
|
36
37
|
/**
|
|
37
38
|
* Options
|
|
38
39
|
*/
|
|
39
|
-
opts, trigger,
|
|
40
|
+
opts, trigger, fn) {
|
|
40
41
|
_InngestFunction_instances.add(this);
|
|
41
42
|
_InngestFunction_opts.set(this, void 0);
|
|
42
43
|
_InngestFunction_trigger.set(this, void 0);
|
|
43
|
-
|
|
44
|
+
_InngestFunction_fn.set(this, void 0);
|
|
44
45
|
__classPrivateFieldSet(this, _InngestFunction_opts, opts, "f");
|
|
45
46
|
__classPrivateFieldSet(this, _InngestFunction_trigger, trigger, "f");
|
|
46
|
-
__classPrivateFieldSet(this,
|
|
47
|
+
__classPrivateFieldSet(this, _InngestFunction_fn, fn, "f");
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* The generated or given ID for this function.
|
|
@@ -70,39 +71,120 @@ class InngestFunction {
|
|
|
70
71
|
* relies on an outside method providing context.
|
|
71
72
|
*/
|
|
72
73
|
baseUrl, appPrefix) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
url: url.href,
|
|
88
|
-
},
|
|
89
|
-
} });
|
|
90
|
-
}, {}),
|
|
91
|
-
};
|
|
74
|
+
const fnId = this.id(appPrefix);
|
|
75
|
+
const stepUrl = new URL(baseUrl.href);
|
|
76
|
+
stepUrl.searchParams.set(consts_1.queryKeys.FnId, fnId);
|
|
77
|
+
stepUrl.searchParams.set(consts_1.queryKeys.StepId, InngestFunction.stepId);
|
|
78
|
+
return Object.assign(Object.assign({}, __classPrivateFieldGet(this, _InngestFunction_opts, "f")), { id: fnId, name: this.name, triggers: [__classPrivateFieldGet(this, _InngestFunction_trigger, "f")], steps: {
|
|
79
|
+
[InngestFunction.stepId]: {
|
|
80
|
+
id: InngestFunction.stepId,
|
|
81
|
+
name: InngestFunction.stepId,
|
|
82
|
+
runtime: {
|
|
83
|
+
type: "http",
|
|
84
|
+
url: stepUrl.href,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
} });
|
|
92
88
|
}
|
|
93
89
|
/**
|
|
94
|
-
* Run
|
|
90
|
+
* Run this function, optionally providing an op stack to pass as state.
|
|
91
|
+
*
|
|
92
|
+
* It is a `private` method to prevent users from being exposed to it
|
|
93
|
+
* directly, but ensuring it is available to the generated handler.
|
|
94
|
+
*
|
|
95
|
+
* For a single-step function that doesn't use any step tooling, this will
|
|
96
|
+
* await the result of the function given to this instance of
|
|
97
|
+
* `InngestFunction` and return the data and a boolean indicating that the
|
|
98
|
+
* function is complete and should not be called again.
|
|
99
|
+
*
|
|
100
|
+
* For a multi-step function, also try to await the result of the function
|
|
101
|
+
* given to this instance of `InngestFunction`, though will check whether an
|
|
102
|
+
* op has been submitted for use (or a Promise is pending, such as a step
|
|
103
|
+
* running) after the function has completed.
|
|
104
|
+
*
|
|
105
|
+
* In both cases, an unknown error (i.e. anything except a
|
|
106
|
+
* `StepFlowInterrupt` error) will bubble up to the caller, meaning the caller
|
|
107
|
+
* must handle what to do with the error.
|
|
108
|
+
*/
|
|
109
|
+
async runFn(
|
|
110
|
+
/**
|
|
111
|
+
* The data to pass to the function, probably straight from Inngest.
|
|
95
112
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
data,
|
|
114
|
+
/**
|
|
115
|
+
* The op stack to pass to the function as state, likely stored in
|
|
116
|
+
* `ctx._state` in the Inngest payload.
|
|
117
|
+
*
|
|
118
|
+
* This must be provided in order to always be cognizant of step function
|
|
119
|
+
* state and to allow for multi-step functions.
|
|
120
|
+
*/
|
|
121
|
+
opStack) {
|
|
122
|
+
/**
|
|
123
|
+
* Create some values to be mutated and passed to the step tools. Once the
|
|
124
|
+
* user's function has run, we can check the mutated state of these to see
|
|
125
|
+
* if an op has been submitted or not.
|
|
126
|
+
*/
|
|
127
|
+
const [tools, state] = (0, InngestStepTools_1.createStepTools)(opStack);
|
|
128
|
+
/**
|
|
129
|
+
* Create args to pass in to our function. We blindly pass in the data and
|
|
130
|
+
* add tools.
|
|
131
|
+
*/
|
|
132
|
+
const fnArg = Object.assign(Object.assign({}, data), { tools });
|
|
133
|
+
let ret;
|
|
134
|
+
/**
|
|
135
|
+
* Attempt to run the function. If this is a step function, we expect to
|
|
136
|
+
* catch `StepFlowInterrupt` errors and ignore them, as they are used to
|
|
137
|
+
* interrupt function execution safely.
|
|
138
|
+
*/
|
|
139
|
+
try {
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
141
|
+
ret = await __classPrivateFieldGet(this, _InngestFunction_fn, "f").call(this, fnArg);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
if (!(err instanceof InngestStepTools_1.StepFlowInterrupt)) {
|
|
145
|
+
/**
|
|
146
|
+
* If the error is not a StepFlowInterrupt, then it is an error that we
|
|
147
|
+
* should probably bubble up.
|
|
148
|
+
*
|
|
149
|
+
* An exception is if the error has been somehow caused after
|
|
150
|
+
* successfully submitting a new op. This might happen if a user
|
|
151
|
+
* attempts to catch step errors with a try/catch block. In that case,
|
|
152
|
+
* we should warn of this but continue on.
|
|
153
|
+
*/
|
|
154
|
+
if (!state.nextOp) {
|
|
155
|
+
throw err;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* If we're here, then this unknown error was caused after successfully
|
|
159
|
+
* submitting an op.
|
|
160
|
+
*
|
|
161
|
+
* In this case, we warn the user that trying to catch these is not a
|
|
162
|
+
* good idea and continue on; the step tool itself will attempt to throw
|
|
163
|
+
* again to stop execution.
|
|
164
|
+
*/
|
|
165
|
+
console.warn("An error occurred after submitting a new op. Continuing on.", err);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* This could be a step function that has triggered an asynchronous step
|
|
170
|
+
* right at this moment.
|
|
171
|
+
*
|
|
172
|
+
* If this is the case, the above function will have now resolved and the
|
|
173
|
+
* async step function might still be running.
|
|
174
|
+
*
|
|
175
|
+
* Let's check for this occurence by checking the toolset we created to see
|
|
176
|
+
* if there is a pending op. If there is, wait for that, otherwise continue
|
|
177
|
+
* straight to the end.
|
|
178
|
+
*/
|
|
179
|
+
if (state.nextOp) {
|
|
180
|
+
return [true, await state.nextOp];
|
|
100
181
|
}
|
|
101
|
-
return
|
|
182
|
+
return [false, ret];
|
|
102
183
|
}
|
|
103
184
|
}
|
|
104
185
|
exports.InngestFunction = InngestFunction;
|
|
105
|
-
_InngestFunction_opts = new WeakMap(), _InngestFunction_trigger = new WeakMap(),
|
|
186
|
+
_InngestFunction_opts = new WeakMap(), _InngestFunction_trigger = new WeakMap(), _InngestFunction_fn = new WeakMap(), _InngestFunction_instances = new WeakSet(), _InngestFunction_generateId = function _InngestFunction_generateId(prefix) {
|
|
106
187
|
return (0, strings_1.slugify)([prefix || "", __classPrivateFieldGet(this, _InngestFunction_opts, "f").name].join("-"));
|
|
107
188
|
};
|
|
189
|
+
InngestFunction.stepId = "step";
|
|
108
190
|
//# sourceMappingURL=InngestFunction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestFunction.js","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAA8C;AAC9C,gDAA6C;
|
|
1
|
+
{"version":3,"file":"InngestFunction.js","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAA8C;AAC9C,gDAA6C;AAU7C,yDAAwE;AAExE;;;;;;;;GAQG;AACH,MAAa,eAAe;IAO1B;;;;;;OAMG;IACH;IACE;;OAEG;IACH,IAAqB,EACrB,OAAsC,EACtC,EAA2B;;QAjB7B,wCAAgC;QAChC,2CAAiD;QACjD,sCAAsC;QAiBpC,uBAAA,IAAI,yBAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,4BAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,uBAAO,EAAE,MAAA,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,EAAE,CAAC,MAAe;QACvB,IAAI,CAAC,uBAAA,IAAI,6BAAM,CAAC,EAAE,EAAE;YAClB,uBAAA,IAAI,6BAAM,CAAC,EAAE,GAAG,uBAAA,IAAI,+DAAY,MAAhB,IAAI,EAAa,MAAM,CAAC,CAAC;SAC1C;QAED,OAAO,uBAAA,IAAI,6BAAM,CAAC,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,uBAAA,IAAI,6BAAM,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACK,SAAS;IACf;;;;OAIG;IACH,OAAY,EACZ,SAAkB;QAElB,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;QAEhC,MAAM,OAAO,GAAG,IA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;gBAED;;;;;;;mBAOG;gBACH,OAAO,CAAC,IAAI,CACV,6DAA6D,EAC7D,GAAG,CACJ,CAAC;aACH;SACF;QAED;;;;;;;;;;WAUG;QACH,IAAI,KAAK,CAAC,MAAM,EAAE;YAChB,OAAO,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;SACnC;QAED,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACtB,CAAC;;AA5LH,0CAoMC;qOAHa,MAAe;IACzB,OAAO,IAAA,iBAAO,EAAC,CAAC,MAAM,IAAI,EAAE,EAAE,uBAAA,IAAI,6BAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC;AAlMM,sBAAM,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { ObjectPaths } from "../helpers/types";
|
|
2
|
+
import { EventPayload, HashedOp, OpStack } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* A unique class used to interrupt the flow of a step. It is intended to be
|
|
5
|
+
* thrown and caught using `instanceof StepFlowInterrupt`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class StepFlowInterrupt {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a new set of step function tools ready to be used in a step function.
|
|
11
|
+
* This function should be run and a fresh set of tools provided every time a
|
|
12
|
+
* function is run.
|
|
13
|
+
*
|
|
14
|
+
* An op stack (function state) is passed in as well as some mutable properties
|
|
15
|
+
* that the tools can use to submit a new op.
|
|
16
|
+
*
|
|
17
|
+
* Broadly, each tool is responsible for potentially filling itself with data
|
|
18
|
+
* from the op stack and submitting an op, interrupting the step function when
|
|
19
|
+
* it does so.
|
|
20
|
+
*
|
|
21
|
+
* This feels better being a class, but class bindings are lost (i.e. `this`
|
|
22
|
+
* becomes `undefined`) if a user destructures the tools within their step
|
|
23
|
+
* function. Thus, we must instead use closures for this functionality.
|
|
24
|
+
*/
|
|
25
|
+
export declare const createStepTools: <Events extends Record<string, EventPayload>, TriggeringEvent extends keyof Events>(_opStack: OpStack) => [{
|
|
26
|
+
/**
|
|
27
|
+
* Wait for a particular event to be received before continuing. When the
|
|
28
|
+
* event is received, it will be returned.
|
|
29
|
+
*
|
|
30
|
+
* You can also provide options to control the particular event that is
|
|
31
|
+
* received, for example to ensure that a user ID matches between two
|
|
32
|
+
* events, or to only wait a maximum amount of time before giving up and
|
|
33
|
+
* returning `null` instead of any event data.
|
|
34
|
+
*/
|
|
35
|
+
waitForEvent: <IncomingEvent extends EventPayload | keyof Events>(event: IncomingEvent extends keyof Events ? IncomingEvent : IncomingEvent extends EventPayload ? IncomingEvent["name"] : never, opts: ((IncomingEvent extends keyof Events ? WaitForEventOpts<Events[TriggeringEvent], Events[IncomingEvent]> : IncomingEvent extends EventPayload ? WaitForEventOpts<Events[TriggeringEvent], IncomingEvent> : never) & {
|
|
36
|
+
if?: undefined;
|
|
37
|
+
}) | ((IncomingEvent extends keyof Events ? WaitForEventOpts<Events[TriggeringEvent], Events[IncomingEvent]> : IncomingEvent extends EventPayload ? WaitForEventOpts<Events[TriggeringEvent], IncomingEvent> : never) & {
|
|
38
|
+
match?: undefined;
|
|
39
|
+
})) => IncomingEvent extends keyof Events ? Events[IncomingEvent] | null : IncomingEvent | null;
|
|
40
|
+
/**
|
|
41
|
+
* Use this tool to run business logic. Each call to `run` will be retried
|
|
42
|
+
* individually, meaning you can compose complex workflows that safely
|
|
43
|
+
* retry dependent asynchronous actions.
|
|
44
|
+
*
|
|
45
|
+
* The function you pass to `run` will be called only when this "step" is to
|
|
46
|
+
* be executed and can be synchronous or asynchronous.
|
|
47
|
+
*
|
|
48
|
+
* In either case, the return value of the function will be the return value
|
|
49
|
+
* of the `run` tool, meaning you can return and reason about return data
|
|
50
|
+
* for next steps.
|
|
51
|
+
*/
|
|
52
|
+
run: <T extends (...args: any[]) => any>(name: string, fn: T) => T extends (...args: any[]) => Promise<infer U> ? Awaited<U extends void ? null : U> : ReturnType<T> extends void ? null : ReturnType<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Wait a specified amount of time before continuing.
|
|
55
|
+
*
|
|
56
|
+
* The time to wait can be specified using a `number` of milliseconds or an
|
|
57
|
+
* `ms`-compatible time string like `"1 hour"`, `"30 mins"`, or `"2.5d"`.
|
|
58
|
+
*
|
|
59
|
+
* {@link https://npm.im/ms}
|
|
60
|
+
*
|
|
61
|
+
* To wait until a particular date, use `sleepUntil` instead.
|
|
62
|
+
*/
|
|
63
|
+
sleep: (time: number | string) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Wait until a particular date before continuing by passing a `Date`.
|
|
66
|
+
*
|
|
67
|
+
* To wait for a particular amount of time, use `sleep` instead.
|
|
68
|
+
*/
|
|
69
|
+
sleepUntil: (time: Date) => void;
|
|
70
|
+
}, {
|
|
71
|
+
nextOp: Promise<HashedOp> | undefined;
|
|
72
|
+
}];
|
|
73
|
+
/**
|
|
74
|
+
* A set of optional parameters given to a `waitForEvent` call to control how
|
|
75
|
+
* the event is handled.
|
|
76
|
+
*/
|
|
77
|
+
interface WaitForEventOpts<TriggeringEvent extends EventPayload, IncomingEvent extends EventPayload> {
|
|
78
|
+
/**
|
|
79
|
+
* The step function will wait for the event for a maximum of this time, at
|
|
80
|
+
* which point the event will be returned as `null` instead of any event data.
|
|
81
|
+
*
|
|
82
|
+
* The time to wait can be specified using a `number` of milliseconds, an
|
|
83
|
+
* `ms`-compatible time string like `"1 hour"`, `"30 mins"`, or `"2.5d"`, or
|
|
84
|
+
* a `Date` object.
|
|
85
|
+
*
|
|
86
|
+
* {@link https://npm.im/ms}
|
|
87
|
+
*/
|
|
88
|
+
timeout: number | string | Date;
|
|
89
|
+
/**
|
|
90
|
+
* If provided, the step function will wait for the incoming event to match
|
|
91
|
+
* particular criteria. If the event does not match, it will be ignored and
|
|
92
|
+
* the step function will wait for another event.
|
|
93
|
+
*
|
|
94
|
+
* It must be a string of a dot-notation field name within both events to
|
|
95
|
+
* compare, e.g. `"date.id"` or `"user.email"`.
|
|
96
|
+
*
|
|
97
|
+
* ```
|
|
98
|
+
* // Wait for an event where the `user.email` field matches
|
|
99
|
+
* match: "user.email"
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* All of these are helpers for the `if` option, which allows you to specify
|
|
103
|
+
* a custom condition to check. This can be useful if you need to compare
|
|
104
|
+
* multiple fields or use a more complex condition.
|
|
105
|
+
*
|
|
106
|
+
* See the Inngest expressions docs for more information.
|
|
107
|
+
*
|
|
108
|
+
* {@link https://www.inngest.com/docs/functions/expressions}
|
|
109
|
+
*/
|
|
110
|
+
match?: ObjectPaths<TriggeringEvent> & ObjectPaths<IncomingEvent>;
|
|
111
|
+
/**
|
|
112
|
+
* If provided, the step function will wait for the incoming event to match
|
|
113
|
+
* the given condition. If the event does not match, it will be ignored and
|
|
114
|
+
* the step function will wait for another event.
|
|
115
|
+
*
|
|
116
|
+
* The condition is a string of Google's Common Expression Language. For most
|
|
117
|
+
* simple cases, you might prefer to use `match` instead.
|
|
118
|
+
*
|
|
119
|
+
* See the Inngest expressions docs for more information.
|
|
120
|
+
*
|
|
121
|
+
* {@link https://www.inngest.com/docs/functions/expressions}
|
|
122
|
+
*/
|
|
123
|
+
if?: string;
|
|
124
|
+
}
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=InngestStepTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InngestStepTools.d.ts","sourceRoot":"","sources":["../../src/components/InngestStepTools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAM,OAAO,EAAc,MAAM,UAAU,CAAC;AAE3E;;;GAGG;AACH,qBAAa,iBAAiB;CAAG;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,gGAIhB,OAAO;IA8Lf;;;;;;;;OAQG;;;;;;IAwDH;;;;;;;;;;;OAWG;8BAEoB,GAAG,EAAE,KAAK,GAAG,QAM1B,MAAM,gCAWW,GAAG,EAAE;IAiBhC;;;;;;;;;OASG;kBAMO,MAAM,GAAG,MAAM,KAClB,IAAI;IAYX;;;;OAIG;uBAMO,IAAI,KACP,IAAI;;YAlKH,QAAQ,QAAQ,CAAC,GAAG,SAAS;EAgLxC,CAAC;AAEF;;;GAGG;AACH,UAAU,gBAAgB,CACxB,eAAe,SAAS,YAAY,EACpC,aAAa,SAAS,YAAY;IAElC;;;;;;;;;OASG;IACH,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAEhC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;IAElE;;;;;;;;;;;OAWG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb"}
|