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.
Files changed (47) hide show
  1. package/dist/Client.d.ts +55 -24
  2. package/dist/Client.js +84 -25
  3. package/dist/Events.d.ts +36 -61
  4. package/dist/Events.js +5 -13
  5. package/dist/Function.d.ts +35 -15
  6. package/dist/Function.js +14 -8
  7. package/dist/Group.d.ts +5 -4
  8. package/dist/Group.js +26 -24
  9. package/dist/HttpApi.d.ts +49 -54
  10. package/dist/HttpApi.js +32 -17
  11. package/dist/_virtual/_rolldown/runtime.js +13 -0
  12. package/dist/index.js +1 -2
  13. package/dist/internal/checkpoint.d.ts +32 -0
  14. package/dist/internal/checkpoint.js +112 -0
  15. package/dist/internal/constants.js +1 -2
  16. package/dist/internal/driver.d.ts +1 -5
  17. package/dist/internal/driver.js +164 -52
  18. package/dist/internal/errors.d.ts +20 -27
  19. package/dist/internal/errors.js +29 -15
  20. package/dist/internal/handler.d.ts +4 -13
  21. package/dist/internal/handler.js +70 -43
  22. package/dist/internal/helpers.js +12 -9
  23. package/dist/internal/interrupts.d.ts +1 -2
  24. package/dist/internal/interrupts.js +1 -3
  25. package/dist/internal/memo.js +22 -20
  26. package/dist/internal/protocol.d.ts +28 -1
  27. package/dist/internal/protocol.js +84 -52
  28. package/dist/internal/signature.d.ts +5 -9
  29. package/dist/internal/signature.js +34 -18
  30. package/dist/internal/step.d.ts +5 -11
  31. package/dist/internal/step.js +48 -32
  32. package/package.json +26 -21
  33. package/src/Client.ts +244 -68
  34. package/src/Events.ts +3 -3
  35. package/src/Function.ts +52 -15
  36. package/src/Group.ts +39 -26
  37. package/src/HttpApi.ts +38 -27
  38. package/src/internal/checkpoint.ts +218 -0
  39. package/src/internal/driver.ts +241 -93
  40. package/src/internal/errors.ts +21 -14
  41. package/src/internal/handler.ts +185 -142
  42. package/src/internal/helpers.ts +9 -9
  43. package/src/internal/memo.ts +48 -33
  44. package/src/internal/protocol.ts +89 -45
  45. package/src/internal/signature.ts +76 -58
  46. package/src/internal/step.ts +83 -32
  47. package/dist/_virtual/rolldown_runtime.js +0 -18
package/dist/Client.d.ts CHANGED
@@ -1,14 +1,16 @@
1
- import * as HttpClient from "@effect/platform/HttpClient";
2
- import * as Context from "effect/Context";
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 ConfigError from "effect/ConfigError";
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: typeof Schema.String;
95
- data: typeof Schema.Unknown;
96
- ts: Schema.optional<typeof Schema.Number>;
97
- id: Schema.optional<typeof Schema.String>;
98
- v: Schema.optional<typeof Schema.String>;
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.optionalWith<Schema.Array$<typeof Schema.String>, {
102
- default: () => never[];
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.TaggedErrorClass<SendEventError, "SendEventError", {
109
- readonly _tag: Schema.tag<"SendEventError">;
110
- } & {
111
- message: typeof Schema.String;
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.TagClass<InngestClient, "effect-inngest/InngestClient", InngestClientService>;
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.Config.Wrap<ClientConfig>) => Layer.Layer<InngestClient, ConfigError.ConfigError, HttpClient.HttpClient>;
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, ConfigError.ConfigError, HttpClient.HttpClient>;
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/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";
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 HttpClientRequest from "@effect/platform/HttpClientRequest";
10
- import * as HttpClientResponse from "@effect/platform/HttpClientResponse";
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.optionalWith(Schema.Array(Schema.String), { default: () => [] }),
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.TaggedError()("SendEventError", {
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.Tag("effect-inngest/InngestClient")() {};
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 makeClient = (config, httpClient) => {
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
- const sendEvent = (events) => {
65
- if (!config.eventKey && mode === "cloud") return new SendEventError({
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 = Date.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.catchAll((error) => new SendEventError({
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.map(HttpClient.HttpClient, (httpClient) => makeClient(config, httpClient)));
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.flatMap(Config.unwrap(config), (resolvedConfig) => Effect.map(HttpClient.HttpClient, (httpClient) => makeClient(resolvedConfig, httpClient))));
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: 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
- }, {}, {}>;
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.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
- }>;
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.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
- }>;
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.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
- }>;
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.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
- }>;
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.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
- }>;
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.TaggedClass<ScheduledTimer, "inngest/scheduled.timer", {
100
- readonly _tag: Schema.tag<"inngest/scheduled.timer">;
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/rolldown_runtime.js";
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 };
@@ -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.Schema.Any & {
18
- readonly _tag: string;
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.DurationInput;
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.DurationInput;
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.DurationInput;
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.DurationInput;
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.DurationInput;
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.DurationInput;
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.DurationInput;
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.DurationInput;
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.Schema.Any, Options extends FunctionOptions = FunctionOptions> {
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.Schema.Any, FunctionOptions>;
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.Schema.Any, const O extends FunctionOptions = {}>(tag: Tag, options: {
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 };