effect-inngest 0.1.2 → 0.2.0-beta.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/dist/Client.d.ts +55 -24
- package/dist/Client.js +84 -25
- package/dist/Events.d.ts +36 -61
- package/dist/Events.js +5 -13
- package/dist/Function.d.ts +35 -15
- package/dist/Function.js +14 -8
- package/dist/Group.d.ts +5 -4
- package/dist/Group.js +26 -24
- package/dist/HttpApi.d.ts +49 -54
- package/dist/HttpApi.js +32 -17
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.js +1 -2
- package/dist/internal/checkpoint.d.ts +32 -0
- package/dist/internal/checkpoint.js +112 -0
- package/dist/internal/constants.js +1 -2
- package/dist/internal/driver.d.ts +1 -5
- package/dist/internal/driver.js +164 -52
- package/dist/internal/errors.d.ts +20 -27
- package/dist/internal/errors.js +29 -15
- package/dist/internal/handler.d.ts +4 -13
- package/dist/internal/handler.js +70 -43
- package/dist/internal/helpers.js +12 -9
- package/dist/internal/interrupts.d.ts +1 -2
- package/dist/internal/interrupts.js +1 -3
- package/dist/internal/memo.js +22 -20
- package/dist/internal/protocol.d.ts +28 -1
- package/dist/internal/protocol.js +84 -52
- package/dist/internal/signature.d.ts +5 -9
- package/dist/internal/signature.js +34 -18
- package/dist/internal/step.d.ts +5 -11
- package/dist/internal/step.js +48 -32
- package/package.json +26 -21
- package/src/Client.ts +244 -68
- package/src/Events.ts +3 -3
- package/src/Function.ts +52 -15
- package/src/Group.ts +39 -26
- package/src/HttpApi.ts +38 -27
- package/src/internal/checkpoint.ts +218 -0
- package/src/internal/driver.ts +241 -93
- package/src/internal/errors.ts +21 -14
- package/src/internal/handler.ts +185 -142
- package/src/internal/helpers.ts +9 -9
- package/src/internal/memo.ts +48 -33
- package/src/internal/protocol.ts +89 -45
- package/src/internal/signature.ts +76 -58
- package/src/internal/step.ts +83 -32
- package/dist/_virtual/rolldown_runtime.js +0 -18
package/dist/Client.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { GeneratorOpcode } from "./internal/protocol.js";
|
|
2
|
+
import { CheckpointApiError, CheckpointingOption } from "./internal/checkpoint.js";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as Layer from "effect/Layer";
|
|
5
4
|
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
6
8
|
import * as Config from "effect/Config";
|
|
7
|
-
import * as
|
|
9
|
+
import * as _$effect_Cause0 from "effect/Cause";
|
|
8
10
|
|
|
9
11
|
//#region src/Client.d.ts
|
|
10
12
|
declare namespace Client_d_exports {
|
|
11
|
-
export { EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
|
13
|
+
export { CheckpointApiError, CheckpointingOption, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* @since 0.1.0
|
|
@@ -89,28 +91,40 @@ interface ClientConfig {
|
|
|
89
91
|
* The path where the Inngest serve handler is mounted. Used for registration.
|
|
90
92
|
*/
|
|
91
93
|
readonly servePath?: string | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Whether to use checkpointing by default for executions of functions
|
|
96
|
+
* created using this client.
|
|
97
|
+
*
|
|
98
|
+
* - `false` disables checkpointing for all functions on this client.
|
|
99
|
+
* - `true` enables checkpointing with safe defaults (`bufferedSteps: 1`,
|
|
100
|
+
* `maxInterval: 0`, `maxRuntime: 10s`). Steps are checkpointed to the
|
|
101
|
+
* Inngest API as they complete instead of yielding a 206 per step.
|
|
102
|
+
* - An object lets you tune `bufferedSteps`, `maxInterval`, `maxRuntime`.
|
|
103
|
+
*
|
|
104
|
+
* Per-function `checkpointing` overrides this setting. Defaults to `true`
|
|
105
|
+
* (checkpointing enabled).
|
|
106
|
+
*
|
|
107
|
+
* @default true
|
|
108
|
+
*/
|
|
109
|
+
readonly checkpointing?: CheckpointingOption | undefined;
|
|
92
110
|
}
|
|
93
111
|
declare const EventPayload: Schema.Struct<{
|
|
94
|
-
name:
|
|
95
|
-
data:
|
|
96
|
-
ts: Schema.optional<
|
|
97
|
-
id: Schema.optional<
|
|
98
|
-
v: Schema.optional<
|
|
112
|
+
readonly name: Schema.String;
|
|
113
|
+
readonly data: Schema.Unknown;
|
|
114
|
+
readonly ts: Schema.optional<Schema.Number>;
|
|
115
|
+
readonly id: Schema.optional<Schema.String>;
|
|
116
|
+
readonly v: Schema.optional<Schema.String>;
|
|
99
117
|
}>;
|
|
100
118
|
declare const SendEventResponse: Schema.Struct<{
|
|
101
|
-
ids: Schema.
|
|
102
|
-
|
|
103
|
-
}>;
|
|
104
|
-
status: Schema.optional<typeof Schema.Number>;
|
|
119
|
+
readonly ids: Schema.withDecodingDefault<Schema.$Array<Schema.String>>;
|
|
120
|
+
readonly status: Schema.optional<Schema.Number>;
|
|
105
121
|
}>;
|
|
106
122
|
type EventPayload = typeof EventPayload.Type;
|
|
107
123
|
type SendEventResponse = typeof SendEventResponse.Type;
|
|
108
|
-
declare const SendEventError_base: Schema.
|
|
109
|
-
readonly
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
events: Schema.Array$<typeof Schema.String>;
|
|
113
|
-
}>;
|
|
124
|
+
declare const SendEventError_base: Schema.Class<SendEventError, Schema.TaggedStruct<"SendEventError", {
|
|
125
|
+
readonly message: Schema.String;
|
|
126
|
+
readonly events: Schema.$Array<Schema.String>;
|
|
127
|
+
}>, _$effect_Cause0.YieldableError>;
|
|
114
128
|
declare class SendEventError extends SendEventError_base {}
|
|
115
129
|
interface InngestClientService {
|
|
116
130
|
readonly [TypeId]: TypeId;
|
|
@@ -119,8 +133,25 @@ interface InngestClientService {
|
|
|
119
133
|
readonly eventBaseUrl: string;
|
|
120
134
|
readonly apiBaseUrl: string;
|
|
121
135
|
readonly sendEvent: (events: ReadonlyArray<EventPayload>) => Effect.Effect<SendEventResponse, SendEventError>;
|
|
136
|
+
/**
|
|
137
|
+
* Async checkpoint API call per spec §10.3.1.
|
|
138
|
+
*
|
|
139
|
+
* POSTs `{run_id, fn_id, qi_id, steps, ts}` to
|
|
140
|
+
* `{apiBaseUrl}/v1/checkpoint/{runId}/async` with a hashed-signing-key
|
|
141
|
+
* Bearer token. Retries 5xx responses with exponential backoff + jitter
|
|
142
|
+
* (5 attempts). On 401, falls back to the configured fallback signing key
|
|
143
|
+
* for the remainder of the client's lifetime (one-way switch).
|
|
144
|
+
*
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
readonly checkpointAsync: (args: {
|
|
148
|
+
readonly runId: string;
|
|
149
|
+
readonly fnId: string;
|
|
150
|
+
readonly qiId: string;
|
|
151
|
+
readonly steps: ReadonlyArray<typeof GeneratorOpcode.Type>;
|
|
152
|
+
}) => Effect.Effect<void, CheckpointApiError>;
|
|
122
153
|
}
|
|
123
|
-
declare const InngestClient_base: Context.
|
|
154
|
+
declare const InngestClient_base: Context.ServiceClass<InngestClient, "effect-inngest/InngestClient", InngestClientService>;
|
|
124
155
|
/**
|
|
125
156
|
* InngestClient service for communicating with Inngest.
|
|
126
157
|
*
|
|
@@ -148,7 +179,7 @@ declare const layer: (config: ClientConfig) => Layer.Layer<InngestClient, never,
|
|
|
148
179
|
* @since 0.1.0
|
|
149
180
|
* @category layers
|
|
150
181
|
*/
|
|
151
|
-
declare const layerConfig: (config: Config.
|
|
182
|
+
declare const layerConfig: (config: Config.Wrap<ClientConfig>) => Layer.Layer<InngestClient, Config.ConfigError, HttpClient.HttpClient>;
|
|
152
183
|
/**
|
|
153
184
|
* Create an InngestClient layer from environment variables.
|
|
154
185
|
*
|
|
@@ -162,6 +193,6 @@ declare const layerConfig: (config: Config.Config.Wrap<ClientConfig>) => Layer.L
|
|
|
162
193
|
* @since 0.1.0
|
|
163
194
|
* @category layers
|
|
164
195
|
*/
|
|
165
|
-
declare const layerFromEnv: Layer.Layer<InngestClient,
|
|
196
|
+
declare const layerFromEnv: Layer.Layer<InngestClient, Config.ConfigError, HttpClient.HttpClient>;
|
|
166
197
|
//#endregion
|
|
167
|
-
export { Client_d_exports, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
|
198
|
+
export { CheckpointApiError, type CheckpointingOption, Client_d_exports, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
package/dist/Client.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import { __exportAll } from "./_virtual/
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { CheckpointApiError } from "./internal/checkpoint.js";
|
|
3
|
+
import { GeneratorOpcode, Headers } from "./internal/protocol.js";
|
|
4
|
+
import { hashSigningKey } from "./internal/signature.js";
|
|
5
|
+
import * as Clock from "effect/Clock";
|
|
5
6
|
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as Layer from "effect/Layer";
|
|
7
7
|
import * as Option from "effect/Option";
|
|
8
|
+
import * as Ref from "effect/Ref";
|
|
8
9
|
import * as Schema from "effect/Schema";
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
10
|
+
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
11
|
+
import * as Context from "effect/Context";
|
|
12
|
+
import * as Layer from "effect/Layer";
|
|
13
|
+
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
|
14
|
+
import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
|
|
11
15
|
import * as Config from "effect/Config";
|
|
12
16
|
import * as Predicate from "effect/Predicate";
|
|
13
|
-
|
|
17
|
+
import * as Schedule from "effect/Schedule";
|
|
14
18
|
//#region src/Client.ts
|
|
15
19
|
/**
|
|
16
20
|
* @since 0.1.0
|
|
17
21
|
*/
|
|
18
22
|
var Client_exports = /* @__PURE__ */ __exportAll({
|
|
23
|
+
CheckpointApiError: () => CheckpointApiError,
|
|
19
24
|
EventPayload: () => EventPayload,
|
|
20
25
|
InngestClient: () => InngestClient,
|
|
21
26
|
layer: () => layer,
|
|
@@ -40,10 +45,10 @@ const EventPayload = Schema.Struct({
|
|
|
40
45
|
v: Schema.optional(Schema.String)
|
|
41
46
|
});
|
|
42
47
|
const SendEventResponse = Schema.Struct({
|
|
43
|
-
ids: Schema.
|
|
48
|
+
ids: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
|
|
44
49
|
status: Schema.optional(Schema.Number)
|
|
45
50
|
});
|
|
46
|
-
var SendEventError = class extends Schema.
|
|
51
|
+
var SendEventError = class extends Schema.TaggedErrorClass()("SendEventError", {
|
|
47
52
|
message: Schema.String,
|
|
48
53
|
events: Schema.Array(Schema.String)
|
|
49
54
|
}) {};
|
|
@@ -53,23 +58,31 @@ var SendEventError = class extends Schema.TaggedError()("SendEventError", {
|
|
|
53
58
|
* @since 0.1.0
|
|
54
59
|
* @category context
|
|
55
60
|
*/
|
|
56
|
-
var InngestClient = class extends Context.
|
|
61
|
+
var InngestClient = class extends Context.Service()("effect-inngest/InngestClient") {};
|
|
57
62
|
const resolveMode = (config) => config.mode ?? "dev";
|
|
58
63
|
const resolveEventBaseUrl = (config, mode) => config.eventBaseUrl ?? (mode === "dev" ? DEFAULT_DEV_SERVER_URL : DEFAULT_EVENT_BASE_URL);
|
|
59
64
|
const resolveApiBaseUrl = (config, mode) => config.apiBaseUrl ?? (mode === "dev" ? DEFAULT_DEV_SERVER_URL : DEFAULT_API_BASE_URL);
|
|
60
|
-
const
|
|
65
|
+
const isRetriable = (error) => error.status === void 0 || error.status >= 500;
|
|
66
|
+
const defaultCheckpointRetrySchedule = Schedule.exponential("100 millis", 2).pipe(Schedule.jittered, Schedule.both(Schedule.recurs(5)), Schedule.while((m) => isRetriable(m.input)));
|
|
67
|
+
const makeClient = (config, httpClient, retrySchedule = defaultCheckpointRetrySchedule) => Effect.gen(function* () {
|
|
61
68
|
const mode = resolveMode(config);
|
|
62
69
|
const eventBaseUrl = resolveEventBaseUrl(config, mode);
|
|
63
70
|
const apiBaseUrl = resolveApiBaseUrl(config, mode);
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
/**
|
|
72
|
+
* One-way switch: once the fallback signing key succeeds for any
|
|
73
|
+
* checkpoint API call, all subsequent calls use it first. Per spec
|
|
74
|
+
* §10.3.4.
|
|
75
|
+
*/
|
|
76
|
+
const useFallbackKey = yield* Ref.make(false);
|
|
77
|
+
const sendEvent = Effect.fn("InngestClient.sendEvent")(function* (events) {
|
|
78
|
+
if (!config.eventKey && mode === "cloud") return yield* Effect.fail(new SendEventError({
|
|
66
79
|
message: "Event key is required to send events in cloud mode",
|
|
67
80
|
events: events.map((e) => e.name)
|
|
68
|
-
});
|
|
81
|
+
}));
|
|
69
82
|
const key = config.eventKey ?? "local";
|
|
70
83
|
const url = new URL(`e/${key}`, eventBaseUrl).toString();
|
|
71
84
|
const eventNames = events.map((e) => e.name);
|
|
72
|
-
const now =
|
|
85
|
+
const now = yield* Clock.currentTimeMillis;
|
|
73
86
|
const payloads = events.map((e) => ({
|
|
74
87
|
name: e.name,
|
|
75
88
|
data: e.data ?? {},
|
|
@@ -82,23 +95,62 @@ const makeClient = (config, httpClient) => {
|
|
|
82
95
|
[Headers.SDK]: `effect-ts:v${SDK_VERSION}`,
|
|
83
96
|
...config.env ? { [Headers.Env]: config.env } : {}
|
|
84
97
|
}));
|
|
85
|
-
return HttpClientRequest.schemaBodyJson(Schema.Array(EventPayload))(request, payloads).pipe(Effect.flatMap(httpClient.execute), Effect.flatMap(HttpClientResponse.schemaBodyJson(SendEventResponse)), Effect.map((response) => ({
|
|
98
|
+
return yield* HttpClientRequest.schemaBodyJson(Schema.Array(EventPayload))(request, payloads).pipe(Effect.flatMap(httpClient.execute), Effect.flatMap(HttpClientResponse.schemaBodyJson(SendEventResponse)), Effect.map((response) => ({
|
|
86
99
|
ids: response.ids,
|
|
87
100
|
status: response.status
|
|
88
|
-
})), Effect.scoped, Effect.
|
|
101
|
+
})), Effect.scoped, Effect.catch((error) => Effect.fail(new SendEventError({
|
|
89
102
|
message: `Failed to send events: ${Predicate.hasProperty(error, "message") ? error.message : "Unknown error"}`,
|
|
90
103
|
events: eventNames
|
|
91
|
-
})));
|
|
104
|
+
}))));
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* Issue a checkpoint POST with the given signing key. Returns a tagged
|
|
108
|
+
* error on non-2xx so the caller can decide whether to retry, swap keys,
|
|
109
|
+
* or fall back.
|
|
110
|
+
*/
|
|
111
|
+
const checkpointRequest = (runId, body, signingKey) => {
|
|
112
|
+
const url = new URL(`v1/checkpoint/${runId}/async`, apiBaseUrl).toString();
|
|
113
|
+
const request = HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders({
|
|
114
|
+
"Content-Type": "application/json",
|
|
115
|
+
[Headers.SDK]: `effect-inngest:v${SDK_VERSION}`,
|
|
116
|
+
[Headers.RequestVersion]: "2",
|
|
117
|
+
...config.env ? { [Headers.Env]: config.env } : {}
|
|
118
|
+
}), HttpClientRequest.bearerToken(hashSigningKey(signingKey)), HttpClientRequest.bodyText(body, "application/json"));
|
|
119
|
+
return httpClient.execute(request).pipe(Effect.scoped, Effect.catch((error) => Effect.fail(new CheckpointApiError({ message: `Network error issuing checkpoint: ${Predicate.hasProperty(error, "message") ? error.message : String(error)}` }))), Effect.flatMap((response) => {
|
|
120
|
+
if (response.status >= 200 && response.status < 300) return Effect.void;
|
|
121
|
+
return Effect.fail(new CheckpointApiError({
|
|
122
|
+
message: `Checkpoint API returned ${response.status}`,
|
|
123
|
+
status: response.status
|
|
124
|
+
}));
|
|
125
|
+
}));
|
|
92
126
|
};
|
|
127
|
+
const checkpointAsync = Effect.fn("InngestClient.checkpointAsync")(function* (args) {
|
|
128
|
+
const signingKey = config.signingKey;
|
|
129
|
+
if (!signingKey) return yield* Effect.fail(new CheckpointApiError({ message: "No signing key configured for checkpoint API" }));
|
|
130
|
+
const now = yield* Clock.currentTimeMillis;
|
|
131
|
+
const body = JSON.stringify({
|
|
132
|
+
run_id: args.runId,
|
|
133
|
+
fn_id: args.fnId,
|
|
134
|
+
qi_id: args.qiId,
|
|
135
|
+
steps: Schema.encodeSync(Schema.Array(GeneratorOpcode))(args.steps),
|
|
136
|
+
ts: now
|
|
137
|
+
});
|
|
138
|
+
const fallbackKey = config.signingKeyFallback;
|
|
139
|
+
return yield* Ref.get(useFallbackKey).pipe(Effect.flatMap((usingFallback) => {
|
|
140
|
+
const primaryKey = usingFallback && fallbackKey ? fallbackKey : signingKey;
|
|
141
|
+
return checkpointRequest(args.runId, body, primaryKey).pipe(Effect.catch((error) => error.status === 401 && !usingFallback && fallbackKey ? checkpointRequest(args.runId, body, fallbackKey).pipe(Effect.andThen(Ref.set(useFallbackKey, true))) : Effect.fail(error)));
|
|
142
|
+
})).pipe(Effect.retry(retrySchedule));
|
|
143
|
+
});
|
|
93
144
|
return {
|
|
94
145
|
[TypeId]: TypeId,
|
|
95
146
|
config,
|
|
96
147
|
mode,
|
|
97
148
|
eventBaseUrl,
|
|
98
149
|
apiBaseUrl,
|
|
99
|
-
sendEvent
|
|
150
|
+
sendEvent,
|
|
151
|
+
checkpointAsync
|
|
100
152
|
};
|
|
101
|
-
};
|
|
153
|
+
});
|
|
102
154
|
/**
|
|
103
155
|
* Create an InngestClient layer from a config.
|
|
104
156
|
*
|
|
@@ -112,14 +164,22 @@ const makeClient = (config, httpClient) => {
|
|
|
112
164
|
* })
|
|
113
165
|
* ```
|
|
114
166
|
*/
|
|
115
|
-
const layer = (config) => Layer.effect(InngestClient, Effect.
|
|
167
|
+
const layer = (config) => Layer.effect(InngestClient, Effect.gen(function* () {
|
|
168
|
+
return yield* makeClient(config, yield* HttpClient.HttpClient);
|
|
169
|
+
}));
|
|
170
|
+
const TEST_FACTORY_KEY = Symbol.for("effect-inngest/internal/test-retry-schedule-factory");
|
|
171
|
+
InngestClient[TEST_FACTORY_KEY] = (config, retrySchedule) => Layer.effect(InngestClient, Effect.gen(function* () {
|
|
172
|
+
return yield* makeClient(config, yield* HttpClient.HttpClient, retrySchedule);
|
|
173
|
+
}));
|
|
116
174
|
/**
|
|
117
175
|
* Create an InngestClient layer from Effect Config.
|
|
118
176
|
*
|
|
119
177
|
* @since 0.1.0
|
|
120
178
|
* @category layers
|
|
121
179
|
*/
|
|
122
|
-
const layerConfig = (config) => Layer.effect(InngestClient, Effect.
|
|
180
|
+
const layerConfig = (config) => Layer.effect(InngestClient, Effect.gen(function* () {
|
|
181
|
+
return yield* makeClient(yield* Config.unwrap(config), yield* HttpClient.HttpClient);
|
|
182
|
+
}));
|
|
123
183
|
/**
|
|
124
184
|
* Create an InngestClient layer from environment variables.
|
|
125
185
|
*
|
|
@@ -139,6 +199,5 @@ const layerFromEnv = layerConfig(Config.all({
|
|
|
139
199
|
signingKey: Config.string("INNGEST_SIGNING_KEY").pipe(Config.option, Config.map(Option.getOrUndefined)),
|
|
140
200
|
signingKeyFallback: Config.string("INNGEST_SIGNING_KEY_FALLBACK").pipe(Config.option, Config.map(Option.getOrUndefined))
|
|
141
201
|
}));
|
|
142
|
-
|
|
143
202
|
//#endregion
|
|
144
|
-
export { Client_exports, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
|
203
|
+
export { CheckpointApiError, Client_exports, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
package/dist/Events.d.ts
CHANGED
|
@@ -4,65 +4,46 @@ import * as Schema from "effect/Schema";
|
|
|
4
4
|
declare namespace Events_d_exports {
|
|
5
5
|
export { FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
|
|
6
6
|
}
|
|
7
|
-
declare const JsonError_base: Schema.Class<JsonError, {
|
|
8
|
-
name:
|
|
9
|
-
message:
|
|
10
|
-
stack: Schema.optional<
|
|
11
|
-
cause: Schema.optional<
|
|
12
|
-
}
|
|
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
|
-
}, {}, {}>;
|
|
7
|
+
declare const JsonError_base: Schema.Class<JsonError, Schema.Struct<{
|
|
8
|
+
readonly name: Schema.String;
|
|
9
|
+
readonly message: Schema.String;
|
|
10
|
+
readonly stack: Schema.optional<Schema.String>;
|
|
11
|
+
readonly cause: Schema.optional<Schema.Unknown>;
|
|
12
|
+
}>, {}>;
|
|
26
13
|
/**
|
|
27
14
|
* Error structure used in internal Inngest events.
|
|
28
15
|
* @since 0.1.0
|
|
29
16
|
*/
|
|
30
17
|
declare class JsonError extends JsonError_base {}
|
|
31
|
-
declare const FunctionFailed_base: Schema.
|
|
32
|
-
readonly
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
event: Schema.Record$<typeof Schema.String, typeof Schema.Unknown>;
|
|
38
|
-
}>;
|
|
18
|
+
declare const FunctionFailed_base: Schema.Class<FunctionFailed, Schema.TaggedStruct<"inngest/function.failed", {
|
|
19
|
+
readonly function_id: Schema.String;
|
|
20
|
+
readonly run_id: Schema.String;
|
|
21
|
+
readonly error: typeof JsonError;
|
|
22
|
+
readonly event: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
23
|
+
}>, {}>;
|
|
39
24
|
/**
|
|
40
25
|
* Sent when a function fails after exhausting all retries.
|
|
41
26
|
* Trigger on this to handle failures (e.g., alerting, cleanup).
|
|
42
27
|
* @since 0.1.0
|
|
43
28
|
*/
|
|
44
29
|
declare class FunctionFailed extends FunctionFailed_base {}
|
|
45
|
-
declare const FunctionFinishedError_base: Schema.
|
|
46
|
-
readonly
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
error: typeof JsonError;
|
|
52
|
-
}>;
|
|
30
|
+
declare const FunctionFinishedError_base: Schema.Class<FunctionFinishedError, Schema.TaggedStruct<"inngest/function.finished", {
|
|
31
|
+
readonly function_id: Schema.String;
|
|
32
|
+
readonly run_id: Schema.String;
|
|
33
|
+
readonly correlation_id: Schema.optional<Schema.String>;
|
|
34
|
+
readonly error: typeof JsonError;
|
|
35
|
+
}>, {}>;
|
|
53
36
|
/**
|
|
54
37
|
* Sent when a function finishes with an error.
|
|
55
38
|
* @since 0.1.0
|
|
56
39
|
*/
|
|
57
40
|
declare class FunctionFinishedError extends FunctionFinishedError_base {}
|
|
58
|
-
declare const FunctionFinishedSuccess_base: Schema.
|
|
59
|
-
readonly
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
result: typeof Schema.Unknown;
|
|
65
|
-
}>;
|
|
41
|
+
declare const FunctionFinishedSuccess_base: Schema.Class<FunctionFinishedSuccess, Schema.TaggedStruct<"inngest/function.finished", {
|
|
42
|
+
readonly function_id: Schema.String;
|
|
43
|
+
readonly run_id: Schema.String;
|
|
44
|
+
readonly correlation_id: Schema.optional<Schema.String>;
|
|
45
|
+
readonly result: Schema.Unknown;
|
|
46
|
+
}>, {}>;
|
|
66
47
|
/**
|
|
67
48
|
* Sent when a function finishes successfully.
|
|
68
49
|
* @since 0.1.0
|
|
@@ -72,35 +53,29 @@ declare class FunctionFinishedSuccess extends FunctionFinishedSuccess_base {}
|
|
|
72
53
|
* Union of both FunctionFinished variants.
|
|
73
54
|
* @since 0.1.0
|
|
74
55
|
*/
|
|
75
|
-
declare const FunctionFinished: Schema.Union<[typeof FunctionFinishedError, typeof FunctionFinishedSuccess]>;
|
|
56
|
+
declare const FunctionFinished: Schema.Union<readonly [typeof FunctionFinishedError, typeof FunctionFinishedSuccess]>;
|
|
76
57
|
type FunctionFinished = typeof FunctionFinished.Type;
|
|
77
|
-
declare const FunctionCancelled_base: Schema.
|
|
78
|
-
readonly
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
correlation_id: Schema.optional<typeof Schema.String>;
|
|
83
|
-
}>;
|
|
58
|
+
declare const FunctionCancelled_base: Schema.Class<FunctionCancelled, Schema.TaggedStruct<"inngest/function.cancelled", {
|
|
59
|
+
readonly function_id: Schema.String;
|
|
60
|
+
readonly run_id: Schema.String;
|
|
61
|
+
readonly correlation_id: Schema.optional<Schema.String>;
|
|
62
|
+
}>, {}>;
|
|
84
63
|
/**
|
|
85
64
|
* Sent when a function is cancelled.
|
|
86
65
|
* @since 0.1.0
|
|
87
66
|
*/
|
|
88
67
|
declare class FunctionCancelled extends FunctionCancelled_base {}
|
|
89
|
-
declare const FunctionInvoked_base: Schema.
|
|
90
|
-
readonly
|
|
91
|
-
}
|
|
92
|
-
data: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
93
|
-
}>;
|
|
68
|
+
declare const FunctionInvoked_base: Schema.Class<FunctionInvoked, Schema.TaggedStruct<"inngest/function.invoked", {
|
|
69
|
+
readonly data: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
70
|
+
}>, {}>;
|
|
94
71
|
/**
|
|
95
72
|
* Sent when a function is invoked via step.invoke().
|
|
96
73
|
* @since 0.1.0
|
|
97
74
|
*/
|
|
98
75
|
declare class FunctionInvoked extends FunctionInvoked_base {}
|
|
99
|
-
declare const ScheduledTimer_base: Schema.
|
|
100
|
-
readonly
|
|
101
|
-
}
|
|
102
|
-
cron: typeof Schema.String;
|
|
103
|
-
}>;
|
|
76
|
+
declare const ScheduledTimer_base: Schema.Class<ScheduledTimer, Schema.TaggedStruct<"inngest/scheduled.timer", {
|
|
77
|
+
readonly cron: Schema.String;
|
|
78
|
+
}>, {}>;
|
|
104
79
|
/**
|
|
105
80
|
* Sent when a cron trigger fires.
|
|
106
81
|
* @since 0.1.0
|
package/dist/Events.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { __exportAll } from "./_virtual/
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
|
-
|
|
4
3
|
//#region src/Events.ts
|
|
5
4
|
/**
|
|
6
5
|
* Internal Inngest events that the platform sends automatically.
|
|
@@ -36,10 +35,7 @@ var FunctionFailed = class extends Schema.TaggedClass()("inngest/function.failed
|
|
|
36
35
|
function_id: Schema.String,
|
|
37
36
|
run_id: Schema.String,
|
|
38
37
|
error: JsonError,
|
|
39
|
-
event: Schema.Record(
|
|
40
|
-
key: Schema.String,
|
|
41
|
-
value: Schema.Unknown
|
|
42
|
-
})
|
|
38
|
+
event: Schema.Record(Schema.String, Schema.Unknown)
|
|
43
39
|
}) {};
|
|
44
40
|
/**
|
|
45
41
|
* Sent when a function finishes with an error.
|
|
@@ -65,7 +61,7 @@ var FunctionFinishedSuccess = class extends Schema.TaggedClass()("inngest/functi
|
|
|
65
61
|
* Union of both FunctionFinished variants.
|
|
66
62
|
* @since 0.1.0
|
|
67
63
|
*/
|
|
68
|
-
const FunctionFinished = Schema.Union(FunctionFinishedError, FunctionFinishedSuccess);
|
|
64
|
+
const FunctionFinished = Schema.Union([FunctionFinishedError, FunctionFinishedSuccess]);
|
|
69
65
|
/**
|
|
70
66
|
* Sent when a function is cancelled.
|
|
71
67
|
* @since 0.1.0
|
|
@@ -79,15 +75,11 @@ var FunctionCancelled = class extends Schema.TaggedClass()("inngest/function.can
|
|
|
79
75
|
* Sent when a function is invoked via step.invoke().
|
|
80
76
|
* @since 0.1.0
|
|
81
77
|
*/
|
|
82
|
-
var FunctionInvoked = class extends Schema.TaggedClass()("inngest/function.invoked", { data: Schema.optional(Schema.Record({
|
|
83
|
-
key: Schema.String,
|
|
84
|
-
value: Schema.Unknown
|
|
85
|
-
})) }) {};
|
|
78
|
+
var FunctionInvoked = class extends Schema.TaggedClass()("inngest/function.invoked", { data: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)) }) {};
|
|
86
79
|
/**
|
|
87
80
|
* Sent when a cron trigger fires.
|
|
88
81
|
* @since 0.1.0
|
|
89
82
|
*/
|
|
90
83
|
var ScheduledTimer = class extends Schema.TaggedClass()("inngest/scheduled.timer", { cron: Schema.String }) {};
|
|
91
|
-
|
|
92
84
|
//#endregion
|
|
93
|
-
export { Events_exports, FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
|
|
85
|
+
export { Events_exports, FunctionCancelled, FunctionFailed, FunctionFinished, FunctionFinishedError, FunctionFinishedSuccess, FunctionInvoked, JsonError, ScheduledTimer };
|
package/dist/Function.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { CheckpointingOption } from "./internal/checkpoint.js";
|
|
1
2
|
import { Duration, Schema } from "effect";
|
|
3
|
+
import { Pipeable } from "effect/Pipeable";
|
|
2
4
|
|
|
3
5
|
//#region src/Function.d.ts
|
|
4
6
|
declare namespace Function_d_exports {
|
|
5
|
-
export { CronTrigger, EventTrigger, FunctionOptions, InngestFunction, Trigger, TriggerInput, TypeId, make };
|
|
7
|
+
export { CheckpointingOption, CronTrigger, EventTrigger, FunctionOptions, InngestFunction, Trigger, TriggerInput, TypeId, make };
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* @since 0.1.0
|
|
@@ -14,8 +16,8 @@ declare const TypeId: unique symbol;
|
|
|
14
16
|
* @category type ids
|
|
15
17
|
*/
|
|
16
18
|
type TypeId = typeof TypeId;
|
|
17
|
-
type EventSchema = Schema.
|
|
18
|
-
readonly
|
|
19
|
+
type EventSchema = Schema.Top & {
|
|
20
|
+
readonly identifier: string;
|
|
19
21
|
};
|
|
20
22
|
/**
|
|
21
23
|
* An event-based trigger configuration.
|
|
@@ -88,7 +90,7 @@ interface RateLimitOption {
|
|
|
88
90
|
/**
|
|
89
91
|
* The period of time to allow the function to run `limit` times.
|
|
90
92
|
*/
|
|
91
|
-
readonly period: Duration.
|
|
93
|
+
readonly period: Duration.Input;
|
|
92
94
|
}
|
|
93
95
|
interface ThrottleOption {
|
|
94
96
|
/**
|
|
@@ -106,7 +108,7 @@ interface ThrottleOption {
|
|
|
106
108
|
* The period of time for the rate limit. Run starts are evenly spaced through
|
|
107
109
|
* the given period. The minimum granularity is 1 second.
|
|
108
110
|
*/
|
|
109
|
-
readonly period: Duration.
|
|
111
|
+
readonly period: Duration.Input;
|
|
110
112
|
/**
|
|
111
113
|
* The number of runs allowed to start in the given window in a single burst.
|
|
112
114
|
* A burst > 1 bypasses smoothing for the burst and allows many runs to start
|
|
@@ -122,13 +124,13 @@ interface DebounceOption {
|
|
|
122
124
|
/**
|
|
123
125
|
* The period of time to delay after receiving the last trigger to run the function.
|
|
124
126
|
*/
|
|
125
|
-
readonly period: Duration.
|
|
127
|
+
readonly period: Duration.Input;
|
|
126
128
|
/**
|
|
127
129
|
* The maximum time that a debounce can be extended before running.
|
|
128
130
|
* If events are continually received within the given period, a function
|
|
129
131
|
* will always run after the given timeout period.
|
|
130
132
|
*/
|
|
131
|
-
readonly timeout?: Duration.
|
|
133
|
+
readonly timeout?: Duration.Input;
|
|
132
134
|
}
|
|
133
135
|
interface BatchEventsOption {
|
|
134
136
|
/**
|
|
@@ -140,7 +142,7 @@ interface BatchEventsOption {
|
|
|
140
142
|
* If timeout is reached, the function will be invoked with a batch
|
|
141
143
|
* even if it's not filled up to `maxSize`.
|
|
142
144
|
*/
|
|
143
|
-
readonly timeout: Duration.
|
|
145
|
+
readonly timeout: Duration.Input;
|
|
144
146
|
/**
|
|
145
147
|
* An optional key to use for batching.
|
|
146
148
|
*/
|
|
@@ -169,13 +171,13 @@ interface TimeoutsOption {
|
|
|
169
171
|
* This is, essentially, the amount of time that a function sits in the
|
|
170
172
|
* queue before starting.
|
|
171
173
|
*/
|
|
172
|
-
readonly start?: Duration.
|
|
174
|
+
readonly start?: Duration.Input;
|
|
173
175
|
/**
|
|
174
176
|
* Finish represents the time between a function starting and the function
|
|
175
177
|
* finishing. If a function takes longer than this time to finish, the
|
|
176
178
|
* function is marked as cancelled.
|
|
177
179
|
*/
|
|
178
|
-
readonly finish?: Duration.
|
|
180
|
+
readonly finish?: Duration.Input;
|
|
179
181
|
}
|
|
180
182
|
interface SingletonOption {
|
|
181
183
|
/**
|
|
@@ -208,7 +210,7 @@ interface CancellationOption {
|
|
|
208
210
|
* specified, cancellation triggers are valid for up to a year or until the
|
|
209
211
|
* function ends.
|
|
210
212
|
*/
|
|
211
|
-
readonly timeout?: Duration.
|
|
213
|
+
readonly timeout?: Duration.Input;
|
|
212
214
|
}
|
|
213
215
|
type Retries = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20;
|
|
214
216
|
/**
|
|
@@ -278,6 +280,19 @@ interface FunctionOptions {
|
|
|
278
280
|
* Batch events configuration.
|
|
279
281
|
*/
|
|
280
282
|
readonly batchEvents?: BatchEventsOption;
|
|
283
|
+
/**
|
|
284
|
+
* Whether to use checkpointing for executions of this function. Overrides
|
|
285
|
+
* the client-level `checkpointing` setting.
|
|
286
|
+
*
|
|
287
|
+
* - `false` disables checkpointing for this function.
|
|
288
|
+
* - `true` enables checkpointing with safe defaults
|
|
289
|
+
* (`bufferedSteps: 1`, `maxInterval: 0`, `maxRuntime: 10s`).
|
|
290
|
+
* - An object lets you tune `bufferedSteps`, `maxInterval`, `maxRuntime`.
|
|
291
|
+
*
|
|
292
|
+
* Defaults to inheriting from the client-level setting (which itself
|
|
293
|
+
* defaults to enabled with safe defaults).
|
|
294
|
+
*/
|
|
295
|
+
readonly checkpointing?: CheckpointingOption;
|
|
281
296
|
}
|
|
282
297
|
interface RegistrationConfig {
|
|
283
298
|
readonly appId: string;
|
|
@@ -347,6 +362,11 @@ interface FunctionRegistration {
|
|
|
347
362
|
readonly key?: string;
|
|
348
363
|
};
|
|
349
364
|
readonly idempotency?: string;
|
|
365
|
+
readonly checkpoint?: {
|
|
366
|
+
readonly batch_steps: number;
|
|
367
|
+
readonly batch_interval: string;
|
|
368
|
+
readonly max_runtime: string;
|
|
369
|
+
};
|
|
350
370
|
}
|
|
351
371
|
/**
|
|
352
372
|
* An Inngest function definition.
|
|
@@ -354,7 +374,7 @@ interface FunctionRegistration {
|
|
|
354
374
|
* @since 0.1.0
|
|
355
375
|
* @category models
|
|
356
376
|
*/
|
|
357
|
-
interface InngestFunction<Tag extends string, Triggers extends Trigger, Success extends Schema.
|
|
377
|
+
interface InngestFunction<Tag extends string, Triggers extends Trigger, Success extends Schema.Top, Options extends FunctionOptions = FunctionOptions> extends Pipeable {
|
|
358
378
|
readonly [TypeId]: TypeId;
|
|
359
379
|
readonly _tag: Tag;
|
|
360
380
|
readonly key: string;
|
|
@@ -368,7 +388,7 @@ interface InngestFunction<Tag extends string, Triggers extends Trigger, Success
|
|
|
368
388
|
* @category models
|
|
369
389
|
*/
|
|
370
390
|
declare namespace InngestFunction {
|
|
371
|
-
type Any = InngestFunction<string, Trigger, Schema.
|
|
391
|
+
type Any = InngestFunction<string, Trigger, Schema.Top, FunctionOptions>;
|
|
372
392
|
type Tag<F> = F extends InngestFunction<infer T, any, any, any> ? T : never;
|
|
373
393
|
type Triggers<F> = F extends InngestFunction<any, infer T, any, any> ? T : never;
|
|
374
394
|
type Events<F> = F extends InngestFunction<any, infer T, any, any> ? (T extends EventTrigger<infer E> ? E : never) : never;
|
|
@@ -410,9 +430,9 @@ type NormalizeTriggers<T extends TriggerInput> = T extends ReadonlyArray<Trigger
|
|
|
410
430
|
* })
|
|
411
431
|
* ```
|
|
412
432
|
*/
|
|
413
|
-
declare function make<const Tag extends string, T extends TriggerInput, S extends Schema.
|
|
433
|
+
declare function make<const Tag extends string, T extends TriggerInput, S extends Schema.Top, const O extends FunctionOptions = {}>(tag: Tag, options: {
|
|
414
434
|
readonly trigger: T;
|
|
415
435
|
readonly success: S;
|
|
416
436
|
} & O): InngestFunction<Tag, NormalizeTriggers<T>, S, O>;
|
|
417
437
|
//#endregion
|
|
418
|
-
export { CronTrigger, EventTrigger, FunctionOptions, Function_d_exports, InngestFunction, Trigger, TriggerInput, TypeId, make };
|
|
438
|
+
export { type CheckpointingOption, CronTrigger, EventTrigger, FunctionOptions, Function_d_exports, InngestFunction, Trigger, TriggerInput, TypeId, make };
|