inngest 0.3.0 → 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 (60) 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/components/Inngest.js +169 -0
  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/components/InngestFunction.js +113 -0
  9. package/components/InngestFunction.js.map +1 -0
  10. package/components/InngestStep.d.ts +15 -0
  11. package/components/InngestStep.d.ts.map +1 -0
  12. package/components/InngestStep.js +37 -0
  13. package/components/InngestStep.js.map +1 -0
  14. package/handlers/default.d.ts +81 -0
  15. package/handlers/default.d.ts.map +1 -0
  16. package/handlers/default.js +181 -0
  17. package/handlers/default.js.map +1 -0
  18. package/helpers/consts.d.ts +4 -0
  19. package/helpers/consts.d.ts.map +1 -0
  20. package/helpers/consts.js +7 -0
  21. package/helpers/consts.js.map +1 -0
  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/helpers/types.js +3 -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/index.js +12 -0
  33. package/index.js.map +1 -0
  34. package/{dist/init.d.ts → init.d.ts} +0 -0
  35. package/{dist/init.d.ts.map → init.d.ts.map} +0 -0
  36. package/{dist/init.js → init.js} +1 -1
  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 +41 -14
  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/types.d.ts +284 -0
  49. package/types.d.ts.map +1 -0
  50. package/types.js +3 -0
  51. package/types.js.map +1 -0
  52. package/version.d.ts +2 -0
  53. package/version.d.ts.map +1 -0
  54. package/version.js +6 -0
  55. package/version.js.map +1 -0
  56. package/dist/index.d.ts +0 -122
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js +0 -72
  59. package/dist/index.js.map +0 -1
  60. package/dist/init.js.map +0 -1
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
+ //# sourceMappingUR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this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ var _Inngest_instances, _Inngest_getResponseError;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Inngest = void 0;
13
+ const axios_1 = __importDefault(require("axios"));
14
+ const version_1 = require("../version");
15
+ const InngestFunction_1 = require("./InngestFunction");
16
+ const InngestStep_1 = require("./InngestStep");
17
+ /**
18
+ * A client used to interact with the Inngest API by sending or reacting to
19
+ * events.
20
+ *
21
+ * To provide event typing, make sure to pass in your generated event types as
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
41
+ */
42
+ class Inngest {
43
+ /**
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
+ * ```
65
+ */
66
+ constructor({ name, eventKey = process.env.INNGEST_EVENT_KEY, inngestBaseUrl = "https://inn.gs/", }) {
67
+ _Inngest_instances.add(this);
68
+ if (!name) {
69
+ throw new Error("A name must be passed to create an Inngest instance.");
70
+ }
71
+ if (!eventKey) {
72
+ throw new Error("An event key must be passed to create an Inngest instance.");
73
+ }
74
+ this.name = name;
75
+ this.eventKey = eventKey;
76
+ this.inngestBaseUrl = new URL(inngestBaseUrl);
77
+ this.inngestApiUrl = new URL(`e/${this.eventKey}`, this.inngestBaseUrl);
78
+ this.client = axios_1.default.create({
79
+ timeout: 0,
80
+ headers: {
81
+ "Content-Type": "application/json",
82
+ "User-Agent": `InngestJS v${version_1.version}`,
83
+ },
84
+ validateStatus: () => true,
85
+ maxRedirects: 0,
86
+ });
87
+ }
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);
118
+ if (response.status >= 200 && response.status < 300) {
119
+ return;
120
+ }
121
+ throw __classPrivateFieldGet(this, _Inngest_instances, "m", _Inngest_getResponseError).call(this, response);
122
+ }
123
+ /**
124
+ * Given an event to listen to, run the given function when that event is
125
+ * seen.
126
+ */
127
+ createFunction(nameOrOpts, event, fn) {
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) });
135
+ }
136
+ }
137
+ exports.Inngest = Inngest;
138
+ _Inngest_instances = new WeakSet(), _Inngest_getResponseError = function _Inngest_getResponseError(response) {
139
+ let errorMessage = "Unknown error";
140
+ switch (response.status) {
141
+ case 401:
142
+ errorMessage = "Event key Not Found";
143
+ break;
144
+ case 400:
145
+ errorMessage = "Cannot process event payload";
146
+ break;
147
+ case 403:
148
+ errorMessage = "Forbidden";
149
+ break;
150
+ case 404:
151
+ errorMessage = "Event key not found";
152
+ break;
153
+ case 406:
154
+ errorMessage = `${JSON.stringify(response.data)}`;
155
+ break;
156
+ case 409:
157
+ case 412:
158
+ errorMessage = "Event transformation failed";
159
+ break;
160
+ case 413:
161
+ errorMessage = "Event payload too large";
162
+ break;
163
+ case 500:
164
+ errorMessage = "Internal server error";
165
+ break;
166
+ }
167
+ return new Error(`Inngest API Error: ${response.status} ${errorMessage}`);
168
+ };
169
+ //# sourceMappingURL=Inngest.js.map
@@ -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;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,YAAY,EACV,IAAI,EAC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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"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _InngestFunction_instances, _InngestFunction_opts, _InngestFunction_trigger, _InngestFunction_steps, _InngestFunction_generateId;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.InngestFunction = void 0;
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
+ */
26
+ class InngestFunction {
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) {
39
+ _InngestFunction_instances.add(this);
40
+ _InngestFunction_opts.set(this, void 0);
41
+ _InngestFunction_trigger.set(this, void 0);
42
+ _InngestFunction_steps.set(this, void 0);
43
+ __classPrivateFieldSet(this, _InngestFunction_opts, opts, "f");
44
+ __classPrivateFieldSet(this, _InngestFunction_trigger, trigger, "f");
45
+ __classPrivateFieldSet(this, _InngestFunction_steps, steps || {}, "f");
46
+ }
47
+ /**
48
+ * The generated or given ID for this function.
49
+ */
50
+ get id() {
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;
55
+ }
56
+ /**
57
+ * The name of this function as it will appear in the Inngest Cloud UI.
58
+ */
59
+ get name() {
60
+ return __classPrivateFieldGet(this, _InngestFunction_opts, "f").name;
61
+ }
62
+ /**
63
+ * Retrieve the Inngest config for this function.
64
+ */
65
+ getConfig(
66
+ /**
67
+ * Must be provided a URL that will be used to access the function and step.
68
+ * This function can't be expected to know how it will be accessed, so
69
+ * relies on an outside method providing context.
70
+ */
71
+ baseUrl) {
72
+ return {
73
+ id: this.id,
74
+ name: this.name,
75
+ triggers: [__classPrivateFieldGet(this, _InngestFunction_trigger, "f")],
76
+ steps: Object.keys(__classPrivateFieldGet(this, _InngestFunction_steps, "f")).reduce((acc, stepId) => {
77
+ const url = new URL(baseUrl.href);
78
+ url.searchParams.set(consts_1.fnIdParam, __classPrivateFieldGet(this, _InngestFunction_opts, "f").name);
79
+ url.searchParams.set(consts_1.stepIdParam, stepId);
80
+ return Object.assign(Object.assign({}, acc), { [stepId]: {
81
+ id: stepId,
82
+ name: stepId,
83
+ runtime: {
84
+ type: "http",
85
+ url: url.href,
86
+ },
87
+ } });
88
+ }, {}),
89
+ };
90
+ }
91
+ /**
92
+ * Run a step in this function defined by `stepId` with `data`.
93
+ */
94
+ runStep(stepId, data) {
95
+ const step = __classPrivateFieldGet(this, _InngestFunction_steps, "f")[stepId];
96
+ if (!step) {
97
+ throw new Error(`Could not find step with ID "${stepId}" in function "${this.name}"`);
98
+ }
99
+ return step["run"](data);
100
+ }
101
+ }
102
+ exports.InngestFunction = InngestFunction;
103
+ _InngestFunction_opts = new WeakMap(), _InngestFunction_trigger = new WeakMap(), _InngestFunction_steps = new WeakMap(), _InngestFunction_instances = new WeakSet(), _InngestFunction_generateId = function _InngestFunction_generateId() {
104
+ const join = "-";
105
+ return __classPrivateFieldGet(this, _InngestFunction_opts, "f").name
106
+ .toLowerCase()
107
+ .replaceAll(/[^a-z0-9-]+/g, join)
108
+ .replaceAll(/-+/g, join)
109
+ .split(join)
110
+ .filter(Boolean)
111
+ .join(join);
112
+ };
113
+ //# sourceMappingURL=InngestFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InngestFunction.js","s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AY,CAAC,GAAG,CAAC,oBAAW,EAAE,MAAM,CAAC,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"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A typed, individual step within an `InngestFunction`.
3
+ */
4
+ export declare class InngestStep<Input extends any[], Output> {
5
+ #private;
6
+ constructor(fn: (...args: Input) => Output);
7
+ /**
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.
12
+ */
13
+ private run;
14
+ }
15
+ //# sourceMappingURL=InngestStep.d.ts.map
@@ -0,0 +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;;;;;OAKG;YAEW,GAAG;CAGlB"}