inngest 0.4.0-beta.1 → 0.4.0-beta.10

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 (77) hide show
  1. package/README.md +43 -33
  2. package/components/Inngest.d.ts +215 -0
  3. package/components/Inngest.d.ts.map +1 -0
  4. package/{dist/components → components}/Inngest.js +84 -18
  5. package/components/Inngest.js.map +1 -0
  6. package/components/InngestFunction.d.ts +42 -0
  7. package/components/InngestFunction.d.ts.map +1 -0
  8. package/{dist/components → components}/InngestFunction.js +32 -3
  9. package/components/InngestFunction.js.map +1 -0
  10. package/{dist/components → components}/InngestStep.d.ts +3 -0
  11. package/{dist/components → components}/InngestStep.d.ts.map +1 -1
  12. package/{dist/components → components}/InngestStep.js +4 -0
  13. package/components/InngestStep.js.map +1 -0
  14. package/{dist/handlers → handlers}/default.d.ts +19 -18
  15. package/handlers/default.d.ts.map +1 -0
  16. package/{dist/handlers → handlers}/default.js +58 -44
  17. package/handlers/default.js.map +1 -0
  18. package/{dist/helpers → helpers}/consts.d.ts +1 -0
  19. package/{dist/helpers → helpers}/consts.d.ts.map +1 -1
  20. package/helpers/consts.js +7 -0
  21. package/{dist/helpers → helpers}/consts.js.map +1 -1
  22. package/helpers/func.d.ts +16 -0
  23. package/helpers/func.d.ts.map +1 -0
  24. package/helpers/func.js +61 -0
  25. package/helpers/func.js.map +1 -0
  26. package/helpers/types.d.ts +11 -0
  27. package/helpers/types.d.ts.map +1 -0
  28. package/{dist → helpers}/types.js +0 -0
  29. package/helpers/types.js.map +1 -0
  30. package/index.d.ts +5 -0
  31. package/index.d.ts.map +1 -0
  32. package/{dist/index.js → index.js} +3 -2
  33. package/{dist/index.js.map → index.js.map} +1 -1
  34. package/init.d.ts +3 -0
  35. package/init.d.ts.map +1 -0
  36. package/init.js +70 -0
  37. package/init.js.map +1 -0
  38. package/next.d.ts +9 -0
  39. package/next.d.ts.map +1 -0
  40. package/next.js +73 -0
  41. package/next.js.map +1 -0
  42. package/package.json +36 -11
  43. package/remix.d.ts +9 -0
  44. package/remix.d.ts.map +1 -0
  45. package/remix.js +79 -0
  46. package/remix.js.map +1 -0
  47. package/src/version.ts +2 -0
  48. package/{dist/types.d.ts → types.d.ts} +136 -14
  49. package/types.d.ts.map +1 -0
  50. package/types.js +3 -0
  51. package/{dist/types.js.map → types.js.map} +0 -0
  52. package/version.d.ts +2 -0
  53. package/{dist/version.d.ts.map → version.d.ts.map} +0 -0
  54. package/{dist/version.js → version.js} +1 -1
  55. package/{dist/version.js.map → version.js.map} +0 -0
  56. package/dist/components/Inngest.d.ts +0 -57
  57. package/dist/components/Inngest.d.ts.map +0 -1
  58. package/dist/components/Inngest.js.map +0 -1
  59. package/dist/components/InngestFunction.d.ts +0 -16
  60. package/dist/components/InngestFunction.d.ts.map +0 -1
  61. package/dist/components/InngestFunction.js.map +0 -1
  62. package/dist/components/InngestStep.js.map +0 -1
  63. package/dist/handlers/default.d.ts.map +0 -1
  64. package/dist/handlers/default.js.map +0 -1
  65. package/dist/handlers/next.d.ts +0 -3
  66. package/dist/handlers/next.d.ts.map +0 -1
  67. package/dist/handlers/next.js +0 -58
  68. package/dist/handlers/next.js.map +0 -1
  69. package/dist/helpers/consts.js +0 -6
  70. package/dist/helpers/func.d.ts +0 -4
  71. package/dist/helpers/func.d.ts.map +0 -1
  72. package/dist/helpers/func.js +0 -12
  73. package/dist/helpers/func.js.map +0 -1
  74. package/dist/index.d.ts +0 -5
  75. package/dist/index.d.ts.map +0 -1
  76. package/dist/types.d.ts.map +0 -1
  77. package/dist/version.d.ts +0 -2
package/README.md CHANGED
@@ -1,42 +1,52 @@
1
- # inngest-node
1
+ # inngest
2
+
3
+ [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
4
+ [![npm version](https://img.shields.io/npm/v/inngest)](https://www.npmjs.com/package/inngest)
5
+ [![Discord](https://img.shields.io/discord/842170679536517141?label=discord)](https://discord.gg/EuesV2ZSnX)
6
+ [![Twitter Follow](https://img.shields.io/twitter/follow/inngest?style=social)](https://twitter.com/inngest)
7
+
8
+ Build, test, and deploy code that runs in response to events or on a schedule right in your own codebase.
9
+
10
+ 👋 _**Have a question or feature request? [Join our Discord](https://www.inngest.com/discord)!**_
2
11
 
3
12
  ```
4
13
  npm install inngest
5
14
  ```
6
15
 
7
- 👋 _**Have a question or feature request? [Join our Discord](https://www.inngest.com/discord)!**_
16
+ ```ts
17
+ // Send events
18
+ import { Inngest } from "inngest";
19
+ const inngest = new Inngest({ name: "My App" });
20
+
21
+ inngest.send("app/user.created", { data: { id: 123 } });
22
+ ```
8
23
 
9
- ## Usage
24
+ ```ts
25
+ // Listen to events
26
+ import { createFunction } from "inngest";
10
27
 
11
- ```js
12
- // ES Modules / TypeScript
13
- import { Inngest } from "inngest";
14
- // or CommonJS
15
- const { Inngest } = require("inngest");
16
-
17
- const inngest = new Inngest(process.env.INNGEST_SOURCE_API_KEY);
18
-
19
- // Send a single event
20
- await inngest.send({
21
- name: "user.signup",
22
- data: {
23
- plan: account.planType,
24
- },
25
- user: {
26
- external_id: user.id,
27
- email: user.email,
28
- },
29
- });
30
-
31
- // Send events in bulk
32
- const events = ["+12125551234", "+13135555678"].map(phoneNumber => ({
33
- name: "sms.response.requested",
34
- data: {
35
- message: "Are you available for work today? (y/n)"
36
- },
37
- user: {
38
- phone: phoneNumber
28
+ export default createFunction(
29
+ "Send welcome email",
30
+ "app/user.created",
31
+ ({ event }) => {
32
+ sendEmailTo(event.data.id, "Welcome!");
39
33
  }
40
- }});
41
- await inngest.send(events);
34
+ );
42
35
  ```
36
+
37
+ ## Getting started
38
+
39
+ Links to how to start, platforms, frameworks, logos?
40
+
41
+ ## Contributing
42
+
43
+ Clone the repository, then:
44
+
45
+ ```sh
46
+ yarn # install dependencies
47
+ yarn dev # build/lint/test
48
+ ```
49
+
50
+ We use [Volta](https://volta.sh/) to manage Node/Yarn versions.
51
+
52
+ When making a pull request, make sure to commit the changed `etc/inngest.api.md` file; this is a generated types/docs file that will highlight changes to the exposed API.
@@ -0,0 +1,215 @@
1
+ import { SingleOrArray, ValueOf } from "../helpers/types";
2
+ import { ClientOptions, EventPayload, FunctionOptions, StepFn } from "../types";
3
+ import { InngestFunction } from "./InngestFunction";
4
+ /**
5
+ * A client used to interact with the Inngest API by sending or reacting to
6
+ * events.
7
+ *
8
+ * To provide event typing, make sure to pass in your generated event types as
9
+ * the first generic.
10
+ *
11
+ * ```ts
12
+ * const inngest = new Inngest<Events>("My App", process.env.INNGEST_EVENT_KEY);
13
+ *
14
+ * // or to provide custom events too
15
+ * const inngest = new Inngest<
16
+ * Events & {
17
+ * "demo/event.blah": {
18
+ * name: "demo/event.blah";
19
+ * data: {
20
+ * bar: boolean;
21
+ * };
22
+ * };
23
+ * }
24
+ * >("My App", process.env.INNGEST_EVENT_KEY);
25
+ * ```
26
+ *
27
+ * @public
28
+ */
29
+ export declare class Inngest<Events extends Record<string, EventPayload>> {
30
+ #private;
31
+ /**
32
+ * The name of this instance, most commonly the name of the application it
33
+ * resides in.
34
+ */
35
+ readonly name: string;
36
+ /**
37
+ * Inngest event key, used to send events to Inngest Cloud.
38
+ */
39
+ private readonly eventKey;
40
+ /**
41
+ * Base URL for Inngest Cloud.
42
+ */
43
+ readonly inngestBaseUrl: URL;
44
+ /**
45
+ * The absolute URL of the Inngest Cloud API.
46
+ */
47
+ private readonly inngestApiUrl;
48
+ /**
49
+ * An Axios instance used for communicating with Inngest Cloud.
50
+ *
51
+ * {@link https://npm.im/axios}
52
+ */
53
+ private readonly client;
54
+ /**
55
+ * A client used to interact with the Inngest API by sending or reacting to
56
+ * events.
57
+ *
58
+ * To provide event typing, make sure to pass in your generated event types as
59
+ * the first generic.
60
+ *
61
+ * ```ts
62
+ * const inngest = new Inngest<Events>("My App", process.env.INNGEST_EVENT_KEY);
63
+ *
64
+ * // or to provide custom events too
65
+ * const inngest = new Inngest<
66
+ * Events & {
67
+ * "demo/event.blah": {
68
+ * name: "demo/event.blah";
69
+ * data: {
70
+ * bar: boolean;
71
+ * };
72
+ * };
73
+ * }
74
+ * >("My App", process.env.INNGEST_EVENT_KEY);
75
+ * ```
76
+ */
77
+ constructor({ name, eventKey, inngestBaseUrl, }: ClientOptions);
78
+ /**
79
+ * Send one or many events to Inngest. Takes a known event from this Inngest
80
+ * instance based on the given `name`.
81
+ *
82
+ * ```ts
83
+ * await inngest.send("app/user.created", { data: { id: 123 } });
84
+ * ```
85
+ *
86
+ * Returns a promise that will resolve if the event(s) were sent successfully,
87
+ * else throws with an error explaining what went wrong.
88
+ *
89
+ * If you wish to send an event with custom types (i.e. one that hasn't been
90
+ * generated), make sure to add it when creating your Inngest instance, like
91
+ * so:
92
+ *
93
+ * ```ts
94
+ * const inngest = new Inngest<Events & {
95
+ * "my/event": {
96
+ * name: "my/event";
97
+ * data: { bar: string; };
98
+ * }
99
+ * }>("My App", "API_KEY");
100
+ * ```
101
+ */
102
+ send<Event extends keyof Events>(name: Event, payload: SingleOrArray<Omit<Events[Event], "name">>): Promise<void>;
103
+ /**
104
+ * Send one or many events to Inngest. Takes an entire payload (including
105
+ * name) as each input.
106
+ *
107
+ * ```ts
108
+ * await inngest.send({ name: "app/user.created", data: { id: 123 } });
109
+ * ```
110
+ *
111
+ * Returns a promise that will resolve if the event(s) were sent successfully,
112
+ * else throws with an error explaining what went wrong.
113
+ *
114
+ * If you wish to send an event with custom types (i.e. one that hasn't been
115
+ * generated), make sure to add it when creating your Inngest instance, like
116
+ * so:
117
+ *
118
+ * ```ts
119
+ * const inngest = new Inngest<Events & {
120
+ * "my/event": {
121
+ * name: "my/event";
122
+ * data: { bar: string; };
123
+ * }
124
+ * }>("My App", "API_KEY");
125
+ * ```
126
+ */
127
+ send<Payload extends SingleOrArray<ValueOf<Events>>>(payload: Payload): Promise<void>;
128
+ /**
129
+ * Given an event to listen to, run the given function when that event is
130
+ * seen.
131
+ */
132
+ createFunction<Event extends keyof Events, Name extends string, Fn extends StepFn<Events[Event], Name, "step">>(
133
+ /**
134
+ * The name of this function as it will appear in the Inngst Cloud UI.
135
+ */
136
+ name: Name,
137
+ /**
138
+ * The event to listen for.
139
+ */
140
+ event: Event,
141
+ /**
142
+ * The function to run when the event is received.
143
+ */
144
+ fn: Fn): InngestFunction<Events>;
145
+ /**
146
+ * Given an event to listen to, run the given function when that event is
147
+ * seen.
148
+ */
149
+ createFunction<Event extends keyof Events, Opts extends FunctionOptions, Fn extends StepFn<Events[Event], Opts extends FunctionOptions ? Opts["name"] : string, "step">>(
150
+ /**
151
+ * Options for this Inngest function - useful for defining a custom ID.
152
+ */
153
+ opts: Opts,
154
+ /**
155
+ * The event to listen for.
156
+ */
157
+ event: Event,
158
+ /**
159
+ * The function to run when the event is received.
160
+ */
161
+ fn: Fn): InngestFunction<Events>;
162
+ /**
163
+ * Run the given `fn` at a specified time or on a schedule given by `cron`.
164
+ */
165
+ createScheduledFunction<Name extends string>(
166
+ /**
167
+ * The name of this function as it will appear in the Inngest Cloud UI.
168
+ */
169
+ name: Name,
170
+ /**
171
+ * The cron definition to schedule your function.
172
+ *
173
+ * @example
174
+ *
175
+ * "0 0 0 1 1 * 1" // At 12:00 AM, on day 1 of the month, only in January, only in 0001
176
+ * "0 0 0 1 1 * 1,2" // At 12:00 AM, on day 1 of the month, only in January, only in 0001 and 0002
177
+ * "0 0 0 1 1 * 1,2,3" // At 12:00 AM, on day 1 of the month, only in January, only in 0001, 0002, and 0003
178
+ * "0 0 0 1 * * 1/4" // At 12:00 AM, on day 1 of the month, every 4 years
179
+ * "0 0 0 * * 0 1-4" // At 12:00 AM, only on Sunday, 0001 through 0004
180
+ * "0 0 0 * * * 2/4" // At 12:00 AM, every 4 years, 0002 through 9999
181
+ * "0 0 * * * * *" // Every hour
182
+ */
183
+ cron: string,
184
+ /**
185
+ * The function to run.
186
+ */
187
+ fn: StepFn<null, Name, "step">): InngestFunction<Events>;
188
+ /**
189
+ * Run the given `fn` at a specified time or on a schedule given by `cron`.
190
+ */
191
+ createScheduledFunction<Opts extends FunctionOptions>(
192
+ /**
193
+ * Options for this Inngest function - useful for defining a custom ID.
194
+ */
195
+ opts: Opts,
196
+ /**
197
+ * The cron definition to schedule your function.
198
+ *
199
+ * @example
200
+ *
201
+ * "0 0 0 1 1 * 1" // At 12:00 AM, on day 1 of the month, only in January, only in 0001
202
+ * "0 0 0 1 1 * 1,2" // At 12:00 AM, on day 1 of the month, only in January, only in 0001 and 0002
203
+ * "0 0 0 1 1 * 1,2,3" // At 12:00 AM, on day 1 of the month, only in January, only in 0001, 0002, and 0003
204
+ * "0 0 0 1 * * 1/4" // At 12:00 AM, on day 1 of the month, every 4 years
205
+ * "0 0 0 * * 0 1-4" // At 12:00 AM, only on Sunday, 0001 through 0004
206
+ * "0 0 0 * * * 2/4" // At 12:00 AM, every 4 years, 0002 through 9999
207
+ * "0 0 * * * * *" // Every hour
208
+ */
209
+ cron: string,
210
+ /**
211
+ * The function to run.
212
+ */
213
+ fn: StepFn<null, Opts extends FunctionOptions ? Opts["name"] : string, "step">): InngestFunction<Events>;
214
+ }
215
+ //# sourceMappingURL=Inngest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,OAAO,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;;IAC9D;;;OAGG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC;;OAEG;IACH,SAAgB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AEZ;;OAEG;IACH,EAAE,EAAE,EAAE,GACL,eAAe,CAAC,MAAM,CAAC;IAyB1B;;OAEG;IACI,uBAAuB,CAAC,IAAI,SAAS,MAAM;IAChD;;OAEG;IACH,IAAI,EAAE,IAAI;IAEV;;;;;;;;;;;;OAYG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,GAC7B,eAAe,CAAC,MAAM,CAAC;IAC1B;;OAEG;IACI,uBAAuB,CAAC,IAAI,SAAS,eAAe;IACzD;;OAEG;IACH,IAAI,EAAE,IAAI;IAEV;;;;;;;;;;;;OAYG;IACH,IAAI,EAAE,MAAM;IAEZ;;OAEG;IACH,EAAE,EAAE,MAAM,CACR,IAAI,EACJ,IAAI,SAAS,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,EACpD,MAAM,CACP,GACA,eAAe,CAAC,MAAM,CAAC;CAuB3B"}
@@ -11,6 +11,7 @@ var _Inngest_instances, _Inngest_getResponseError;
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Inngest = void 0;
13
13
  const axios_1 = __importDefault(require("axios"));
14
+ const version_1 = require("../version");
14
15
  const InngestFunction_1 = require("./InngestFunction");
15
16
  const InngestStep_1 = require("./InngestStep");
16
17
  /**
@@ -19,18 +20,50 @@ const InngestStep_1 = require("./InngestStep");
19
20
  *
20
21
  * To provide event typing, make sure to pass in your generated event types as
21
22
  * the first generic.
23
+ *
24
+ * ```ts
25
+ * const inngest = new Inngest<Events>("My App", process.env.INNGEST_EVENT_KEY);
26
+ *
27
+ * // or to provide custom events too
28
+ * const inngest = new Inngest<
29
+ * Events & {
30
+ * "demo/event.blah": {
31
+ * name: "demo/event.blah";
32
+ * data: {
33
+ * bar: boolean;
34
+ * };
35
+ * };
36
+ * }
37
+ * >("My App", process.env.INNGEST_EVENT_KEY);
38
+ * ```
39
+ *
40
+ * @public
22
41
  */
23
42
  class Inngest {
24
- constructor(
25
- /**
26
- * The name of this instance, most commonly the name of the application it
27
- * resides in.
28
- */
29
- name,
30
43
  /**
31
- * Inngest event key, used to send events to Inngest Cloud.
44
+ * A client used to interact with the Inngest API by sending or reacting to
45
+ * events.
46
+ *
47
+ * To provide event typing, make sure to pass in your generated event types as
48
+ * the first generic.
49
+ *
50
+ * ```ts
51
+ * const inngest = new Inngest<Events>("My App", process.env.INNGEST_EVENT_KEY);
52
+ *
53
+ * // or to provide custom events too
54
+ * const inngest = new Inngest<
55
+ * Events & {
56
+ * "demo/event.blah": {
57
+ * name: "demo/event.blah";
58
+ * data: {
59
+ * bar: boolean;
60
+ * };
61
+ * };
62
+ * }
63
+ * >("My App", process.env.INNGEST_EVENT_KEY);
64
+ * ```
32
65
  */
33
- eventKey, { inngestBaseUrl = "https://inn.gs/" } = {}) {
66
+ constructor({ name, eventKey = process.env.INNGEST_EVENT_KEY, inngestBaseUrl = "https://inn.gs/", }) {
34
67
  _Inngest_instances.add(this);
35
68
  if (!name) {
36
69
  throw new Error("A name must be passed to create an Inngest instance.");
@@ -46,26 +79,59 @@ class Inngest {
46
79
  timeout: 0,
47
80
  headers: {
48
81
  "Content-Type": "application/json",
49
- "User-Agent": "InngestJS 0.1.0",
82
+ "User-Agent": `InngestJS v${version_1.version}`,
50
83
  },
51
84
  validateStatus: () => true,
52
85
  maxRedirects: 0,
53
86
  });
54
87
  }
55
- /**
56
- * Send event(s) to Inngest
57
- */
58
- async send(name, payload) {
59
- const response = await this.client.post(this.inngestApiUrl.href, Object.assign(Object.assign({}, payload), { name }));
88
+ async send(nameOrPayload, maybePayload) {
89
+ let payloads;
90
+ if (typeof nameOrPayload === "string") {
91
+ /**
92
+ * Add our payloads and ensure they all have a name.
93
+ */
94
+ payloads = (Array.isArray(maybePayload)
95
+ ? maybePayload
96
+ : maybePayload
97
+ ? [maybePayload]
98
+ : []).map((payload) => (Object.assign(Object.assign({}, payload), { name: nameOrPayload })));
99
+ }
100
+ else {
101
+ /**
102
+ * Grab our payloads straight from the args.
103
+ */
104
+ payloads = (Array.isArray(nameOrPayload)
105
+ ? nameOrPayload
106
+ : nameOrPayload
107
+ ? [nameOrPayload]
108
+ : []);
109
+ }
110
+ /**
111
+ * The two overload types should never allow this to happen, but in the case
112
+ * the user is in JS Land and it does, let's throw.
113
+ */
114
+ if (!payloads.length) {
115
+ throw new Error("Provided a name but no events to send; make sure to send an event payload too");
116
+ }
117
+ const response = await this.client.post(this.inngestApiUrl.href, payloads);
60
118
  if (response.status >= 200 && response.status < 300) {
61
- return true;
119
+ return;
62
120
  }
63
121
  throw __classPrivateFieldGet(this, _Inngest_instances, "m", _Inngest_getResponseError).call(this, response);
64
122
  }
123
+ /**
124
+ * Given an event to listen to, run the given function when that event is
125
+ * seen.
126
+ */
65
127
  createFunction(nameOrOpts, event, fn) {
66
- return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, event, {
67
- step: new InngestStep_1.InngestStep(fn),
68
- });
128
+ return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { event: event }, { step: new InngestStep_1.InngestStep(fn) });
129
+ }
130
+ /**
131
+ * Run the given `fn` at a specified time or on a schedule given by `cron`.
132
+ */
133
+ createScheduledFunction(nameOrOpts, cron, fn) {
134
+ return new InngestFunction_1.InngestFunction(typeof nameOrOpts === "string" ? { name: nameOrOpts } : nameOrOpts, { cron }, { step: new InngestStep_1.InngestStep(fn) });
69
135
  }
70
136
  }
71
137
  exports.Inngest = Inngest;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Inngest.js","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA4D;AAG5D,wCAAqC;AACrC,uDAAoD;AACpD,+CAA4C;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,OAAO;IA6BlB;;;;;;;;;;;;;;;;;;;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C;IACJ,CAAC;CACF;AAjYD,0BAiYC;mGA3SmB,QAAuB;IACvC,IAAI,YAAY,GAAG,eAAe,CAAC;IACnC,QAAQ,QAAQ,CAAC,MAAM,EAAE;QACvB,KAAK,GAAG;YACN,YAAY,GAAG,qBAAqB,CAAC;YACrC,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,8BAA8B,CAAC;YAC9C,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,WAAW,CAAC;YAC3B,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,qBAAqB,CAAC;YACrC,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAClD,MAAM;QACR,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,YAAY,GAAG,6BAA6B,CAAC;YAC7C,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,yBAAyB,CAAC;YACzC,MAAM;QACR,KAAK,GAAG;YACN,YAAY,GAAG,uBAAuB,CAAC;YACvC,MAAM;KACT;IACD,OAAO,IAAI,KAAK,CAAC,sBAAsB,QAAQ,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { EventPayload, FunctionOptions, FunctionTrigger, Steps } from "../types";
2
+ /**
3
+ * A stateless Inngest function, wrapping up function configuration and any
4
+ * in-memory steps to run when triggered.
5
+ *
6
+ * This function can be "registered" to create a handler that Inngest can
7
+ * trigger remotely.
8
+ *
9
+ * @public
10
+ */
11
+ export declare class InngestFunction<Events extends Record<string, EventPayload>> {
12
+ #private;
13
+ /**
14
+ * A stateless Inngest function, wrapping up function configuration and any
15
+ * in-memory steps to run when triggered.
16
+ *
17
+ * This function can be "registered" to create a handler that Inngest can
18
+ * trigger remotely.
19
+ */
20
+ constructor(
21
+ /**
22
+ * Options
23
+ */
24
+ opts: FunctionOptions, trigger: FunctionTrigger<keyof Events>, steps: Steps);
25
+ /**
26
+ * The generated or given ID for this function.
27
+ */
28
+ get id(): string;
29
+ /**
30
+ * The name of this function as it will appear in the Inngest Cloud UI.
31
+ */
32
+ get name(): string;
33
+ /**
34
+ * Retrieve the Inngest config for this function.
35
+ */
36
+ private getConfig;
37
+ /**
38
+ * Run a step in this function defined by `stepId` with `data`.
39
+ */
40
+ private runStep;
41
+ }
42
+ //# sourceMappingURL=InngestFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InngestFunction.d.ts","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EAEZ,eAAe,EACf,eAAe,EACf,KAAK,EACN,MAAM,UAAU,CAAC;AAElB;;;;;;;;GAQG;AACH,qBAAa,eAAe,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;;IAKtE;;;;;;OAMG;;IAED;;OAEG;IACH,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,eAAe,CAAC,MAAM,MAAM,CAAC,EACtC,KAAK,EAAE,KAAK;IAOd;;OAEG;IACH,IAAW,EAAE,WAMZ;IAED;;OAEG;IACH,IAAW,IAAI,WAEd;IAED;;OAEG;IACH,OAAO,CAAC,SAAS;IAmCjB;;OAEG;IACH,OAAO,CAAC,OAAO;CAyBhB"}
@@ -14,8 +14,28 @@ var _InngestFunction_instances, _InngestFunction_opts, _InngestFunction_trigger,
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.InngestFunction = void 0;
16
16
  const consts_1 = require("../helpers/consts");
17
+ /**
18
+ * A stateless Inngest function, wrapping up function configuration and any
19
+ * in-memory steps to run when triggered.
20
+ *
21
+ * This function can be "registered" to create a handler that Inngest can
22
+ * trigger remotely.
23
+ *
24
+ * @public
25
+ */
17
26
  class InngestFunction {
18
- constructor(opts, trigger, steps) {
27
+ /**
28
+ * A stateless Inngest function, wrapping up function configuration and any
29
+ * in-memory steps to run when triggered.
30
+ *
31
+ * This function can be "registered" to create a handler that Inngest can
32
+ * trigger remotely.
33
+ */
34
+ constructor(
35
+ /**
36
+ * Options
37
+ */
38
+ opts, trigger, steps) {
19
39
  _InngestFunction_instances.add(this);
20
40
  _InngestFunction_opts.set(this, void 0);
21
41
  _InngestFunction_trigger.set(this, void 0);
@@ -24,9 +44,18 @@ class InngestFunction {
24
44
  __classPrivateFieldSet(this, _InngestFunction_trigger, trigger, "f");
25
45
  __classPrivateFieldSet(this, _InngestFunction_steps, steps || {}, "f");
26
46
  }
47
+ /**
48
+ * The generated or given ID for this function.
49
+ */
27
50
  get id() {
28
- return __classPrivateFieldGet(this, _InngestFunction_opts, "f").id || __classPrivateFieldGet(this, _InngestFunction_instances, "m", _InngestFunction_generateId).call(this);
51
+ if (!__classPrivateFieldGet(this, _InngestFunction_opts, "f").id) {
52
+ __classPrivateFieldGet(this, _InngestFunction_opts, "f").id = __classPrivateFieldGet(this, _InngestFunction_instances, "m", _InngestFunction_generateId).call(this);
53
+ }
54
+ return __classPrivateFieldGet(this, _InngestFunction_opts, "f").id;
29
55
  }
56
+ /**
57
+ * The name of this function as it will appear in the Inngest Cloud UI.
58
+ */
30
59
  get name() {
31
60
  return __classPrivateFieldGet(this, _InngestFunction_opts, "f").name;
32
61
  }
@@ -43,7 +72,7 @@ class InngestFunction {
43
72
  return {
44
73
  id: this.id,
45
74
  name: this.name,
46
- triggers: [{ event: __classPrivateFieldGet(this, _InngestFunction_trigger, "f") }],
75
+ triggers: [__classPrivateFieldGet(this, _InngestFunction_trigger, "f")],
47
76
  steps: Object.keys(__classPrivateFieldGet(this, _InngestFunction_steps, "f")).reduce((acc, stepId) => {
48
77
  const url = new URL(baseUrl.href);
49
78
  url.searchParams.set(consts_1.fnIdParam, __classPrivateFieldGet(this, _InngestFunction_opts, "f").name);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InngestFunction.js","sourceRoot":"","sources":["../../src/components/InngestFunction.ts"],"names":[],"mappings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,CAAC;gBAE1C,uCACK,GAAG,KACN,CAAC,MAAM,CAAC,EAAE;wBACR,EAAE,EAAE,MAAM;wBACV,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE;4BACP,IAAI,EAAE,MAAM;4BACZ,GAAG,EAAE,GAAG,CAAC,IAAI;yBACd;qBACF,IACD;YACJ,CAAC,EACD,EAAE,CACH;SACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,OAAO,CAAC,MAAc,EAAE,IAAS;QACvC,MAAM,IAAI,GAAG,uBAAA,IAAI,8BAAO,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,IAAI,KAAK,CACb,gCAAgC,MAAM,kBAAkB,IAAI,CAAC,IAAI,GAAG,CACrE,CAAC;SACH;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;CAgBF;AA7GD,0CA6GC;;IAVG,MAAM,IAAI,GAAG,GAAG,CAAC;IAEjB,OAAO,uBAAA,IAAI,6BAAM,CAAC,IAAI;SACnB,WAAW,EAAE;SACb,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC;SAChC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC;SACvB,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -6,6 +6,9 @@ export declare class InngestStep<Input extends any[], Output> {
6
6
  constructor(fn: (...args: Input) => Output);
7
7
  /**
8
8
  * Run this step with the given `data`.
9
+ *
10
+ * Purposefully return a promise so that it's easier to catch further up the
11
+ * stack.
9
12
  */
10
13
  private run;
11
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"InngestStep.d.ts","sourceRoot":"","sources":["../../src/components/InngestStep.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAW,CAAC,KAAK,SAAS,GAAG,EAAE,EAAE,MAAM;;gBAGtC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM;IAI1C;;OAEG;YACW,GAAG;CAGlB"}
1
+ {"version":3,"file":"InngestStep.d.ts","sourceRoot":"","sources":["../../src/components/InngestStep.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,WAAW,CAAC,KAAK,SAAS,GAAG,EAAE,EAAE,MAAM;;gBAGtC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM;IAI1C;;;;;OAKG;YAEW,GAAG;CAGlB"}
@@ -23,7 +23,11 @@ class InngestStep {
23
23
  }
24
24
  /**
25
25
  * Run this step with the given `data`.
26
+ *
27
+ * Purposefully return a promise so that it's easier to catch further up the
28
+ * stack.
26
29
  */
30
+ // eslint-disable-next-line @typescript-eslint/require-await
27
31
  async run(data) {
28
32
  return __classPrivateFieldGet(this, _InngestStep_fn, "f").call(this, data);
29
33
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InngestStep.js","sourceRoot":"","sources":["../../src/components/InngestStep.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;GAEG;AACH,MAAa,WAAW;IAGtB,YAAY,EAA8B;QAF1C,kCAAuC;QAGrC,uBAAA,IAAI,mBAAO,EAAE,MAAA,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,4DAA4D;IACpD,KAAK,CAAC,GAAG,CAAC,IAAS;QACzB,OAAO,uBAAA,IAAI,uBAAI,MAAR,IAAI,EAAK,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAjBD,kCAiBC"}