effect-inngest 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +457 -0
- package/dist/Client.d.ts +167 -0
- package/dist/Client.js +144 -0
- package/dist/Events.d.ts +110 -0
- package/dist/Events.js +93 -0
- package/dist/Function.d.ts +384 -0
- package/dist/Function.js +104 -0
- package/dist/Group.d.ts +152 -0
- package/dist/Group.js +164 -0
- package/dist/HttpApi.d.ts +75 -0
- package/dist/HttpApi.js +47 -0
- package/dist/_virtual/rolldown_runtime.js +18 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/internal/constants.js +15 -0
- package/dist/internal/driver.d.ts +5 -0
- package/dist/internal/driver.js +117 -0
- package/dist/internal/errors.d.ts +56 -0
- package/dist/internal/errors.js +61 -0
- package/dist/internal/handler.d.ts +20 -0
- package/dist/internal/handler.js +145 -0
- package/dist/internal/helpers.js +44 -0
- package/dist/internal/interrupts.d.ts +2 -0
- package/dist/internal/interrupts.js +45 -0
- package/dist/internal/memo.js +56 -0
- package/dist/internal/protocol.d.ts +1 -0
- package/dist/internal/protocol.js +191 -0
- package/dist/internal/signature.d.ts +18 -0
- package/dist/internal/signature.js +97 -0
- package/dist/internal/step.d.ts +59 -0
- package/dist/internal/step.js +183 -0
- package/package.json +121 -0
- package/src/Client.ts +279 -0
- package/src/Events.ts +87 -0
- package/src/Function.ts +493 -0
- package/src/Group.ts +314 -0
- package/src/HttpApi.ts +82 -0
- package/src/index.ts +171 -0
- package/src/internal/constants.ts +11 -0
- package/src/internal/driver.ts +194 -0
- package/src/internal/errors.ts +130 -0
- package/src/internal/handler.ts +222 -0
- package/src/internal/helpers.ts +58 -0
- package/src/internal/interrupts.ts +62 -0
- package/src/internal/memo.ts +73 -0
- package/src/internal/protocol.ts +218 -0
- package/src/internal/signature.ts +158 -0
- package/src/internal/step.ts +377 -0
package/dist/Client.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import { Headers } from "./internal/protocol.js";
|
|
3
|
+
import * as HttpClient from "@effect/platform/HttpClient";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Option from "effect/Option";
|
|
8
|
+
import * as Schema from "effect/Schema";
|
|
9
|
+
import * as HttpClientRequest from "@effect/platform/HttpClientRequest";
|
|
10
|
+
import * as HttpClientResponse from "@effect/platform/HttpClientResponse";
|
|
11
|
+
import * as Config from "effect/Config";
|
|
12
|
+
import * as Predicate from "effect/Predicate";
|
|
13
|
+
|
|
14
|
+
//#region src/Client.ts
|
|
15
|
+
/**
|
|
16
|
+
* @since 0.1.0
|
|
17
|
+
*/
|
|
18
|
+
var Client_exports = /* @__PURE__ */ __exportAll({
|
|
19
|
+
EventPayload: () => EventPayload,
|
|
20
|
+
InngestClient: () => InngestClient,
|
|
21
|
+
layer: () => layer,
|
|
22
|
+
layerConfig: () => layerConfig,
|
|
23
|
+
layerFromEnv: () => layerFromEnv
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
* @category type ids
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
const TypeId = Symbol.for("effect-inngest/Client");
|
|
31
|
+
const DEFAULT_EVENT_BASE_URL = "https://inn.gs/";
|
|
32
|
+
const DEFAULT_API_BASE_URL = "https://api.inngest.com/";
|
|
33
|
+
const DEFAULT_DEV_SERVER_URL = "http://localhost:8288/";
|
|
34
|
+
const SDK_VERSION = "2.0.0";
|
|
35
|
+
const EventPayload = Schema.Struct({
|
|
36
|
+
name: Schema.String,
|
|
37
|
+
data: Schema.Unknown,
|
|
38
|
+
ts: Schema.optional(Schema.Number),
|
|
39
|
+
id: Schema.optional(Schema.String),
|
|
40
|
+
v: Schema.optional(Schema.String)
|
|
41
|
+
});
|
|
42
|
+
const SendEventResponse = Schema.Struct({
|
|
43
|
+
ids: Schema.optionalWith(Schema.Array(Schema.String), { default: () => [] }),
|
|
44
|
+
status: Schema.optional(Schema.Number)
|
|
45
|
+
});
|
|
46
|
+
var SendEventError = class extends Schema.TaggedError()("SendEventError", {
|
|
47
|
+
message: Schema.String,
|
|
48
|
+
events: Schema.Array(Schema.String)
|
|
49
|
+
}) {};
|
|
50
|
+
/**
|
|
51
|
+
* InngestClient service for communicating with Inngest.
|
|
52
|
+
*
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
* @category context
|
|
55
|
+
*/
|
|
56
|
+
var InngestClient = class extends Context.Tag("effect-inngest/InngestClient")() {};
|
|
57
|
+
const resolveMode = (config) => config.mode ?? "dev";
|
|
58
|
+
const resolveEventBaseUrl = (config, mode) => config.eventBaseUrl ?? (mode === "dev" ? DEFAULT_DEV_SERVER_URL : DEFAULT_EVENT_BASE_URL);
|
|
59
|
+
const resolveApiBaseUrl = (config, mode) => config.apiBaseUrl ?? (mode === "dev" ? DEFAULT_DEV_SERVER_URL : DEFAULT_API_BASE_URL);
|
|
60
|
+
const makeClient = (config, httpClient) => {
|
|
61
|
+
const mode = resolveMode(config);
|
|
62
|
+
const eventBaseUrl = resolveEventBaseUrl(config, mode);
|
|
63
|
+
const apiBaseUrl = resolveApiBaseUrl(config, mode);
|
|
64
|
+
const sendEvent = (events) => {
|
|
65
|
+
if (!config.eventKey && mode === "cloud") return new SendEventError({
|
|
66
|
+
message: "Event key is required to send events in cloud mode",
|
|
67
|
+
events: events.map((e) => e.name)
|
|
68
|
+
});
|
|
69
|
+
const key = config.eventKey ?? "local";
|
|
70
|
+
const url = new URL(`e/${key}`, eventBaseUrl).toString();
|
|
71
|
+
const eventNames = events.map((e) => e.name);
|
|
72
|
+
const now = Date.now();
|
|
73
|
+
const payloads = events.map((e) => ({
|
|
74
|
+
name: e.name,
|
|
75
|
+
data: e.data ?? {},
|
|
76
|
+
ts: e.ts ?? now,
|
|
77
|
+
id: e.id,
|
|
78
|
+
v: e.v
|
|
79
|
+
}));
|
|
80
|
+
const request = HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders({
|
|
81
|
+
"Content-Type": "application/json",
|
|
82
|
+
[Headers.SDK]: `effect-ts:v${SDK_VERSION}`,
|
|
83
|
+
...config.env ? { [Headers.Env]: config.env } : {}
|
|
84
|
+
}));
|
|
85
|
+
return HttpClientRequest.schemaBodyJson(Schema.Array(EventPayload))(request, payloads).pipe(Effect.flatMap(httpClient.execute), Effect.flatMap(HttpClientResponse.schemaBodyJson(SendEventResponse)), Effect.map((response) => ({
|
|
86
|
+
ids: response.ids,
|
|
87
|
+
status: response.status
|
|
88
|
+
})), Effect.scoped, Effect.catchAll((error) => new SendEventError({
|
|
89
|
+
message: `Failed to send events: ${Predicate.hasProperty(error, "message") ? error.message : "Unknown error"}`,
|
|
90
|
+
events: eventNames
|
|
91
|
+
})));
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
[TypeId]: TypeId,
|
|
95
|
+
config,
|
|
96
|
+
mode,
|
|
97
|
+
eventBaseUrl,
|
|
98
|
+
apiBaseUrl,
|
|
99
|
+
sendEvent
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Create an InngestClient layer from a config.
|
|
104
|
+
*
|
|
105
|
+
* @since 0.1.0
|
|
106
|
+
* @category layers
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const ClientLive = InngestClient.layer({
|
|
110
|
+
* id: "my-app",
|
|
111
|
+
* eventKey: "my-event-key",
|
|
112
|
+
* })
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
const layer = (config) => Layer.effect(InngestClient, Effect.map(HttpClient.HttpClient, (httpClient) => makeClient(config, httpClient)));
|
|
116
|
+
/**
|
|
117
|
+
* Create an InngestClient layer from Effect Config.
|
|
118
|
+
*
|
|
119
|
+
* @since 0.1.0
|
|
120
|
+
* @category layers
|
|
121
|
+
*/
|
|
122
|
+
const layerConfig = (config) => Layer.effect(InngestClient, Effect.flatMap(Config.unwrap(config), (resolvedConfig) => Effect.map(HttpClient.HttpClient, (httpClient) => makeClient(resolvedConfig, httpClient))));
|
|
123
|
+
/**
|
|
124
|
+
* Create an InngestClient layer from environment variables.
|
|
125
|
+
*
|
|
126
|
+
* Uses:
|
|
127
|
+
* - INNGEST_APP_ID or "app" as id
|
|
128
|
+
* - INNGEST_EVENT_KEY for event key
|
|
129
|
+
* - INNGEST_SIGNING_KEY for signing key
|
|
130
|
+
*
|
|
131
|
+
* Mode is inferred from environment (INNGEST_DEV, NODE_ENV, etc.)
|
|
132
|
+
*
|
|
133
|
+
* @since 0.1.0
|
|
134
|
+
* @category layers
|
|
135
|
+
*/
|
|
136
|
+
const layerFromEnv = layerConfig(Config.all({
|
|
137
|
+
id: Config.string("INNGEST_APP_ID").pipe(Config.withDefault("app")),
|
|
138
|
+
eventKey: Config.string("INNGEST_EVENT_KEY").pipe(Config.option, Config.map(Option.getOrUndefined)),
|
|
139
|
+
signingKey: Config.string("INNGEST_SIGNING_KEY").pipe(Config.option, Config.map(Option.getOrUndefined)),
|
|
140
|
+
signingKeyFallback: Config.string("INNGEST_SIGNING_KEY_FALLBACK").pipe(Config.option, Config.map(Option.getOrUndefined))
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
export { Client_exports, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
package/dist/Events.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
|
|
3
|
+
//#region src/Events.d.ts
|
|
4
|
+
declare namespace Events_d_exports {
|
|
5
|
+
export { FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
|
|
6
|
+
}
|
|
7
|
+
declare const JsonError_base: Schema.Class<JsonError, {
|
|
8
|
+
name: typeof Schema.String;
|
|
9
|
+
message: typeof Schema.String;
|
|
10
|
+
stack: Schema.optional<typeof Schema.String>;
|
|
11
|
+
cause: Schema.optional<typeof Schema.Unknown>;
|
|
12
|
+
}, Schema.Struct.Encoded<{
|
|
13
|
+
name: typeof Schema.String;
|
|
14
|
+
message: typeof Schema.String;
|
|
15
|
+
stack: Schema.optional<typeof Schema.String>;
|
|
16
|
+
cause: Schema.optional<typeof Schema.Unknown>;
|
|
17
|
+
}>, never, {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
} & {
|
|
20
|
+
readonly message: string;
|
|
21
|
+
} & {
|
|
22
|
+
readonly stack?: string | undefined;
|
|
23
|
+
} & {
|
|
24
|
+
readonly cause?: unknown;
|
|
25
|
+
}, {}, {}>;
|
|
26
|
+
/**
|
|
27
|
+
* Error structure used in internal Inngest events.
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
declare class JsonError extends JsonError_base {}
|
|
31
|
+
declare const FunctionFailed_base: Schema.TaggedClass<FunctionFailed, "inngest/function.failed", {
|
|
32
|
+
readonly _tag: Schema.tag<"inngest/function.failed">;
|
|
33
|
+
} & {
|
|
34
|
+
function_id: typeof Schema.String;
|
|
35
|
+
run_id: typeof Schema.String;
|
|
36
|
+
error: typeof JsonError;
|
|
37
|
+
event: Schema.Record$<typeof Schema.String, typeof Schema.Unknown>;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Sent when a function fails after exhausting all retries.
|
|
41
|
+
* Trigger on this to handle failures (e.g., alerting, cleanup).
|
|
42
|
+
* @since 0.1.0
|
|
43
|
+
*/
|
|
44
|
+
declare class FunctionFailed extends FunctionFailed_base {}
|
|
45
|
+
declare const FunctionFinishedError_base: Schema.TaggedClass<FunctionFinishedError, "inngest/function.finished", {
|
|
46
|
+
readonly _tag: Schema.tag<"inngest/function.finished">;
|
|
47
|
+
} & {
|
|
48
|
+
function_id: typeof Schema.String;
|
|
49
|
+
run_id: typeof Schema.String;
|
|
50
|
+
correlation_id: Schema.optional<typeof Schema.String>;
|
|
51
|
+
error: typeof JsonError;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Sent when a function finishes with an error.
|
|
55
|
+
* @since 0.1.0
|
|
56
|
+
*/
|
|
57
|
+
declare class FunctionFinishedError extends FunctionFinishedError_base {}
|
|
58
|
+
declare const FunctionFinishedSuccess_base: Schema.TaggedClass<FunctionFinishedSuccess, "inngest/function.finished", {
|
|
59
|
+
readonly _tag: Schema.tag<"inngest/function.finished">;
|
|
60
|
+
} & {
|
|
61
|
+
function_id: typeof Schema.String;
|
|
62
|
+
run_id: typeof Schema.String;
|
|
63
|
+
correlation_id: Schema.optional<typeof Schema.String>;
|
|
64
|
+
result: typeof Schema.Unknown;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Sent when a function finishes successfully.
|
|
68
|
+
* @since 0.1.0
|
|
69
|
+
*/
|
|
70
|
+
declare class FunctionFinishedSuccess extends FunctionFinishedSuccess_base {}
|
|
71
|
+
/**
|
|
72
|
+
* Union of both FunctionFinished variants.
|
|
73
|
+
* @since 0.1.0
|
|
74
|
+
*/
|
|
75
|
+
declare const FunctionFinished: Schema.Union<[typeof FunctionFinishedError, typeof FunctionFinishedSuccess]>;
|
|
76
|
+
type FunctionFinished = typeof FunctionFinished.Type;
|
|
77
|
+
declare const FunctionCancelled_base: Schema.TaggedClass<FunctionCancelled, "inngest/function.cancelled", {
|
|
78
|
+
readonly _tag: Schema.tag<"inngest/function.cancelled">;
|
|
79
|
+
} & {
|
|
80
|
+
function_id: typeof Schema.String;
|
|
81
|
+
run_id: typeof Schema.String;
|
|
82
|
+
correlation_id: Schema.optional<typeof Schema.String>;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Sent when a function is cancelled.
|
|
86
|
+
* @since 0.1.0
|
|
87
|
+
*/
|
|
88
|
+
declare class FunctionCancelled extends FunctionCancelled_base {}
|
|
89
|
+
declare const FunctionInvoked_base: Schema.TaggedClass<FunctionInvoked, "inngest/function.invoked", {
|
|
90
|
+
readonly _tag: Schema.tag<"inngest/function.invoked">;
|
|
91
|
+
} & {
|
|
92
|
+
data: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Sent when a function is invoked via step.invoke().
|
|
96
|
+
* @since 0.1.0
|
|
97
|
+
*/
|
|
98
|
+
declare class FunctionInvoked extends FunctionInvoked_base {}
|
|
99
|
+
declare const ScheduledTimer_base: Schema.TaggedClass<ScheduledTimer, "inngest/scheduled.timer", {
|
|
100
|
+
readonly _tag: Schema.tag<"inngest/scheduled.timer">;
|
|
101
|
+
} & {
|
|
102
|
+
cron: typeof Schema.String;
|
|
103
|
+
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Sent when a cron trigger fires.
|
|
106
|
+
* @since 0.1.0
|
|
107
|
+
*/
|
|
108
|
+
declare class ScheduledTimer extends ScheduledTimer_base {}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { Events_d_exports, FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
|
package/dist/Events.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
|
|
4
|
+
//#region src/Events.ts
|
|
5
|
+
/**
|
|
6
|
+
* Internal Inngest events that the platform sends automatically.
|
|
7
|
+
* Use these as triggers to react to function lifecycle events.
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
*/
|
|
10
|
+
var Events_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
FunctionCancelled: () => FunctionCancelled,
|
|
12
|
+
FunctionFailed: () => FunctionFailed,
|
|
13
|
+
FunctionFinished: () => FunctionFinished,
|
|
14
|
+
FunctionFinishedError: () => FunctionFinishedError,
|
|
15
|
+
FunctionFinishedSuccess: () => FunctionFinishedSuccess,
|
|
16
|
+
FunctionInvoked: () => FunctionInvoked,
|
|
17
|
+
JsonError: () => JsonError,
|
|
18
|
+
ScheduledTimer: () => ScheduledTimer
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Error structure used in internal Inngest events.
|
|
22
|
+
* @since 0.1.0
|
|
23
|
+
*/
|
|
24
|
+
var JsonError = class extends Schema.Class("JsonError")({
|
|
25
|
+
name: Schema.String,
|
|
26
|
+
message: Schema.String,
|
|
27
|
+
stack: Schema.optional(Schema.String),
|
|
28
|
+
cause: Schema.optional(Schema.Unknown)
|
|
29
|
+
}) {};
|
|
30
|
+
/**
|
|
31
|
+
* Sent when a function fails after exhausting all retries.
|
|
32
|
+
* Trigger on this to handle failures (e.g., alerting, cleanup).
|
|
33
|
+
* @since 0.1.0
|
|
34
|
+
*/
|
|
35
|
+
var FunctionFailed = class extends Schema.TaggedClass()("inngest/function.failed", {
|
|
36
|
+
function_id: Schema.String,
|
|
37
|
+
run_id: Schema.String,
|
|
38
|
+
error: JsonError,
|
|
39
|
+
event: Schema.Record({
|
|
40
|
+
key: Schema.String,
|
|
41
|
+
value: Schema.Unknown
|
|
42
|
+
})
|
|
43
|
+
}) {};
|
|
44
|
+
/**
|
|
45
|
+
* Sent when a function finishes with an error.
|
|
46
|
+
* @since 0.1.0
|
|
47
|
+
*/
|
|
48
|
+
var FunctionFinishedError = class extends Schema.TaggedClass()("inngest/function.finished", {
|
|
49
|
+
function_id: Schema.String,
|
|
50
|
+
run_id: Schema.String,
|
|
51
|
+
correlation_id: Schema.optional(Schema.String),
|
|
52
|
+
error: JsonError
|
|
53
|
+
}) {};
|
|
54
|
+
/**
|
|
55
|
+
* Sent when a function finishes successfully.
|
|
56
|
+
* @since 0.1.0
|
|
57
|
+
*/
|
|
58
|
+
var FunctionFinishedSuccess = class extends Schema.TaggedClass()("inngest/function.finished", {
|
|
59
|
+
function_id: Schema.String,
|
|
60
|
+
run_id: Schema.String,
|
|
61
|
+
correlation_id: Schema.optional(Schema.String),
|
|
62
|
+
result: Schema.Unknown
|
|
63
|
+
}) {};
|
|
64
|
+
/**
|
|
65
|
+
* Union of both FunctionFinished variants.
|
|
66
|
+
* @since 0.1.0
|
|
67
|
+
*/
|
|
68
|
+
const FunctionFinished = Schema.Union(FunctionFinishedError, FunctionFinishedSuccess);
|
|
69
|
+
/**
|
|
70
|
+
* Sent when a function is cancelled.
|
|
71
|
+
* @since 0.1.0
|
|
72
|
+
*/
|
|
73
|
+
var FunctionCancelled = class extends Schema.TaggedClass()("inngest/function.cancelled", {
|
|
74
|
+
function_id: Schema.String,
|
|
75
|
+
run_id: Schema.String,
|
|
76
|
+
correlation_id: Schema.optional(Schema.String)
|
|
77
|
+
}) {};
|
|
78
|
+
/**
|
|
79
|
+
* Sent when a function is invoked via step.invoke().
|
|
80
|
+
* @since 0.1.0
|
|
81
|
+
*/
|
|
82
|
+
var FunctionInvoked = class extends Schema.TaggedClass()("inngest/function.invoked", { data: Schema.optional(Schema.Record({
|
|
83
|
+
key: Schema.String,
|
|
84
|
+
value: Schema.Unknown
|
|
85
|
+
})) }) {};
|
|
86
|
+
/**
|
|
87
|
+
* Sent when a cron trigger fires.
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
90
|
+
var ScheduledTimer = class extends Schema.TaggedClass()("inngest/scheduled.timer", { cron: Schema.String }) {};
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
export { Events_exports, FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
|