inngest 1.9.1 → 2.0.0-next.2
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/components/EventSchemas.d.ts +161 -0
- package/components/EventSchemas.d.ts.map +1 -0
- package/components/EventSchemas.js +112 -0
- package/components/EventSchemas.js.map +1 -0
- package/components/Inngest.d.ts +96 -63
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +141 -50
- package/components/Inngest.js.map +1 -1
- package/components/InngestCommHandler.d.ts +4 -4
- package/components/InngestCommHandler.d.ts.map +1 -1
- package/components/InngestCommHandler.js +12 -14
- package/components/InngestCommHandler.js.map +1 -1
- package/components/InngestFunction.d.ts +73 -5
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +122 -61
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestMiddleware.d.ts +295 -0
- package/components/InngestMiddleware.d.ts.map +1 -0
- package/components/InngestMiddleware.js +96 -0
- package/components/InngestMiddleware.js.map +1 -0
- package/components/InngestRun.d.ts +17 -0
- package/components/InngestRun.d.ts.map +1 -0
- package/components/InngestRun.js +25 -0
- package/components/InngestRun.js.map +1 -0
- package/components/InngestStepTools.d.ts +7 -71
- package/components/InngestStepTools.d.ts.map +1 -1
- package/components/InngestStepTools.js +6 -41
- package/components/InngestStepTools.js.map +1 -1
- package/helpers/functions.d.ts +15 -0
- package/helpers/functions.d.ts.map +1 -1
- package/helpers/functions.js +36 -1
- package/helpers/functions.js.map +1 -1
- package/helpers/types.d.ts +16 -0
- package/helpers/types.d.ts.map +1 -1
- package/index.d.ts +6 -1
- package/index.d.ts.map +1 -1
- package/index.js +5 -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/package.json +1 -1
- package/types.d.ts +73 -22
- package/types.d.ts.map +1 -1
- package/types.js +8 -1
- package/types.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { type Simplify } from "type-fest";
|
|
2
|
+
import { type z } from "zod";
|
|
3
|
+
import { type IsStringLiteral } from "../helpers/types";
|
|
4
|
+
import { type EventPayload } from "../types";
|
|
5
|
+
/**
|
|
6
|
+
* Declares the shape of an event schema we expect from the user. This may be
|
|
7
|
+
* different to what a user is sending us depending on the supported library,
|
|
8
|
+
* but this standard format is what we require as the end result.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export type StandardEventSchema = {
|
|
13
|
+
data: Record<string, any>;
|
|
14
|
+
user?: Record<string, any>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A helper type that declares a standardised custom part of the event schema.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export type StandardEventSchemas = Record<string, StandardEventSchema>;
|
|
22
|
+
/**
|
|
23
|
+
* A helper type that declares a standardised custom part of the event schema,
|
|
24
|
+
* defined using Zod.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export type ZodEventSchemas = Record<string, {
|
|
29
|
+
data: z.AnyZodObject | z.ZodAny;
|
|
30
|
+
user?: z.AnyZodObject | z.ZodAny;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* A helper type to convert input schemas into the format expected by the
|
|
34
|
+
* `EventSchemas` class, which ensures that each event contains all pieces
|
|
35
|
+
* of information required.
|
|
36
|
+
*
|
|
37
|
+
* It purposefully uses slightly more complex (read: verbose) mapped types to
|
|
38
|
+
* flatten the output and preserve comments.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export type StandardEventSchemaToPayload<T> = Simplify<{
|
|
43
|
+
[K in keyof T & string]: {
|
|
44
|
+
[K2 in keyof (Omit<EventPayload, keyof T[K]> & T[K] & {
|
|
45
|
+
name: K;
|
|
46
|
+
})]: (Omit<EventPayload, keyof T[K]> & T[K] & {
|
|
47
|
+
name: K;
|
|
48
|
+
})[K2];
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* A helper type to combine two event schemas together, ensuring the result is
|
|
53
|
+
* as flat as possible and that we don't accidentally overwrite existing schemas
|
|
54
|
+
* with a generic `string` key.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export type Combine<TCurr extends Record<string, EventPayload>, TInc extends StandardEventSchemas> = IsStringLiteral<keyof TCurr & string> extends true ? Simplify<Omit<TCurr, keyof StandardEventSchemaToPayload<TInc>> & StandardEventSchemaToPayload<TInc>> : StandardEventSchemaToPayload<TInc>;
|
|
59
|
+
/**
|
|
60
|
+
* Provide an `EventSchemas` class to type events, providing type safety when
|
|
61
|
+
* sending events and running functions via Inngest.
|
|
62
|
+
*
|
|
63
|
+
* You can provide generated Inngest types, custom types, types using Zod, or
|
|
64
|
+
* a combination of the above. See {@link EventSchemas} for more information.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* export const inngest = new Inngest({
|
|
70
|
+
* name: "My App",
|
|
71
|
+
* schemas: new EventSchemas().fromZod({
|
|
72
|
+
* "app/user.created": {
|
|
73
|
+
* data: z.object({
|
|
74
|
+
* id: z.string(),
|
|
75
|
+
* name: z.string(),
|
|
76
|
+
* }),
|
|
77
|
+
* },
|
|
78
|
+
* }),
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export declare class EventSchemas<S extends Record<string, EventPayload>> {
|
|
85
|
+
/**
|
|
86
|
+
* Use generated Inngest types to type events.
|
|
87
|
+
*/
|
|
88
|
+
fromGenerated<T extends StandardEventSchemas>(): EventSchemas<Combine<S, T>>;
|
|
89
|
+
/**
|
|
90
|
+
* Use a `Record<>` type to type events.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* export const inngest = new Inngest({
|
|
96
|
+
* name: "My App",
|
|
97
|
+
* schemas: new EventSchemas().fromRecord<{
|
|
98
|
+
* "app/user.created": {
|
|
99
|
+
* data: {
|
|
100
|
+
* id: string;
|
|
101
|
+
* name: string;
|
|
102
|
+
* };
|
|
103
|
+
* };
|
|
104
|
+
* }>(),
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
fromRecord<T extends StandardEventSchemas>(): EventSchemas<Combine<S, T>>;
|
|
109
|
+
/**
|
|
110
|
+
* Use a union type to type events.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* type AccountCreated = {
|
|
116
|
+
* name: "app/account.created";
|
|
117
|
+
* data: { org: string };
|
|
118
|
+
* user: { id: string };
|
|
119
|
+
* };
|
|
120
|
+
*
|
|
121
|
+
* type AccountDeleted = {
|
|
122
|
+
* name: "app/account.deleted";
|
|
123
|
+
* data: { org: string };
|
|
124
|
+
* user: { id: string };
|
|
125
|
+
* };
|
|
126
|
+
*
|
|
127
|
+
* type Events = AccountCreated | AccountDeleted;
|
|
128
|
+
*
|
|
129
|
+
* export const inngest = new Inngest({
|
|
130
|
+
* name: "My App",
|
|
131
|
+
* schemas: new EventSchemas().fromUnion<Events>(),
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
fromUnion<T extends {
|
|
136
|
+
name: string;
|
|
137
|
+
} & StandardEventSchema>(): EventSchemas<Combine<S, { [K in T["name"]]: Extract<T, {
|
|
138
|
+
name: K;
|
|
139
|
+
}>; }>>;
|
|
140
|
+
/**
|
|
141
|
+
* Use Zod to type events.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* export const inngest = new Inngest({
|
|
147
|
+
* name: "My App",
|
|
148
|
+
* schemas: new EventSchemas().fromZod({
|
|
149
|
+
* "app/user.created": {
|
|
150
|
+
* data: z.object({
|
|
151
|
+
* id: z.string(),
|
|
152
|
+
* name: z.string(),
|
|
153
|
+
* }),
|
|
154
|
+
* },
|
|
155
|
+
* }),
|
|
156
|
+
* });
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
fromZod<T extends ZodEventSchemas>(schemas: T): EventSchemas<Combine<S, { [EventName in keyof T & string]: { [Key in keyof T[EventName] & string]: T[EventName][Key] extends z.ZodTypeAny ? z.TypeOf<T[EventName][Key]> : T[EventName][Key]; }; }>>;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=EventSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSchemas.d.ts","sourceRoot":"","sources":["../../src/components/EventSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAEhC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE1B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAClC,MAAM,EACN;IACE,IAAI,EAAE,CAAC,CAAC,YAAY,GAAG,CAAC,C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,SAAS;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,mBAAmB;;;IAWjE;;;;;;;;;;;;;;;;;;OAkBG;IAEI,OAAO,CAAC,CAAC,SAAS,eAAe,EAAE,OAAO,EAAE,CAAC;CAerD"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventSchemas = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Provide an `EventSchemas` class to type events, providing type safety when
|
|
6
|
+
* sending events and running functions via Inngest.
|
|
7
|
+
*
|
|
8
|
+
* You can provide generated Inngest types, custom types, types using Zod, or
|
|
9
|
+
* a combination of the above. See {@link EventSchemas} for more information.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* export const inngest = new Inngest({
|
|
15
|
+
* name: "My App",
|
|
16
|
+
* schemas: new EventSchemas().fromZod({
|
|
17
|
+
* "app/user.created": {
|
|
18
|
+
* data: z.object({
|
|
19
|
+
* id: z.string(),
|
|
20
|
+
* name: z.string(),
|
|
21
|
+
* }),
|
|
22
|
+
* },
|
|
23
|
+
* }),
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
class EventSchemas {
|
|
30
|
+
/**
|
|
31
|
+
* Use generated Inngest types to type events.
|
|
32
|
+
*/
|
|
33
|
+
fromGenerated() {
|
|
34
|
+
return new EventSchemas();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Use a `Record<>` type to type events.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* export const inngest = new Inngest({
|
|
43
|
+
* name: "My App",
|
|
44
|
+
* schemas: new EventSchemas().fromRecord<{
|
|
45
|
+
* "app/user.created": {
|
|
46
|
+
* data: {
|
|
47
|
+
* id: string;
|
|
48
|
+
* name: string;
|
|
49
|
+
* };
|
|
50
|
+
* };
|
|
51
|
+
* }>(),
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
fromRecord() {
|
|
56
|
+
return new EventSchemas();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Use a union type to type events.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* type AccountCreated = {
|
|
65
|
+
* name: "app/account.created";
|
|
66
|
+
* data: { org: string };
|
|
67
|
+
* user: { id: string };
|
|
68
|
+
* };
|
|
69
|
+
*
|
|
70
|
+
* type AccountDeleted = {
|
|
71
|
+
* name: "app/account.deleted";
|
|
72
|
+
* data: { org: string };
|
|
73
|
+
* user: { id: string };
|
|
74
|
+
* };
|
|
75
|
+
*
|
|
76
|
+
* type Events = AccountCreated | AccountDeleted;
|
|
77
|
+
*
|
|
78
|
+
* export const inngest = new Inngest({
|
|
79
|
+
* name: "My App",
|
|
80
|
+
* schemas: new EventSchemas().fromUnion<Events>(),
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
fromUnion() {
|
|
85
|
+
return new EventSchemas();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Use Zod to type events.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* export const inngest = new Inngest({
|
|
94
|
+
* name: "My App",
|
|
95
|
+
* schemas: new EventSchemas().fromZod({
|
|
96
|
+
* "app/user.created": {
|
|
97
|
+
* data: z.object({
|
|
98
|
+
* id: z.string(),
|
|
99
|
+
* name: z.string(),
|
|
100
|
+
* }),
|
|
101
|
+
* },
|
|
102
|
+
* }),
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
107
|
+
fromZod(schemas) {
|
|
108
|
+
return new EventSchemas();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.EventSchemas = EventSchemas;
|
|
112
|
+
//# sourceMappingURL=EventSchemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventSchemas.js","sourceRoot":"","sources":["../../src/components/EventSchemas.ts"],"names":[],"mappings":";;;AA6EA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,YAAY;IACvB;;OAEG;IACI,aAAa;QAClB,OAAO,IAAI,YAAY,EAAiB,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACI,UAAU;QACf,OAAO,IAAI,YAAY,EAAiB,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,SAAS;QACd,OAAO,IAAI,YAAY,EAOpB,CAAC;IACN,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,6DAA6D;IACtD,OAAO,CAA4B,OAAU;QAClD,OAAO,IAAI,YAAY,EAYpB,CAAC;IACN,CAAC;CACF;AAvGD,oCAuGC"}
|
package/components/Inngest.d.ts
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type
|
|
1
|
+
import { type SendEventPayload } from "../helpers/types";
|
|
2
|
+
import { type Logger } from "../middleware/logger";
|
|
3
|
+
import { type ClientOptions, type EventNameFromTrigger, type EventPayload, type FailureEventArgs, type FunctionOptions, type FunctionTrigger, type Handler, type MiddlewareStack, type ShimmedFns, type TriggerOptions } from "../types";
|
|
4
|
+
import { type EventSchemas } from "./EventSchemas";
|
|
3
5
|
import { InngestFunction } from "./InngestFunction";
|
|
6
|
+
import { InngestMiddleware, type MiddlewareStackRunInputMutation } from "./InngestMiddleware";
|
|
7
|
+
/**
|
|
8
|
+
* Given a set of client options for Inngest, return the event types that can
|
|
9
|
+
* be sent or received.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export type EventsFromOpts<TOpts extends ClientOptions> = TOpts["schemas"] extends EventSchemas<infer U> ? U : Record<string, EventPayload>;
|
|
4
14
|
/**
|
|
5
15
|
* A client used to interact with the Inngest API by sending or reacting to
|
|
6
16
|
* events.
|
|
7
17
|
*
|
|
8
|
-
* To provide event typing,
|
|
9
|
-
* the first generic.
|
|
18
|
+
* To provide event typing, see {@link EventSchemas}.
|
|
10
19
|
*
|
|
11
20
|
* ```ts
|
|
12
|
-
* const inngest = new Inngest
|
|
21
|
+
* const inngest = new Inngest({ name: "My App" });
|
|
13
22
|
*
|
|
14
|
-
* // or to provide
|
|
15
|
-
* const inngest = new Inngest
|
|
16
|
-
*
|
|
23
|
+
* // or to provide event typing too
|
|
24
|
+
* const inngest = new Inngest({
|
|
25
|
+
* name: "My App",
|
|
26
|
+
* schemas: new EventSchemas().fromRecord<{
|
|
17
27
|
* "app/user.created": {
|
|
18
|
-
*
|
|
19
|
-
* data: {
|
|
20
|
-
* foo: boolean;
|
|
21
|
-
* };
|
|
28
|
+
* data: { userId: string };
|
|
22
29
|
* };
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
30
|
+
* }>(),
|
|
31
|
+
* });
|
|
25
32
|
* ```
|
|
26
33
|
*
|
|
27
34
|
* @public
|
|
28
35
|
*/
|
|
29
|
-
export declare class Inngest<
|
|
36
|
+
export declare class Inngest<TOpts extends ClientOptions = ClientOptions> {
|
|
30
37
|
#private;
|
|
31
38
|
/**
|
|
32
39
|
* The name of this instance, most commonly the name of the application it
|
|
@@ -48,30 +55,37 @@ export declare class Inngest<Events extends Record<string, EventPayload> = Recor
|
|
|
48
55
|
private readonly headers;
|
|
49
56
|
private readonly fetch;
|
|
50
57
|
private readonly logger;
|
|
58
|
+
/**
|
|
59
|
+
* A promise that resolves when the middleware stack has been initialized and
|
|
60
|
+
* the client is ready to be used.
|
|
61
|
+
*/
|
|
62
|
+
private readonly middleware;
|
|
51
63
|
/**
|
|
52
64
|
* A client used to interact with the Inngest API by sending or reacting to
|
|
53
65
|
* events.
|
|
54
66
|
*
|
|
55
|
-
* To provide event typing,
|
|
56
|
-
* the first generic.
|
|
67
|
+
* To provide event typing, see {@link EventSchemas}.
|
|
57
68
|
*
|
|
58
69
|
* ```ts
|
|
59
|
-
* const inngest = new Inngest
|
|
70
|
+
* const inngest = new Inngest({ name: "My App" });
|
|
60
71
|
*
|
|
61
|
-
* // or to provide
|
|
62
|
-
* const inngest = new Inngest
|
|
63
|
-
*
|
|
72
|
+
* // or to provide event typing too
|
|
73
|
+
* const inngest = new Inngest({
|
|
74
|
+
* name: "My App",
|
|
75
|
+
* schemas: new EventSchemas().fromRecord<{
|
|
64
76
|
* "app/user.created": {
|
|
65
|
-
*
|
|
66
|
-
* data: {
|
|
67
|
-
* foo: boolean;
|
|
68
|
-
* };
|
|
77
|
+
* data: { userId: string };
|
|
69
78
|
* };
|
|
70
|
-
* }
|
|
71
|
-
*
|
|
79
|
+
* }>(),
|
|
80
|
+
* });
|
|
72
81
|
* ```
|
|
73
82
|
*/
|
|
74
|
-
constructor({ name, eventKey, inngestBaseUrl, fetch, env, logger, }:
|
|
83
|
+
constructor({ name, eventKey, inngestBaseUrl, fetch, env, logger, middleware, }: TOpts);
|
|
84
|
+
/**
|
|
85
|
+
* Initialize all passed middleware, running the `register` function on each
|
|
86
|
+
* in sequence and returning the requested hook registrations.
|
|
87
|
+
*/
|
|
88
|
+
private initializeMiddleware;
|
|
75
89
|
/**
|
|
76
90
|
* Set the event key for this instance of Inngest. This is useful if for some
|
|
77
91
|
* reason the key is not available at time of instantiation or present in the
|
|
@@ -84,31 +98,6 @@ export declare class Inngest<Events extends Record<string, EventPayload> = Recor
|
|
|
84
98
|
* in the `INNGEST_EVENT_KEY` environment variable.
|
|
85
99
|
*/
|
|
86
100
|
eventKey: string): void;
|
|
87
|
-
/**
|
|
88
|
-
* Send one or many events to Inngest. Takes a known event from this Inngest
|
|
89
|
-
* instance based on the given `name`.
|
|
90
|
-
*
|
|
91
|
-
* ```ts
|
|
92
|
-
* await inngest.send("app/user.created", { data: { id: 123 } });
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* Returns a promise that will resolve if the event(s) were sent successfully,
|
|
96
|
-
* else throws with an error explaining what went wrong.
|
|
97
|
-
*
|
|
98
|
-
* If you wish to send an event with custom types (i.e. one that hasn't been
|
|
99
|
-
* generated), make sure to add it when creating your Inngest instance, like
|
|
100
|
-
* so:
|
|
101
|
-
*
|
|
102
|
-
* ```ts
|
|
103
|
-
* const inngest = new Inngest<Events & {
|
|
104
|
-
* "my/event": {
|
|
105
|
-
* name: "my/event";
|
|
106
|
-
* data: { bar: string; };
|
|
107
|
-
* }
|
|
108
|
-
* }>("My App", "API_KEY");
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
send<Event extends keyof Events>(name: Event, payload: SingleOrArray<PartialK<Omit<Events[Event], "name" | "v">, "ts">>): Promise<void>;
|
|
112
101
|
/**
|
|
113
102
|
* Send one or many events to Inngest. Takes an entire payload (including
|
|
114
103
|
* name) as each input.
|
|
@@ -125,16 +114,19 @@ export declare class Inngest<Events extends Record<string, EventPayload> = Recor
|
|
|
125
114
|
* so:
|
|
126
115
|
*
|
|
127
116
|
* ```ts
|
|
128
|
-
* const inngest = new Inngest
|
|
129
|
-
* "
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
117
|
+
* const inngest = new Inngest({
|
|
118
|
+
* name: "My App",
|
|
119
|
+
* schemas: new EventSchemas().fromRecord<{
|
|
120
|
+
* "my/event": {
|
|
121
|
+
* name: "my/event";
|
|
122
|
+
* data: { bar: string };
|
|
123
|
+
* };
|
|
124
|
+
* }>(),
|
|
125
|
+
* });
|
|
134
126
|
* ```
|
|
135
127
|
*/
|
|
136
|
-
send<Payload extends SendEventPayload<
|
|
137
|
-
createFunction<TFns extends Record<string, unknown>, TTrigger extends TriggerOptions<keyof
|
|
128
|
+
send<Payload extends SendEventPayload<EventsFromOpts<TOpts>>>(payload: Payload): Promise<void>;
|
|
129
|
+
createFunction<TFns extends Record<string, unknown>, TMiddleware extends MiddlewareStack, TTrigger extends TriggerOptions<keyof EventsFromOpts<TOpts> & string>, TShimmedFns extends Record<string, (...args: any[]) => any> = ShimmedFns<TFns>, TTriggerName extends keyof EventsFromOpts<TOpts> & string = EventNameFromTrigger<EventsFromOpts<TOpts>, TTrigger>>(nameOrOpts: string | (Omit<FunctionOptions<EventsFromOpts<TOpts>, TTriggerName>, "fns" | "onFailure" | "middleware"> & {
|
|
138
130
|
/**
|
|
139
131
|
* Pass in an object of functions that will be wrapped in Inngest
|
|
140
132
|
* tooling and passes to your handler. This wrapping ensures that each
|
|
@@ -176,7 +168,48 @@ export declare class Inngest<Events extends Record<string, EventPayload> = Recor
|
|
|
176
168
|
* after a failure and supports all the same functionality as a
|
|
177
169
|
* regular handler.
|
|
178
170
|
*/
|
|
179
|
-
onFailure?: Handler<
|
|
180
|
-
|
|
171
|
+
onFailure?: Handler<TOpts, EventsFromOpts<TOpts>, TTriggerName, TShimmedFns, FailureEventArgs<EventsFromOpts<TOpts>[TTriggerName]>>;
|
|
172
|
+
/**
|
|
173
|
+
* TODO
|
|
174
|
+
*/
|
|
175
|
+
middleware?: TMiddleware;
|
|
176
|
+
}), trigger: TTrigger, handler: Handler<TOpts, EventsFromOpts<TOpts>, TTriggerName, TShimmedFns, MiddlewareStackRunInputMutation<{}, typeof builtInMiddleware> & MiddlewareStackRunInputMutation<{}, NonNullable<TOpts["middleware"]>> & MiddlewareStackRunInputMutation<{}, TMiddleware>>): InngestFunction<TOpts, EventsFromOpts<TOpts>, FunctionTrigger<keyof EventsFromOpts<TOpts> & string>, FunctionOptions<EventsFromOpts<TOpts>, keyof EventsFromOpts<TOpts> & string>>;
|
|
181
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Default middleware that is included in every client, placed after the user's
|
|
180
|
+
* middleware on the client but before function-level middleware.
|
|
181
|
+
*
|
|
182
|
+
* It is defined here to ensure that comments are included in the generated TS
|
|
183
|
+
* definitions. Without this, we infer the stack of built-in middleware without
|
|
184
|
+
* comments, losing a lot of value.
|
|
185
|
+
*
|
|
186
|
+
* If this is moved, please ensure that using this package in another project
|
|
187
|
+
* can correctly access comments on mutated input and output.
|
|
188
|
+
*/
|
|
189
|
+
declare const builtInMiddleware: [InngestMiddleware<{
|
|
190
|
+
name: string;
|
|
191
|
+
register({ client }: {
|
|
192
|
+
client: Inngest<any>;
|
|
193
|
+
fn?: InngestFunction<any, any, any, any> | undefined;
|
|
194
|
+
}): {
|
|
195
|
+
run(): {
|
|
196
|
+
input(): {
|
|
197
|
+
ctx: {
|
|
198
|
+
/**
|
|
199
|
+
* The passed in logger from the user.
|
|
200
|
+
* Defaults to a console logger if not provided.
|
|
201
|
+
*/
|
|
202
|
+
logger: Logger;
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
beforeExecution(): void;
|
|
206
|
+
output({ result: { error } }: {
|
|
207
|
+
result: Readonly<Pick<import("../types").OutgoingOp, "data" | "error">>;
|
|
208
|
+
step?: Readonly<Omit<import("../types").OutgoingOp, "id">> | undefined;
|
|
209
|
+
}): void;
|
|
210
|
+
beforeResponse(): Promise<void>;
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
}>];
|
|
214
|
+
export {};
|
|
182
215
|
//# sourceMappingURL=Inngest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":"AAUA,OAAO,
|
|
1
|
+
{"version":3,"file":"Inngest.d.ts","sourceRoot":"","sources":["../../src/components/Inngest.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAA8B,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EACL,K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