effect-inngest 0.2.0-beta.0 → 0.3.0-beta.1
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/README.md +90 -68
- package/dist/Client.d.ts +29 -12
- package/dist/Client.js +37 -32
- package/dist/Event.d.ts +43 -0
- package/dist/Event.js +47 -0
- package/dist/Events.d.ts +32 -35
- package/dist/Events.js +15 -12
- package/dist/Function.d.ts +20 -13
- package/dist/Function.js +23 -19
- package/dist/Group.d.ts +18 -8
- package/dist/Group.js +24 -68
- package/dist/HttpApi.d.ts +7 -7
- package/dist/HttpApi.js +8 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/internal/checkpoint/Config.d.ts +10 -0
- package/dist/internal/checkpoint/Config.js +29 -0
- package/dist/internal/checkpoint/Error.d.ts +11 -0
- package/dist/internal/checkpoint/Error.js +8 -0
- package/dist/internal/checkpoint/State.d.ts +1 -0
- package/dist/internal/checkpoint/State.js +54 -0
- package/dist/internal/checkpoint.d.ts +2 -32
- package/dist/internal/codec/EventPayload.d.ts +6 -0
- package/dist/internal/codec/EventPayload.js +60 -0
- package/dist/internal/codec/StepResult.js +55 -0
- package/dist/internal/domain/ExecutionInput.d.ts +40 -0
- package/dist/internal/domain/ExecutionInput.js +57 -0
- package/dist/internal/domain/ExecutionSuspension.d.ts +34 -0
- package/dist/internal/domain/ExecutionSuspension.js +64 -0
- package/dist/internal/domain/FunctionDefinition.js +13 -0
- package/dist/internal/domain/Memo.d.ts +22 -0
- package/dist/internal/domain/Memo.js +18 -0
- package/dist/internal/domain/StepCommand.d.ts +79 -0
- package/dist/internal/domain/StepCommand.js +124 -0
- package/dist/internal/domain/StepInfo.d.ts +12 -0
- package/dist/internal/domain/StepInfo.js +10 -0
- package/dist/internal/domain/StepInput.d.ts +10 -0
- package/dist/internal/driver.js +14 -225
- package/dist/internal/errors.d.ts +1 -21
- package/dist/internal/errors.js +2 -51
- package/dist/internal/execution/CheckpointRun.js +25 -0
- package/dist/internal/execution/ExecutionFailure.js +19 -0
- package/dist/internal/execution/ExecutionHeaders.js +58 -0
- package/dist/internal/execution/ExecutionResponse.js +68 -0
- package/dist/internal/execution/ExecutionResult.js +56 -0
- package/dist/internal/execution/ExecutionScope.js +30 -0
- package/dist/internal/execution/HandlerRun.js +16 -0
- package/dist/internal/handler.d.ts +2 -4
- package/dist/internal/handler.js +87 -82
- package/dist/internal/protocol.d.ts +120 -5
- package/dist/internal/protocol.js +313 -150
- package/dist/internal/runtime/CheckpointContext.js +5 -0
- package/dist/internal/runtime/HandlerContext.d.ts +13 -0
- package/dist/internal/runtime/HandlerContext.js +19 -0
- package/dist/internal/runtime/HandlerFiberScope.d.ts +10 -0
- package/dist/internal/runtime/HandlerFiberScope.js +5 -0
- package/dist/internal/runtime/StepCommandBus.d.ts +27 -0
- package/dist/internal/runtime/StepCommandBus.js +76 -0
- package/dist/internal/runtime/StepIdentity.d.ts +27 -0
- package/dist/internal/runtime/StepIdentity.js +46 -0
- package/dist/internal/runtime/StepTools.d.ts +83 -0
- package/dist/internal/runtime/StepTools.js +76 -0
- package/dist/internal/runtime/steps/InvokeStep.js +43 -0
- package/dist/internal/runtime/steps/SendEventStep.js +46 -0
- package/dist/internal/runtime/steps/SleepStep.js +22 -0
- package/dist/internal/runtime/steps/SleepUntilStep.js +22 -0
- package/dist/internal/runtime/steps/StepRun.js +48 -0
- package/dist/internal/runtime/steps/WaitForEventStep.js +27 -0
- package/dist/internal/serve/HttpApp.js +71 -0
- package/dist/internal/serve/Request.js +23 -0
- package/dist/internal/{signature.d.ts → serve/Signature.d.ts} +2 -5
- package/dist/internal/serve/Signature.js +123 -0
- package/dist/internal/wire/Duration.js +19 -0
- package/dist/internal/wire/Timestamp.js +14 -0
- package/package.json +25 -10
- package/src/Client.ts +76 -74
- package/src/Event.ts +107 -0
- package/src/Events.ts +50 -30
- package/src/Function.ts +72 -53
- package/src/Group.ts +54 -119
- package/src/HttpApi.ts +5 -6
- package/src/index.ts +21 -11
- package/src/internal/checkpoint/Config.ts +74 -0
- package/src/internal/checkpoint/Error.ts +6 -0
- package/src/internal/checkpoint/State.ts +107 -0
- package/src/internal/checkpoint.ts +3 -218
- package/src/internal/codec/EventPayload.ts +98 -0
- package/src/internal/codec/StepResult.ts +95 -0
- package/src/internal/domain/ExecutionInput.ts +66 -0
- package/src/internal/domain/ExecutionSuspension.ts +79 -0
- package/src/internal/domain/FunctionDefinition.ts +30 -0
- package/src/internal/domain/Memo.ts +28 -0
- package/src/internal/domain/StepCommand.ts +166 -0
- package/src/internal/domain/StepInfo.ts +8 -0
- package/src/internal/domain/StepInput.ts +10 -0
- package/src/internal/driver.ts +26 -332
- package/src/internal/errors.ts +1 -102
- package/src/internal/execution/CheckpointRun.ts +33 -0
- package/src/internal/execution/ExecutionFailure.ts +19 -0
- package/src/internal/execution/ExecutionHeaders.ts +86 -0
- package/src/internal/execution/ExecutionResponse.ts +79 -0
- package/src/internal/execution/ExecutionResult.ts +57 -0
- package/src/internal/execution/ExecutionScope.ts +41 -0
- package/src/internal/execution/HandlerRun.ts +38 -0
- package/src/internal/handler.ts +94 -87
- package/src/internal/protocol.ts +239 -72
- package/src/internal/runtime/CheckpointContext.ts +7 -0
- package/src/internal/runtime/HandlerContext.ts +21 -0
- package/src/internal/runtime/HandlerFiberScope.ts +9 -0
- package/src/internal/runtime/StepCommandBus.ts +129 -0
- package/src/internal/runtime/StepIdentity.ts +67 -0
- package/src/internal/runtime/StepTools.ts +161 -0
- package/src/internal/runtime/steps/InvokeStep.ts +71 -0
- package/src/internal/runtime/steps/SendEventStep.ts +67 -0
- package/src/internal/runtime/steps/SleepStep.ts +34 -0
- package/src/internal/runtime/steps/SleepUntilStep.ts +34 -0
- package/src/internal/runtime/steps/StepRun.ts +95 -0
- package/src/internal/runtime/steps/WaitForEventStep.ts +55 -0
- package/src/internal/serve/HttpApp.ts +123 -0
- package/src/internal/serve/Request.ts +27 -0
- package/src/internal/serve/Signature.ts +170 -0
- package/src/internal/wire/Duration.ts +31 -0
- package/src/internal/wire/Timestamp.ts +11 -0
- package/dist/internal/checkpoint.js +0 -112
- package/dist/internal/constants.js +0 -14
- package/dist/internal/driver.d.ts +0 -1
- package/dist/internal/helpers.js +0 -47
- package/dist/internal/interrupts.d.ts +0 -1
- package/dist/internal/interrupts.js +0 -43
- package/dist/internal/memo.js +0 -58
- package/dist/internal/signature.js +0 -113
- package/dist/internal/step.d.ts +0 -53
- package/dist/internal/step.js +0 -208
- package/src/internal/constants.ts +0 -11
- package/src/internal/helpers.ts +0 -58
- package/src/internal/interrupts.ts +0 -62
- package/src/internal/memo.ts +0 -88
- package/src/internal/signature.ts +0 -176
- package/src/internal/step.ts +0 -447
package/README.md
CHANGED
|
@@ -25,14 +25,16 @@
|
|
|
25
25
|
Effect Inngest brings the power of [Effect](https://effect.website) to [Inngest's](https://inngest.com) durable execution platform. Define event schemas once, and types flow automatically through triggers, handlers, and step operations — no manual annotations needed.
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
|
-
import { InngestFunction, InngestGroup
|
|
28
|
+
import { InngestClient, InngestEvent, InngestFunction, InngestGroup } from "effect-inngest";
|
|
29
29
|
import { Effect, Schema, Layer } from "effect";
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const UserSignup = InngestEvent.make(
|
|
32
|
+
"user/signup",
|
|
33
|
+
Schema.Struct({
|
|
34
|
+
userId: Schema.String,
|
|
35
|
+
email: Schema.String,
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
36
38
|
|
|
37
39
|
// Create a function — event type is inferred from the trigger
|
|
38
40
|
const ProcessSignup = InngestFunction.make("process-signup", {
|
|
@@ -43,17 +45,15 @@ const ProcessSignup = InngestFunction.make("process-signup", {
|
|
|
43
45
|
// Create group and implement handler
|
|
44
46
|
const Group = InngestGroup.make(ProcessSignup);
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
userId: Schema.String,
|
|
48
|
-
}) {}
|
|
48
|
+
const UserOnboarded = InngestEvent.make("user/onboarded", Schema.Struct({ userId: Schema.String }));
|
|
49
49
|
|
|
50
50
|
const Handlers = Group.toLayer({
|
|
51
51
|
"process-signup": ({ event, step }) =>
|
|
52
52
|
Effect.gen(function* () {
|
|
53
|
-
// event is typed as
|
|
54
|
-
yield* step.run("send-welcome", sendWelcomeEmail(event.email));
|
|
53
|
+
// event is typed as { name: "user/signup", data: { userId, email } }
|
|
54
|
+
yield* step.run("send-welcome", sendWelcomeEmail(event.data.email));
|
|
55
55
|
yield* step.sleep("delay", "1 hour");
|
|
56
|
-
yield* step.sendEvent("notify",
|
|
56
|
+
yield* step.sendEvent("notify", UserOnboarded.make({ userId: event.data.userId }));
|
|
57
57
|
}),
|
|
58
58
|
});
|
|
59
59
|
```
|
|
@@ -109,17 +109,18 @@ import { BunHttpServer, BunRuntime } from "@effect/platform-bun";
|
|
|
109
109
|
import * as HttpMiddleware from "@effect/platform/HttpMiddleware";
|
|
110
110
|
import * as HttpServer from "@effect/platform/HttpServer";
|
|
111
111
|
import { Duration, Effect, Layer, Schema } from "effect";
|
|
112
|
-
import { InngestFunction, InngestGroup
|
|
113
|
-
|
|
114
|
-
// 1. Define your
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
import { InngestClient, InngestEvent, InngestFunction, InngestGroup } from "effect-inngest";
|
|
113
|
+
|
|
114
|
+
// 1. Define your Inngest event definitions
|
|
115
|
+
const UserSignup = InngestEvent.make(
|
|
116
|
+
"user/signup",
|
|
117
|
+
Schema.Struct({
|
|
118
|
+
userId: Schema.String,
|
|
119
|
+
email: Schema.String,
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
userId: Schema.String,
|
|
122
|
-
}) {}
|
|
123
|
+
const UserWelcomeSent = InngestEvent.make("user/welcome-sent", Schema.Struct({ userId: Schema.String }));
|
|
123
124
|
|
|
124
125
|
// 2. Define your functions
|
|
125
126
|
const ProcessSignup = InngestFunction.make("process-signup", {
|
|
@@ -138,17 +139,19 @@ const App = InngestGroup.make(ProcessSignup, DailyDigest);
|
|
|
138
139
|
const Handlers = App.toLayer({
|
|
139
140
|
"process-signup": ({ event, step }) =>
|
|
140
141
|
Effect.gen(function* () {
|
|
141
|
-
// event is typed as
|
|
142
|
-
yield* Effect.log(`Processing signup for ${event.email}`);
|
|
142
|
+
// event is typed as { name: "user/signup", data: { userId, email } }
|
|
143
|
+
yield* Effect.log(`Processing signup for ${event.data.email}`);
|
|
143
144
|
|
|
144
|
-
// Durable
|
|
145
|
-
const user = yield* step.run("create-user", Effect.succeed({ id: event.userId, email: event.email })
|
|
145
|
+
// Durable value-returning steps need a replay schema
|
|
146
|
+
const user = yield* step.run("create-user", Effect.succeed({ id: event.data.userId, email: event.data.email }), {
|
|
147
|
+
schema: Schema.Struct({ id: Schema.String, email: Schema.String }),
|
|
148
|
+
});
|
|
146
149
|
|
|
147
150
|
// Sleep durably
|
|
148
151
|
yield* step.sleep("welcome-delay", Duration.seconds(5));
|
|
149
152
|
|
|
150
153
|
// Send follow-up event
|
|
151
|
-
yield* step.sendEvent("notify",
|
|
154
|
+
yield* step.sendEvent("notify", UserWelcomeSent.make({ userId: user.id }));
|
|
152
155
|
|
|
153
156
|
return { welcomed: true };
|
|
154
157
|
}),
|
|
@@ -197,17 +200,18 @@ import { FetchHttpClient } from "@effect/platform";
|
|
|
197
200
|
import { BunHttpServer, BunRuntime } from "@effect/platform-bun";
|
|
198
201
|
import { Duration, Effect, Layer, Schema } from "effect";
|
|
199
202
|
import { InngestApiGroup, layerGroup } from "effect-inngest/HttpApi";
|
|
200
|
-
import { InngestClient, InngestFunction, InngestGroup } from "effect-inngest";
|
|
203
|
+
import { InngestClient, InngestEvent, InngestFunction, InngestGroup } from "effect-inngest";
|
|
201
204
|
|
|
202
205
|
// 1. Define your events
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
const UserSignup = InngestEvent.make(
|
|
207
|
+
"user/signup",
|
|
208
|
+
Schema.Struct({
|
|
209
|
+
userId: Schema.String,
|
|
210
|
+
email: Schema.String,
|
|
211
|
+
}),
|
|
212
|
+
);
|
|
207
213
|
|
|
208
|
-
|
|
209
|
-
userId: Schema.String,
|
|
210
|
-
}) {}
|
|
214
|
+
const UserWelcomeSent = InngestEvent.make("user/welcome-sent", Schema.Struct({ userId: Schema.String }));
|
|
211
215
|
|
|
212
216
|
// 2. Define functions
|
|
213
217
|
const ProcessSignup = InngestFunction.make("process-signup", {
|
|
@@ -226,10 +230,12 @@ const App = InngestGroup.make(ProcessSignup, DailyDigest);
|
|
|
226
230
|
const Handlers = App.toLayer({
|
|
227
231
|
"process-signup": ({ event, step }) =>
|
|
228
232
|
Effect.gen(function* () {
|
|
229
|
-
yield* Effect.log(`Processing signup for ${event.email}`);
|
|
230
|
-
const user = yield* step.run("create-user", Effect.succeed({ id: event.userId, email: event.email })
|
|
233
|
+
yield* Effect.log(`Processing signup for ${event.data.email}`);
|
|
234
|
+
const user = yield* step.run("create-user", Effect.succeed({ id: event.data.userId, email: event.data.email }), {
|
|
235
|
+
schema: Schema.Struct({ id: Schema.String, email: Schema.String }),
|
|
236
|
+
});
|
|
231
237
|
yield* step.sleep("welcome-delay", Duration.seconds(5));
|
|
232
|
-
yield* step.sendEvent("notify",
|
|
238
|
+
yield* step.sendEvent("notify", UserWelcomeSent.make({ userId: user.id }));
|
|
233
239
|
return { welcomed: true };
|
|
234
240
|
}),
|
|
235
241
|
"daily-digest": ({ step }) => step.run("send-digest", Effect.log("Sending daily digest...")),
|
|
@@ -262,22 +268,31 @@ BunRuntime.runMain(Layer.launch(Server));
|
|
|
262
268
|
|
|
263
269
|
## Getting Started
|
|
264
270
|
|
|
265
|
-
### 1. Define your events
|
|
271
|
+
### 1. Define your events
|
|
266
272
|
|
|
267
273
|
```typescript
|
|
268
274
|
import { Schema } from "effect";
|
|
275
|
+
import { InngestEvent } from "effect-inngest";
|
|
276
|
+
|
|
277
|
+
const UserSignup = InngestEvent.make(
|
|
278
|
+
"user/signup",
|
|
279
|
+
Schema.Struct({
|
|
280
|
+
userId: Schema.String,
|
|
281
|
+
email: Schema.String,
|
|
282
|
+
plan: Schema.Literal("free", "pro", "enterprise"),
|
|
283
|
+
}),
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
const OrderPlaced = InngestEvent.make(
|
|
287
|
+
"order/placed",
|
|
288
|
+
Schema.Struct({
|
|
289
|
+
orderId: Schema.String,
|
|
290
|
+
items: Schema.Array(Schema.Struct({ sku: Schema.String, qty: Schema.Number })),
|
|
291
|
+
total: Schema.Number,
|
|
292
|
+
}),
|
|
293
|
+
);
|
|
269
294
|
|
|
270
|
-
|
|
271
|
-
userId: Schema.String,
|
|
272
|
-
email: Schema.String,
|
|
273
|
-
plan: Schema.Literal("free", "pro", "enterprise"),
|
|
274
|
-
}) {}
|
|
275
|
-
|
|
276
|
-
class OrderPlaced extends Schema.TaggedClass<OrderPlaced>()("order/placed", {
|
|
277
|
-
orderId: Schema.String,
|
|
278
|
-
items: Schema.Array(Schema.Struct({ sku: Schema.String, qty: Schema.Number })),
|
|
279
|
-
total: Schema.Number,
|
|
280
|
-
}) {}
|
|
295
|
+
const UserWelcomeSent = InngestEvent.make("user/welcome-sent", Schema.Struct({ userId: Schema.String }));
|
|
281
296
|
```
|
|
282
297
|
|
|
283
298
|
### 2. Define your functions
|
|
@@ -311,7 +326,7 @@ const HandlersLive = AppFunctions.toLayer({
|
|
|
311
326
|
Effect.gen(function* () {
|
|
312
327
|
yield* step.run("create-user", createUser(event));
|
|
313
328
|
yield* step.sleep("delay", Duration.minutes(5));
|
|
314
|
-
yield* step.sendEvent("welcome",
|
|
329
|
+
yield* step.sendEvent("welcome", UserWelcomeSent.make({ userId: event.data.userId }));
|
|
315
330
|
return { welcomeEmailSent: true };
|
|
316
331
|
}),
|
|
317
332
|
|
|
@@ -350,8 +365,8 @@ All step operations are durable — they're memoized and survive retries:
|
|
|
350
365
|
```typescript
|
|
351
366
|
({ step }) =>
|
|
352
367
|
Effect.gen(function* () {
|
|
353
|
-
// Run
|
|
354
|
-
const user = yield* step.run("fetch-user", fetchUser(userId));
|
|
368
|
+
// Run an Effect with memoization. Value-returning steps require a replay schema.
|
|
369
|
+
const user = yield* step.run("fetch-user", fetchUser(userId), { schema: User });
|
|
355
370
|
|
|
356
371
|
// Sleep for a duration
|
|
357
372
|
yield* step.sleep("wait", Duration.hours(24));
|
|
@@ -372,7 +387,7 @@ All step operations are durable — they're memoized and survive retries:
|
|
|
372
387
|
});
|
|
373
388
|
|
|
374
389
|
// Send events
|
|
375
|
-
yield* step.sendEvent("notify",
|
|
390
|
+
yield* step.sendEvent("notify", OrderShipped.make({ orderId }));
|
|
376
391
|
});
|
|
377
392
|
```
|
|
378
393
|
|
|
@@ -384,7 +399,11 @@ Run steps in parallel with Effect's concurrency:
|
|
|
384
399
|
const [user, orders, prefs] =
|
|
385
400
|
yield *
|
|
386
401
|
Effect.all(
|
|
387
|
-
[
|
|
402
|
+
[
|
|
403
|
+
step.run("user", fetchUser(id), { schema: User }),
|
|
404
|
+
step.run("orders", fetchOrders(id), { schema: Schema.Array(Order) }),
|
|
405
|
+
step.run("prefs", fetchPreferences(id), { schema: Preferences }),
|
|
406
|
+
],
|
|
388
407
|
{ concurrency: "unbounded" },
|
|
389
408
|
);
|
|
390
409
|
```
|
|
@@ -409,7 +428,7 @@ const HandlersLive = AppFunctions.toLayer({
|
|
|
409
428
|
"process-signup": ({ event, step }) =>
|
|
410
429
|
Effect.gen(function* () {
|
|
411
430
|
const email = yield* EmailService;
|
|
412
|
-
yield* step.run("send", email.send(event.email, "Welcome!"));
|
|
431
|
+
yield* step.run("send", email.send(event.data.email, "Welcome!"));
|
|
413
432
|
return { welcomeEmailSent: true };
|
|
414
433
|
}),
|
|
415
434
|
});
|
|
@@ -440,7 +459,7 @@ const ProcessOrder = InngestFunction.make("process-order", {
|
|
|
440
459
|
debounce: { period: Duration.seconds(5) },
|
|
441
460
|
idempotency: "event.data.orderId",
|
|
442
461
|
timeouts: { finish: Duration.hours(1) },
|
|
443
|
-
cancelOn: [{ event:
|
|
462
|
+
cancelOn: [{ event: OrderCancelled, if: "event.data.orderId == async.data.orderId" }],
|
|
444
463
|
priority: { run: "event.data.isPremium ? 100 : 0" },
|
|
445
464
|
});
|
|
446
465
|
```
|
|
@@ -452,13 +471,14 @@ const ProcessOrder = InngestFunction.make("process-order", {
|
|
|
452
471
|
Control retry behavior with typed errors:
|
|
453
472
|
|
|
454
473
|
```typescript
|
|
474
|
+
import { Duration, Effect } from "effect";
|
|
455
475
|
import { NonRetriableError, RetryAfterError } from "effect-inngest";
|
|
456
476
|
|
|
457
477
|
// Don't retry this error
|
|
458
|
-
yield *
|
|
478
|
+
yield * Effect.fail(NonRetriableError.make({ message: "Card permanently declined" }));
|
|
459
479
|
|
|
460
|
-
// Retry after a specific duration
|
|
461
|
-
yield *
|
|
480
|
+
// Retry after a specific duration
|
|
481
|
+
yield * Effect.fail(RetryAfterError.make({ message: "Rate limited", retryAfter: Duration.seconds(30) }));
|
|
462
482
|
```
|
|
463
483
|
|
|
464
484
|
---
|
|
@@ -472,19 +492,21 @@ yield * new RetryAfterError({ message: "Rate limited", retryAfter: 60000 });
|
|
|
472
492
|
| `InngestFunction` | Function definition with trigger-based event inference |
|
|
473
493
|
| `InngestGroup` | Group functions, create handlers, and serve HTTP |
|
|
474
494
|
| `InngestClient` | Client configuration and event operations |
|
|
495
|
+
| `InngestEvent` | Event schema constructor with typed `.make` envelopes |
|
|
475
496
|
| `NonRetriableError` | Error to skip retries |
|
|
476
497
|
| `RetryAfterError` | Error to retry after delay |
|
|
477
498
|
|
|
478
499
|
### Step Methods
|
|
479
500
|
|
|
480
|
-
| Method
|
|
481
|
-
|
|
|
482
|
-
| `step.run(id, effect)`
|
|
483
|
-
| `step.
|
|
484
|
-
| `step.
|
|
485
|
-
| `step.
|
|
486
|
-
| `step.
|
|
487
|
-
| `step.
|
|
501
|
+
| Method | Description |
|
|
502
|
+
| ------------------------------------------------ | ----------------------------------------------- |
|
|
503
|
+
| `step.run(id, effect)` | Execute a void effect with memoization |
|
|
504
|
+
| `step.run(id, effect, { schema })` | Execute a value-returning effect with replay IO |
|
|
505
|
+
| `step.sleep(id, duration)` | Sleep for a duration |
|
|
506
|
+
| `step.sleepUntil(id, timestamp)` | Sleep until a timestamp |
|
|
507
|
+
| `step.waitForEvent(id, InngestEvent, opts)` | Wait for an event with timeout |
|
|
508
|
+
| `step.invoke(id, opts)` | Invoke another function |
|
|
509
|
+
| `step.sendEvent(id, InngestEvent.make(payload))` | Send events to Inngest |
|
|
488
510
|
|
|
489
511
|
---
|
|
490
512
|
|
package/dist/Client.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
+
import { CheckpointingOption } from "./internal/checkpoint/Config.js";
|
|
2
|
+
import { CheckpointApiError } from "./internal/checkpoint/Error.js";
|
|
1
3
|
import { GeneratorOpcode } from "./internal/protocol.js";
|
|
2
|
-
import {
|
|
3
|
-
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as Schema from "effect/Schema";
|
|
4
|
+
import { Config, Context, Effect, Layer, Schedule, Schema } from "effect";
|
|
5
5
|
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
6
|
-
import * as Context from "effect/Context";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as Config from "effect/Config";
|
|
9
6
|
import * as _$effect_Cause0 from "effect/Cause";
|
|
10
7
|
|
|
11
8
|
//#region src/Client.d.ts
|
|
12
9
|
declare namespace Client_d_exports {
|
|
13
|
-
export { CheckpointApiError, CheckpointingOption, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
|
10
|
+
export { CheckpointApiError, CheckpointRetrySchedule, CheckpointingOption, ClientConfig, ClientMode, EventPayload, InngestClient, InngestClientService, InngestConfig, SendEventError, SendEventResponse, TypeId, layer, layerConfig, layerFromEnv };
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
13
|
* @since 0.1.0
|
|
@@ -91,6 +88,11 @@ interface ClientConfig {
|
|
|
91
88
|
* The path where the Inngest serve handler is mounted. Used for registration.
|
|
92
89
|
*/
|
|
93
90
|
readonly servePath?: string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* The framework adapter serving this app, e.g. "bun" or "nodejs". Used for
|
|
93
|
+
* protocol headers and registration metadata.
|
|
94
|
+
*/
|
|
95
|
+
readonly framework?: string | undefined;
|
|
94
96
|
/**
|
|
95
97
|
* Whether to use checkpointing by default for executions of functions
|
|
96
98
|
* created using this client.
|
|
@@ -116,7 +118,7 @@ declare const EventPayload: Schema.Struct<{
|
|
|
116
118
|
readonly v: Schema.optional<Schema.String>;
|
|
117
119
|
}>;
|
|
118
120
|
declare const SendEventResponse: Schema.Struct<{
|
|
119
|
-
readonly ids: Schema.withDecodingDefault<Schema.$Array<Schema.String
|
|
121
|
+
readonly ids: Schema.withDecodingDefault<Schema.$Array<Schema.String>, never>;
|
|
120
122
|
readonly status: Schema.optional<Schema.Number>;
|
|
121
123
|
}>;
|
|
122
124
|
type EventPayload = typeof EventPayload.Type;
|
|
@@ -148,6 +150,9 @@ interface InngestClientService {
|
|
|
148
150
|
readonly runId: string;
|
|
149
151
|
readonly fnId: string;
|
|
150
152
|
readonly qiId: string;
|
|
153
|
+
readonly requestId?: string;
|
|
154
|
+
readonly generationId?: number;
|
|
155
|
+
readonly requestStartedAt?: number;
|
|
151
156
|
readonly steps: ReadonlyArray<typeof GeneratorOpcode.Type>;
|
|
152
157
|
}) => Effect.Effect<void, CheckpointApiError>;
|
|
153
158
|
}
|
|
@@ -159,6 +164,18 @@ declare const InngestClient_base: Context.ServiceClass<InngestClient, "effect-in
|
|
|
159
164
|
* @category context
|
|
160
165
|
*/
|
|
161
166
|
declare class InngestClient extends InngestClient_base {}
|
|
167
|
+
declare const InngestConfig_base: Context.ServiceClass<InngestConfig, "effect-inngest/InngestConfig", ClientConfig>;
|
|
168
|
+
/**
|
|
169
|
+
* Static Inngest application configuration.
|
|
170
|
+
*
|
|
171
|
+
* This is the narrow dependency for internals that need app settings but not
|
|
172
|
+
* client behavior such as event sending or checkpoint API calls.
|
|
173
|
+
*
|
|
174
|
+
* @since 0.1.0
|
|
175
|
+
* @category context
|
|
176
|
+
*/
|
|
177
|
+
declare class InngestConfig extends InngestConfig_base {}
|
|
178
|
+
declare const CheckpointRetrySchedule: Context.Reference<Schedule.Schedule<unknown, CheckpointApiError, never, never>>;
|
|
162
179
|
/**
|
|
163
180
|
* Create an InngestClient layer from a config.
|
|
164
181
|
*
|
|
@@ -172,14 +189,14 @@ declare class InngestClient extends InngestClient_base {}
|
|
|
172
189
|
* })
|
|
173
190
|
* ```
|
|
174
191
|
*/
|
|
175
|
-
declare const layer: (config: ClientConfig) => Layer.Layer<InngestClient, never, HttpClient.HttpClient>;
|
|
192
|
+
declare const layer: (config: ClientConfig) => Layer.Layer<InngestClient | InngestConfig, never, HttpClient.HttpClient>;
|
|
176
193
|
/**
|
|
177
194
|
* Create an InngestClient layer from Effect Config.
|
|
178
195
|
*
|
|
179
196
|
* @since 0.1.0
|
|
180
197
|
* @category layers
|
|
181
198
|
*/
|
|
182
|
-
declare const layerConfig: (config: Config.Wrap<ClientConfig>) => Layer.Layer<InngestClient, Config.ConfigError, HttpClient.HttpClient>;
|
|
199
|
+
declare const layerConfig: (config: Config.Wrap<ClientConfig>) => Layer.Layer<InngestClient | InngestConfig, Config.ConfigError, HttpClient.HttpClient>;
|
|
183
200
|
/**
|
|
184
201
|
* Create an InngestClient layer from environment variables.
|
|
185
202
|
*
|
|
@@ -193,6 +210,6 @@ declare const layerConfig: (config: Config.Wrap<ClientConfig>) => Layer.Layer<In
|
|
|
193
210
|
* @since 0.1.0
|
|
194
211
|
* @category layers
|
|
195
212
|
*/
|
|
196
|
-
declare const layerFromEnv: Layer.Layer<InngestClient, Config.ConfigError, HttpClient.HttpClient>;
|
|
213
|
+
declare const layerFromEnv: Layer.Layer<InngestClient | InngestConfig, Config.ConfigError, HttpClient.HttpClient>;
|
|
197
214
|
//#endregion
|
|
198
|
-
export { CheckpointApiError, type CheckpointingOption, Client_d_exports, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
|
215
|
+
export { CheckpointApiError, CheckpointRetrySchedule, type CheckpointingOption, ClientConfig, ClientMode, Client_d_exports, EventPayload, InngestClient, InngestClientService, InngestConfig, SendEventError, SendEventResponse, TypeId, layer, layerConfig, layerFromEnv };
|
package/dist/Client.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { CheckpointApiError } from "./internal/checkpoint.js";
|
|
3
|
-
import {
|
|
4
|
-
import { hashSigningKey } from "./internal/
|
|
5
|
-
import
|
|
6
|
-
import * as Effect from "effect/Effect";
|
|
7
|
-
import * as Option from "effect/Option";
|
|
8
|
-
import * as Ref from "effect/Ref";
|
|
9
|
-
import * as Schema from "effect/Schema";
|
|
2
|
+
import { CheckpointApiError } from "./internal/checkpoint/Error.js";
|
|
3
|
+
import { Headers } from "./internal/protocol.js";
|
|
4
|
+
import { hashSigningKey } from "./internal/serve/Signature.js";
|
|
5
|
+
import { Clock, Config, Context, Effect, Layer, Option, Predicate, Ref, Schedule, Schema } from "effect";
|
|
10
6
|
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
11
|
-
import * as Context from "effect/Context";
|
|
12
|
-
import * as Layer from "effect/Layer";
|
|
13
7
|
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
|
14
8
|
import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
|
|
15
|
-
import * as Config from "effect/Config";
|
|
16
|
-
import * as Predicate from "effect/Predicate";
|
|
17
|
-
import * as Schedule from "effect/Schedule";
|
|
18
9
|
//#region src/Client.ts
|
|
19
10
|
/**
|
|
20
11
|
* @since 0.1.0
|
|
21
12
|
*/
|
|
22
13
|
var Client_exports = /* @__PURE__ */ __exportAll({
|
|
23
14
|
CheckpointApiError: () => CheckpointApiError,
|
|
15
|
+
CheckpointRetrySchedule: () => CheckpointRetrySchedule,
|
|
24
16
|
EventPayload: () => EventPayload,
|
|
25
17
|
InngestClient: () => InngestClient,
|
|
18
|
+
InngestConfig: () => InngestConfig,
|
|
19
|
+
SendEventError: () => SendEventError,
|
|
20
|
+
TypeId: () => TypeId,
|
|
26
21
|
layer: () => layer,
|
|
27
22
|
layerConfig: () => layerConfig,
|
|
28
23
|
layerFromEnv: () => layerFromEnv
|
|
@@ -59,15 +54,27 @@ var SendEventError = class extends Schema.TaggedErrorClass()("SendEventError", {
|
|
|
59
54
|
* @category context
|
|
60
55
|
*/
|
|
61
56
|
var InngestClient = class extends Context.Service()("effect-inngest/InngestClient") {};
|
|
57
|
+
/**
|
|
58
|
+
* Static Inngest application configuration.
|
|
59
|
+
*
|
|
60
|
+
* This is the narrow dependency for internals that need app settings but not
|
|
61
|
+
* client behavior such as event sending or checkpoint API calls.
|
|
62
|
+
*
|
|
63
|
+
* @since 0.1.0
|
|
64
|
+
* @category context
|
|
65
|
+
*/
|
|
66
|
+
var InngestConfig = class extends Context.Service()("effect-inngest/InngestConfig") {};
|
|
62
67
|
const resolveMode = (config) => config.mode ?? "dev";
|
|
63
68
|
const resolveEventBaseUrl = (config, mode) => config.eventBaseUrl ?? (mode === "dev" ? DEFAULT_DEV_SERVER_URL : DEFAULT_EVENT_BASE_URL);
|
|
64
69
|
const resolveApiBaseUrl = (config, mode) => config.apiBaseUrl ?? (mode === "dev" ? DEFAULT_DEV_SERVER_URL : DEFAULT_API_BASE_URL);
|
|
65
|
-
const isRetriable = (error) => error.status
|
|
70
|
+
const isRetriable = (error) => Predicate.isUndefined(error.status) || error.status >= 500;
|
|
66
71
|
const defaultCheckpointRetrySchedule = Schedule.exponential("100 millis", 2).pipe(Schedule.jittered, Schedule.both(Schedule.recurs(5)), Schedule.while((m) => isRetriable(m.input)));
|
|
67
|
-
const
|
|
72
|
+
const CheckpointRetrySchedule = Context.Reference("effect-inngest/internal/CheckpointRetrySchedule", { defaultValue: () => defaultCheckpointRetrySchedule });
|
|
73
|
+
const makeClient = (config, httpClient) => Effect.gen(function* () {
|
|
68
74
|
const mode = resolveMode(config);
|
|
69
75
|
const eventBaseUrl = resolveEventBaseUrl(config, mode);
|
|
70
76
|
const apiBaseUrl = resolveApiBaseUrl(config, mode);
|
|
77
|
+
const retrySchedule = yield* CheckpointRetrySchedule;
|
|
71
78
|
/**
|
|
72
79
|
* One-way switch: once the fallback signing key succeeds for any
|
|
73
80
|
* checkpoint API call, all subsequent calls use it first. Per spec
|
|
@@ -79,7 +86,7 @@ const makeClient = (config, httpClient, retrySchedule = defaultCheckpointRetrySc
|
|
|
79
86
|
message: "Event key is required to send events in cloud mode",
|
|
80
87
|
events: events.map((e) => e.name)
|
|
81
88
|
}));
|
|
82
|
-
const key = config.eventKey ?? "
|
|
89
|
+
const key = config.eventKey ?? "NO_EVENT_KEY_SET";
|
|
83
90
|
const url = new URL(`e/${key}`, eventBaseUrl).toString();
|
|
84
91
|
const eventNames = events.map((e) => e.name);
|
|
85
92
|
const now = yield* Clock.currentTimeMillis;
|
|
@@ -108,14 +115,12 @@ const makeClient = (config, httpClient, retrySchedule = defaultCheckpointRetrySc
|
|
|
108
115
|
* error on non-2xx so the caller can decide whether to retry, swap keys,
|
|
109
116
|
* or fall back.
|
|
110
117
|
*/
|
|
111
|
-
const checkpointRequest = (runId, body,
|
|
118
|
+
const checkpointRequest = (runId, body, hashedSigningKey) => {
|
|
112
119
|
const url = new URL(`v1/checkpoint/${runId}/async`, apiBaseUrl).toString();
|
|
113
120
|
const request = HttpClientRequest.post(url).pipe(HttpClientRequest.setHeaders({
|
|
114
121
|
"Content-Type": "application/json",
|
|
115
|
-
[Headers.SDK]: `effect-inngest:v${SDK_VERSION}`,
|
|
116
|
-
[Headers.RequestVersion]: "2",
|
|
117
122
|
...config.env ? { [Headers.Env]: config.env } : {}
|
|
118
|
-
}), HttpClientRequest.bearerToken(
|
|
123
|
+
}), HttpClientRequest.bearerToken(hashedSigningKey), HttpClientRequest.bodyText(body, "application/json"));
|
|
119
124
|
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
125
|
if (response.status >= 200 && response.status < 300) return Effect.void;
|
|
121
126
|
return Effect.fail(new CheckpointApiError({
|
|
@@ -126,19 +131,23 @@ const makeClient = (config, httpClient, retrySchedule = defaultCheckpointRetrySc
|
|
|
126
131
|
};
|
|
127
132
|
const checkpointAsync = Effect.fn("InngestClient.checkpointAsync")(function* (args) {
|
|
128
133
|
const signingKey = config.signingKey;
|
|
129
|
-
if (!signingKey) return yield* Effect.fail(new CheckpointApiError({ message: "No signing key configured for checkpoint API" }));
|
|
134
|
+
if (!signingKey && mode !== "dev") return yield* Effect.fail(new CheckpointApiError({ message: "No signing key configured for checkpoint API" }));
|
|
130
135
|
const now = yield* Clock.currentTimeMillis;
|
|
131
136
|
const body = JSON.stringify({
|
|
132
137
|
run_id: args.runId,
|
|
133
138
|
fn_id: args.fnId,
|
|
134
139
|
qi_id: args.qiId,
|
|
135
|
-
|
|
140
|
+
request_id: args.requestId,
|
|
141
|
+
generation_id: args.generationId,
|
|
142
|
+
request_started_at: args.requestStartedAt,
|
|
143
|
+
steps: args.steps,
|
|
136
144
|
ts: now
|
|
137
145
|
});
|
|
138
146
|
const fallbackKey = config.signingKeyFallback;
|
|
139
147
|
return yield* Ref.get(useFallbackKey).pipe(Effect.flatMap((usingFallback) => {
|
|
140
148
|
const primaryKey = usingFallback && fallbackKey ? fallbackKey : signingKey;
|
|
141
|
-
|
|
149
|
+
const primaryToken = primaryKey ? hashSigningKey(primaryKey) : "";
|
|
150
|
+
return checkpointRequest(args.runId, body, primaryToken).pipe(Effect.catch((error) => error.status === 401 && !usingFallback && fallbackKey ? checkpointRequest(args.runId, body, hashSigningKey(fallbackKey)).pipe(Effect.andThen(Ref.set(useFallbackKey, true))) : Effect.fail(error)));
|
|
142
151
|
})).pipe(Effect.retry(retrySchedule));
|
|
143
152
|
});
|
|
144
153
|
return {
|
|
@@ -164,21 +173,17 @@ const makeClient = (config, httpClient, retrySchedule = defaultCheckpointRetrySc
|
|
|
164
173
|
* })
|
|
165
174
|
* ```
|
|
166
175
|
*/
|
|
167
|
-
const layer = (config) => Layer.effect(InngestClient, Effect.gen(function* () {
|
|
176
|
+
const layer = (config) => Layer.mergeAll(Layer.succeed(InngestConfig, config), Layer.effect(InngestClient, Effect.gen(function* () {
|
|
168
177
|
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
|
-
}));
|
|
178
|
+
})));
|
|
174
179
|
/**
|
|
175
180
|
* Create an InngestClient layer from Effect Config.
|
|
176
181
|
*
|
|
177
182
|
* @since 0.1.0
|
|
178
183
|
* @category layers
|
|
179
184
|
*/
|
|
180
|
-
const layerConfig = (config) => Layer.
|
|
181
|
-
return
|
|
185
|
+
const layerConfig = (config) => Layer.unwrap(Effect.gen(function* () {
|
|
186
|
+
return layer(yield* Config.unwrap(config));
|
|
182
187
|
}));
|
|
183
188
|
/**
|
|
184
189
|
* Create an InngestClient layer from environment variables.
|
|
@@ -200,4 +205,4 @@ const layerFromEnv = layerConfig(Config.all({
|
|
|
200
205
|
signingKeyFallback: Config.string("INNGEST_SIGNING_KEY_FALLBACK").pipe(Config.option, Config.map(Option.getOrUndefined))
|
|
201
206
|
}));
|
|
202
207
|
//#endregion
|
|
203
|
-
export { CheckpointApiError, Client_exports, EventPayload, InngestClient, layer, layerConfig, layerFromEnv };
|
|
208
|
+
export { CheckpointApiError, CheckpointRetrySchedule, Client_exports, EventPayload, InngestClient, InngestConfig, SendEventError, TypeId, layer, layerConfig, layerFromEnv };
|
package/dist/Event.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MakeOptions } from "effect/Schema";
|
|
3
|
+
|
|
4
|
+
//#region src/Event.d.ts
|
|
5
|
+
declare namespace Event_d_exports {
|
|
6
|
+
export { EventData, EventDefinition, EventEnvelope, EventOptions, EventType, TypeId, isEventSchema, make };
|
|
7
|
+
}
|
|
8
|
+
declare const TypeId: unique symbol;
|
|
9
|
+
interface EventOptions extends MakeOptions {
|
|
10
|
+
readonly id?: string;
|
|
11
|
+
readonly ts?: number;
|
|
12
|
+
readonly v?: string;
|
|
13
|
+
}
|
|
14
|
+
interface EventEnvelope<Name extends string, Data> extends EventOptions {
|
|
15
|
+
readonly name: Name;
|
|
16
|
+
readonly data: Data;
|
|
17
|
+
}
|
|
18
|
+
type EventFields<Name extends string, DataSchema extends Schema.Top> = {
|
|
19
|
+
readonly name: Schema.tag<Name>;
|
|
20
|
+
readonly data: DataSchema;
|
|
21
|
+
readonly id: Schema.optional<Schema.String>;
|
|
22
|
+
readonly ts: Schema.optional<Schema.Number>;
|
|
23
|
+
readonly v: Schema.optional<Schema.String>;
|
|
24
|
+
};
|
|
25
|
+
type EventStruct<Name extends string, DataSchema extends Schema.Top> = Schema.Struct<EventFields<Name, DataSchema>>;
|
|
26
|
+
type EventConstructor<Name extends string, DataSchema extends Schema.Top> = abstract new (_: never) => EventEnvelope<Name, Schema.Schema.Type<DataSchema>>;
|
|
27
|
+
type PayloadConstructor<Name extends string, DataSchema extends Schema.Top> = {
|
|
28
|
+
bivariance(data: Schema.Schema.Type<DataSchema>, options?: EventOptions): EventEnvelope<Name, Schema.Schema.Type<DataSchema>>;
|
|
29
|
+
}["bivariance"];
|
|
30
|
+
type EventDefinition<Name extends string = string, DataSchema extends Schema.Top = Schema.Top> = EventConstructor<Name, DataSchema> & Omit<Schema.Opaque<EventEnvelope<Name, Schema.Schema.Type<DataSchema>>, EventStruct<Name, DataSchema>, {}>, "make" | "~type.make"> & {
|
|
31
|
+
readonly [TypeId]: typeof TypeId;
|
|
32
|
+
readonly identifier: Name;
|
|
33
|
+
readonly schema: DataSchema;
|
|
34
|
+
readonly make: unknown extends Schema.Schema.Type<DataSchema> ? (data: never, options?: EventOptions) => EventEnvelope<Name, unknown> : PayloadConstructor<Name, DataSchema>;
|
|
35
|
+
readonly "~type.make": EventEnvelope<Name, Schema.Schema.Type<DataSchema>>;
|
|
36
|
+
};
|
|
37
|
+
type EventData<Event extends EventDefinition> = Event extends EventDefinition<any, infer S> ? Schema.Schema.Type<S> : never;
|
|
38
|
+
type EventType<Event extends EventDefinition> = Event extends EventDefinition<infer Name, infer S> ? EventEnvelope<Name, Schema.Schema.Type<S>> : never;
|
|
39
|
+
declare function make<const Name extends string>(name: Name): EventDefinition<Name, Schema.Struct<{}>>;
|
|
40
|
+
declare function make<const Name extends string, const DataSchema extends Schema.Top>(name: Name, schema: DataSchema): EventDefinition<Name, DataSchema>;
|
|
41
|
+
declare const isEventSchema: (value: unknown) => value is EventDefinition;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { EventData, EventDefinition, EventEnvelope, EventOptions, EventType, Event_d_exports, TypeId, isEventSchema, make };
|
package/dist/Event.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { Predicate, Schema } from "effect";
|
|
3
|
+
//#region src/Event.ts
|
|
4
|
+
/**
|
|
5
|
+
* Public event definitions.
|
|
6
|
+
*
|
|
7
|
+
* Inngest events are protocol-shaped: `{ name, data, id?, ts?, v? }`.
|
|
8
|
+
* The event name is the discriminator; user payload lives under `data`.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
*/
|
|
12
|
+
var Event_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
+
TypeId: () => TypeId,
|
|
14
|
+
isEventSchema: () => isEventSchema,
|
|
15
|
+
make: () => make
|
|
16
|
+
});
|
|
17
|
+
const TypeId = Symbol.for("effect-inngest/Event");
|
|
18
|
+
function make(name, schema = Schema.Struct({})) {
|
|
19
|
+
const fields = {
|
|
20
|
+
name: Schema.tag(name),
|
|
21
|
+
data: schema,
|
|
22
|
+
id: Schema.optional(Schema.String),
|
|
23
|
+
ts: Schema.optional(Schema.Number),
|
|
24
|
+
v: Schema.optional(Schema.String)
|
|
25
|
+
};
|
|
26
|
+
const Event = Schema.Opaque()(Schema.Struct(fields));
|
|
27
|
+
class InngestEvent {
|
|
28
|
+
static [TypeId] = TypeId;
|
|
29
|
+
static identifier = name;
|
|
30
|
+
static schema = schema;
|
|
31
|
+
static make(data, options) {
|
|
32
|
+
const { id, ts, v } = options ?? {};
|
|
33
|
+
return {
|
|
34
|
+
name,
|
|
35
|
+
data,
|
|
36
|
+
id,
|
|
37
|
+
ts,
|
|
38
|
+
v
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
Object.setPrototypeOf(InngestEvent, Event);
|
|
43
|
+
return InngestEvent;
|
|
44
|
+
}
|
|
45
|
+
const isEventSchema = (value) => Schema.isSchema(value) && Predicate.hasProperty(value, TypeId);
|
|
46
|
+
//#endregion
|
|
47
|
+
export { Event_exports, TypeId, isEventSchema, make };
|