effect-inngest 0.1.3 → 0.3.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/README.md +89 -67
- package/dist/Client.d.ts +76 -28
- package/dist/Client.js +92 -30
- package/dist/Event.d.ts +43 -0
- package/dist/Event.js +46 -0
- package/dist/Events.d.ts +48 -76
- package/dist/Events.js +18 -23
- package/dist/Function.d.ts +46 -19
- package/dist/Function.js +32 -22
- package/dist/Group.d.ts +19 -8
- package/dist/Group.js +30 -72
- package/dist/HttpApi.d.ts +51 -56
- package/dist/HttpApi.js +38 -21
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -3
- 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 -0
- 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 +15 -114
- package/dist/internal/errors.d.ts +21 -48
- package/dist/internal/errors.js +9 -44
- 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 +5 -16
- package/dist/internal/handler.js +128 -96
- package/dist/internal/protocol.d.ts +143 -1
- package/dist/internal/protocol.js +333 -138
- 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/serve/Signature.d.ts +11 -0
- 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 +34 -22
- package/src/Client.ts +269 -91
- package/src/Event.ts +107 -0
- package/src/Events.ts +50 -30
- package/src/Function.ts +102 -46
- package/src/Group.ts +56 -108
- package/src/HttpApi.ts +40 -30
- 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 -0
- 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 +27 -185
- package/src/internal/errors.ts +14 -108
- 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 +222 -172
- package/src/internal/protocol.ts +289 -78
- 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/_virtual/rolldown_runtime.js +0 -18
- package/dist/internal/constants.js +0 -15
- package/dist/internal/driver.d.ts +0 -5
- package/dist/internal/helpers.js +0 -44
- package/dist/internal/interrupts.d.ts +0 -2
- package/dist/internal/interrupts.js +0 -45
- package/dist/internal/memo.js +0 -56
- package/dist/internal/signature.d.ts +0 -18
- package/dist/internal/signature.js +0 -97
- package/dist/internal/step.d.ts +0 -59
- package/dist/internal/step.js +0 -192
- 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 -73
- package/src/internal/signature.ts +0 -158
- package/src/internal/step.ts +0 -394
package/dist/Group.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { InngestClient } from "./Client.js";
|
|
2
2
|
import { InngestFunction } from "./Function.js";
|
|
3
|
-
import { HandlerContext } from "./internal/
|
|
4
|
-
import
|
|
5
|
-
import * as HttpClient from "
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
8
|
-
import * as Layer from "effect/Layer";
|
|
3
|
+
import { HandlerContext } from "./internal/runtime/HandlerContext.js";
|
|
4
|
+
import { Context, Effect, Layer } from "effect";
|
|
5
|
+
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
6
|
+
import * as _$effect_unstable_http_HttpServerRequest0 from "effect/unstable/http/HttpServerRequest";
|
|
7
|
+
import * as _$effect_unstable_http_HttpServerResponse0 from "effect/unstable/http/HttpServerResponse";
|
|
9
8
|
|
|
10
9
|
//#region src/Group.d.ts
|
|
11
10
|
declare namespace Group_d_exports {
|
|
@@ -64,7 +63,7 @@ interface Handler<Tag extends string> {
|
|
|
64
63
|
* @since 0.1.0
|
|
65
64
|
* @category models
|
|
66
65
|
*/
|
|
67
|
-
type ToHandler<F extends InngestFunction.Any> = F extends InngestFunction<infer
|
|
66
|
+
type ToHandler<F extends InngestFunction.Any> = F extends InngestFunction<infer Tag, infer _Triggers, infer _Success> ? Handler<Tag> : never;
|
|
68
67
|
/**
|
|
69
68
|
* @since 0.1.0
|
|
70
69
|
* @category models
|
|
@@ -72,6 +71,10 @@ type ToHandler<F extends InngestFunction.Any> = F extends InngestFunction<infer
|
|
|
72
71
|
interface InngestGroup<Fns extends InngestFunction.Any> {
|
|
73
72
|
readonly [TypeId]: TypeId;
|
|
74
73
|
readonly functions: ReadonlyMap<string, Fns>;
|
|
74
|
+
/**
|
|
75
|
+
* Implement all handlers for the functions in this group, returning a context object.
|
|
76
|
+
*/
|
|
77
|
+
readonly toHandlers: <H extends HandlersFrom<Fns>>(handlers: H) => Effect.Effect<Context.Context<ToHandler<Fns>>, never, HandlersRequirements<H>>;
|
|
75
78
|
/**
|
|
76
79
|
* Implement all handlers for the functions in this group.
|
|
77
80
|
*/
|
|
@@ -80,6 +83,14 @@ interface InngestGroup<Fns extends InngestFunction.Any> {
|
|
|
80
83
|
* Implement a single handler from the group.
|
|
81
84
|
*/
|
|
82
85
|
readonly toLayerHandler: <Tag extends InngestFunction.Tag<Fns>, H extends HandlerFrom<Fns, Tag>>(tag: Tag, handler: H) => Layer.Layer<Handler<Tag>, never, HandlerRequirements<H>>;
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve a handler for a specific function in the group.
|
|
88
|
+
*/
|
|
89
|
+
readonly accessHandler: <Tag extends InngestFunction.Tag<Fns>>(tag: Tag) => Effect.Effect<(context: HandlerContext<Extract<Fns, {
|
|
90
|
+
readonly _tag: Tag;
|
|
91
|
+
}>>) => Effect.Effect<InngestFunction.Success<Extract<Fns, {
|
|
92
|
+
readonly _tag: Tag;
|
|
93
|
+
}>>, unknown>, never, Handler<Tag>>;
|
|
83
94
|
}
|
|
84
95
|
/**
|
|
85
96
|
* @since 0.1.0
|
|
@@ -116,7 +127,7 @@ declare const make: <Fns extends ReadonlyArray<InngestFunction.Any>>(...fns: Fns
|
|
|
116
127
|
* )
|
|
117
128
|
* ```
|
|
118
129
|
*/
|
|
119
|
-
declare const toHttpApp: (group: InngestGroup.Any) =>
|
|
130
|
+
declare const toHttpApp: (group: InngestGroup.Any) => Effect.Effect<_$effect_unstable_http_HttpServerResponse0.HttpServerResponse, never, InngestClient | HttpClient.HttpClient | _$effect_unstable_http_HttpServerRequest0.HttpServerRequest>;
|
|
120
131
|
/**
|
|
121
132
|
* Create a standalone web handler from an InngestGroup.
|
|
122
133
|
*
|
package/dist/Group.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import { __exportAll } from "./_virtual/
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import "@effect/platform/HttpClient";
|
|
7
|
-
import * as HttpServerRequest from "@effect/platform/HttpServerRequest";
|
|
8
|
-
import * as HttpServerResponse from "@effect/platform/HttpServerResponse";
|
|
9
|
-
import * as UrlParams from "@effect/platform/UrlParams";
|
|
10
|
-
import * as Context from "effect/Context";
|
|
11
|
-
import * as Effect from "effect/Effect";
|
|
12
|
-
import * as Layer from "effect/Layer";
|
|
13
|
-
import * as Option from "effect/Option";
|
|
14
|
-
import * as Schema from "effect/Schema";
|
|
15
|
-
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import "./internal/runtime/HandlerContext.js";
|
|
3
|
+
import { toHttpApp as toHttpApp$1, toWebHandler as toWebHandler$1 } from "./internal/serve/HttpApp.js";
|
|
4
|
+
import { Context, Effect, Layer } from "effect";
|
|
5
|
+
import "effect/unstable/http/HttpClient";
|
|
16
6
|
//#region src/Group.ts
|
|
17
|
-
/**
|
|
18
|
-
* @since 0.1.0
|
|
19
|
-
*/
|
|
20
7
|
var Group_exports = /* @__PURE__ */ __exportAll({
|
|
21
8
|
TypeId: () => TypeId,
|
|
22
9
|
make: () => make,
|
|
@@ -30,20 +17,24 @@ var Group_exports = /* @__PURE__ */ __exportAll({
|
|
|
30
17
|
const TypeId = Symbol.for("effect-inngest/Group");
|
|
31
18
|
const Proto = {
|
|
32
19
|
[TypeId]: TypeId,
|
|
33
|
-
|
|
20
|
+
toHandlers(handlers) {
|
|
34
21
|
const functions = this.functions;
|
|
35
|
-
return
|
|
22
|
+
return Effect.gen(function* () {
|
|
36
23
|
const context = yield* Effect.context();
|
|
37
24
|
const contextMap = /* @__PURE__ */ new Map();
|
|
38
25
|
for (const [tag, handler] of Object.entries(handlers)) {
|
|
39
26
|
const fn = functions.get(tag);
|
|
40
27
|
contextMap.set(fn.key, {
|
|
28
|
+
tag: fn._tag,
|
|
41
29
|
handler,
|
|
42
30
|
context
|
|
43
31
|
});
|
|
44
32
|
}
|
|
45
|
-
return Context.
|
|
46
|
-
})
|
|
33
|
+
return Context.makeUnsafe(contextMap);
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
toLayer(handlers) {
|
|
37
|
+
return Layer.effectContext(this.toHandlers(handlers));
|
|
47
38
|
},
|
|
48
39
|
toLayerHandler(tag, handler) {
|
|
49
40
|
const fn = this.functions.get(tag);
|
|
@@ -51,11 +42,19 @@ const Proto = {
|
|
|
51
42
|
const context = yield* Effect.context();
|
|
52
43
|
const contextMap = /* @__PURE__ */ new Map();
|
|
53
44
|
contextMap.set(fn.key, {
|
|
45
|
+
tag: fn._tag,
|
|
54
46
|
handler,
|
|
55
47
|
context
|
|
56
48
|
});
|
|
57
|
-
return Context.
|
|
49
|
+
return Context.makeUnsafe(contextMap);
|
|
58
50
|
}));
|
|
51
|
+
},
|
|
52
|
+
accessHandler(tag) {
|
|
53
|
+
return Effect.contextWith((parentContext) => {
|
|
54
|
+
const fn = this.functions.get(tag);
|
|
55
|
+
const { handler, context } = parentContext.mapUnsafe.get(fn.key);
|
|
56
|
+
return Effect.succeed((handlerContext) => Effect.provide(handler(handlerContext), context));
|
|
57
|
+
});
|
|
59
58
|
}
|
|
60
59
|
};
|
|
61
60
|
/**
|
|
@@ -88,52 +87,9 @@ const make = (...fns) => {
|
|
|
88
87
|
* )
|
|
89
88
|
* ```
|
|
90
89
|
*/
|
|
91
|
-
const toHttpApp =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const requestUrl = Option.match(HttpServerRequest.toURL(request), {
|
|
95
|
-
onNone: () => request.url,
|
|
96
|
-
onSome: (url) => url.toString()
|
|
97
|
-
});
|
|
98
|
-
if (method === "GET") {
|
|
99
|
-
const result = yield* handleIntrospection(group, requestUrl);
|
|
100
|
-
return yield* HttpServerResponse.json(result.body, {
|
|
101
|
-
status: result.status,
|
|
102
|
-
headers: result.headers
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
if (method === "PUT") {
|
|
106
|
-
const result = yield* handleRegistration(group, requestUrl);
|
|
107
|
-
return yield* HttpServerResponse.json(result.body, {
|
|
108
|
-
status: result.status,
|
|
109
|
-
headers: result.headers
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (method === "POST") {
|
|
113
|
-
const url = Option.getOrThrow(HttpServerRequest.toURL(request));
|
|
114
|
-
const ExecuteParams = Schema.Struct({
|
|
115
|
-
fnId: Schema.String,
|
|
116
|
-
stepId: Schema.optional(Schema.String)
|
|
117
|
-
});
|
|
118
|
-
const params = yield* UrlParams.schemaStruct(ExecuteParams)(UrlParams.fromInput(url.searchParams)).pipe(Effect.catchAll(() => Effect.fail(HttpServerResponse.unsafeJson({ error: "Missing or invalid fnId query parameter" }, {
|
|
119
|
-
status: 400,
|
|
120
|
-
headers: { [Headers.NoRetry]: "true" }
|
|
121
|
-
}))));
|
|
122
|
-
const body = yield* verifyAndParseRequestBody(request).pipe(Effect.provide(SignatureLive), Effect.catchAll((error) => Effect.fail(HttpServerResponse.unsafeJson({ error: error.message }, {
|
|
123
|
-
status: error._tag === "SignatureError" ? 401 : 400,
|
|
124
|
-
headers: { [Headers.NoRetry]: "true" }
|
|
125
|
-
}))));
|
|
126
|
-
const result = yield* handleExecution(group, params.fnId, params.stepId, body);
|
|
127
|
-
return yield* HttpServerResponse.json(result.body, {
|
|
128
|
-
status: result.status,
|
|
129
|
-
headers: result.headers
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return yield* HttpServerResponse.json({ error: `Method ${method} not allowed` }, { status: 405 });
|
|
133
|
-
}).pipe(Effect.catchAllCause((cause) => HttpServerResponse.json({
|
|
134
|
-
error: "Internal server error",
|
|
135
|
-
cause: String(cause)
|
|
136
|
-
}, { status: 500 }).pipe(Effect.orDie)));
|
|
90
|
+
const toHttpApp = Effect.fn("InngestGroup.toHttpApp")(function* (group) {
|
|
91
|
+
return yield* toHttpApp$1(group);
|
|
92
|
+
});
|
|
137
93
|
/**
|
|
138
94
|
* Create a standalone web handler from an InngestGroup.
|
|
139
95
|
*
|
|
@@ -158,7 +114,9 @@ const toHttpApp = (group) => Effect.gen(function* () {
|
|
|
158
114
|
* process.on("SIGTERM", dispose)
|
|
159
115
|
* ```
|
|
160
116
|
*/
|
|
161
|
-
const toWebHandler = (group, options) =>
|
|
162
|
-
|
|
117
|
+
const toWebHandler = (group, options) => toWebHandler$1({
|
|
118
|
+
group,
|
|
119
|
+
options
|
|
120
|
+
});
|
|
163
121
|
//#endregion
|
|
164
|
-
export { Group_exports, TypeId, make, toHttpApp, toWebHandler };
|
|
122
|
+
export { Group_exports, TypeId, make, toHttpApp, toWebHandler };
|
package/dist/HttpApi.d.ts
CHANGED
|
@@ -1,75 +1,70 @@
|
|
|
1
1
|
import { InngestClient } from "./Client.js";
|
|
2
2
|
import { InngestGroup } from "./Group.js";
|
|
3
|
-
import { SignatureError } from "./internal/
|
|
3
|
+
import { SignatureError } from "./internal/serve/Signature.js";
|
|
4
4
|
import { InvalidRequestError } from "./internal/handler.js";
|
|
5
|
-
import
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
5
|
+
import { Layer, Schema } from "effect";
|
|
6
|
+
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
7
|
+
import * as HttpApi from "effect/unstable/httpapi/HttpApi";
|
|
8
|
+
import * as HttpApiEndpoint from "effect/unstable/httpapi/HttpApiEndpoint";
|
|
9
|
+
import * as HttpApiGroup from "effect/unstable/httpapi/HttpApiGroup";
|
|
10
|
+
import * as _$effect_Cause0 from "effect/Cause";
|
|
11
11
|
|
|
12
12
|
//#region src/HttpApi.d.ts
|
|
13
13
|
declare namespace HttpApi_d_exports {
|
|
14
14
|
export { InngestApiGroup, layerGroup };
|
|
15
15
|
}
|
|
16
|
-
declare const FunctionNotFoundError_base: Schema.
|
|
17
|
-
readonly
|
|
18
|
-
}
|
|
19
|
-
message: typeof Schema.String;
|
|
20
|
-
}>;
|
|
16
|
+
declare const FunctionNotFoundError_base: Schema.Class<FunctionNotFoundError, Schema.TaggedStruct<"FunctionNotFoundError", {
|
|
17
|
+
readonly message: Schema.String;
|
|
18
|
+
}>, _$effect_Cause0.YieldableError>;
|
|
21
19
|
declare class FunctionNotFoundError extends FunctionNotFoundError_base {}
|
|
20
|
+
declare const InngestApiGroup_base: HttpApiGroup.HttpApiGroup<"inngest", HttpApiEndpoint.HttpApiEndpoint<"introspect", "GET", "/", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Union<readonly [Schema.Struct<{
|
|
21
|
+
readonly function_count: Schema.Number;
|
|
22
|
+
readonly has_event_key: Schema.Boolean;
|
|
23
|
+
readonly has_signing_key: Schema.Boolean;
|
|
24
|
+
readonly has_signing_key_fallback: Schema.optional<Schema.Boolean>;
|
|
25
|
+
readonly mode: Schema.Literals<readonly ["cloud", "dev"]>;
|
|
26
|
+
readonly schema_version: Schema.Literal<"2024-05-24">;
|
|
27
|
+
readonly extra: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
28
|
+
readonly authentication_succeeded: Schema.Literal<true>;
|
|
29
|
+
readonly api_origin: Schema.String;
|
|
30
|
+
readonly app_id: Schema.String;
|
|
31
|
+
readonly env: Schema.NullOr<Schema.String>;
|
|
32
|
+
readonly event_api_origin: Schema.String;
|
|
33
|
+
readonly event_key_hash: Schema.NullOr<Schema.String>;
|
|
34
|
+
readonly framework: Schema.String;
|
|
35
|
+
readonly sdk_language: Schema.String;
|
|
36
|
+
readonly sdk_version: Schema.String;
|
|
37
|
+
readonly serve_origin: Schema.NullOr<Schema.String>;
|
|
38
|
+
readonly serve_path: Schema.NullOr<Schema.String>;
|
|
39
|
+
readonly signing_key_fallback_hash: Schema.NullOr<Schema.String>;
|
|
40
|
+
readonly signing_key_hash: Schema.NullOr<Schema.String>;
|
|
41
|
+
}>, Schema.Struct<{
|
|
42
|
+
readonly function_count: Schema.Number;
|
|
43
|
+
readonly has_event_key: Schema.Boolean;
|
|
44
|
+
readonly has_signing_key: Schema.Boolean;
|
|
45
|
+
readonly has_signing_key_fallback: Schema.optional<Schema.Boolean>;
|
|
46
|
+
readonly mode: Schema.Literals<readonly ["cloud", "dev"]>;
|
|
47
|
+
readonly schema_version: Schema.Literal<"2024-05-24">;
|
|
48
|
+
readonly extra: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
49
|
+
readonly authentication_succeeded: Schema.optional<Schema.Union<readonly [Schema.Literal<false>, Schema.Null]>>;
|
|
50
|
+
readonly capabilities: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
51
|
+
readonly functions: Schema.optionalKey<Schema.$Array<Schema.Unknown>>;
|
|
52
|
+
}>]>>, HttpApiEndpoint.Json<typeof FunctionNotFoundError | typeof InvalidRequestError | typeof SignatureError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"register", "PUT", "/", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
53
|
+
readonly message: Schema.String;
|
|
54
|
+
readonly modified: Schema.Boolean;
|
|
55
|
+
}>>, HttpApiEndpoint.Json<typeof FunctionNotFoundError | typeof InvalidRequestError | typeof SignatureError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"execute", "POST", "/", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<Schema.Struct<{
|
|
56
|
+
readonly fnId: Schema.String;
|
|
57
|
+
readonly stepId: Schema.optional<Schema.String>;
|
|
58
|
+
}>>, HttpApiEndpoint.Json<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Unknown>, HttpApiEndpoint.Json<typeof FunctionNotFoundError | typeof InvalidRequestError | typeof SignatureError>, never, never>, false>;
|
|
22
59
|
/**
|
|
23
60
|
* @since 0.1.0
|
|
24
61
|
* @category api
|
|
25
62
|
*/
|
|
26
|
-
declare
|
|
27
|
-
readonly function_count: number;
|
|
28
|
-
readonly has_event_key: boolean;
|
|
29
|
-
readonly has_signing_key: boolean;
|
|
30
|
-
readonly has_signing_key_fallback: boolean;
|
|
31
|
-
readonly mode: "cloud" | "dev";
|
|
32
|
-
readonly schema_version: "2024-05-24";
|
|
33
|
-
readonly extra?: {
|
|
34
|
-
readonly [x: string]: unknown;
|
|
35
|
-
} | undefined;
|
|
36
|
-
} & {
|
|
37
|
-
readonly authentication_succeeded: true;
|
|
38
|
-
readonly api_origin: string;
|
|
39
|
-
readonly app_id: string;
|
|
40
|
-
readonly env: string | null;
|
|
41
|
-
readonly event_api_origin: string;
|
|
42
|
-
readonly event_key_hash: string | null;
|
|
43
|
-
readonly framework: string;
|
|
44
|
-
readonly sdk_language: string;
|
|
45
|
-
readonly sdk_version: string;
|
|
46
|
-
readonly serve_origin: string | null;
|
|
47
|
-
readonly serve_path: string | null;
|
|
48
|
-
readonly signing_key_fallback_hash: string | null;
|
|
49
|
-
readonly signing_key_hash: string | null;
|
|
50
|
-
}) | ({
|
|
51
|
-
readonly function_count: number;
|
|
52
|
-
readonly has_event_key: boolean;
|
|
53
|
-
readonly has_signing_key: boolean;
|
|
54
|
-
readonly has_signing_key_fallback: boolean;
|
|
55
|
-
readonly mode: "cloud" | "dev";
|
|
56
|
-
readonly schema_version: "2024-05-24";
|
|
57
|
-
readonly extra?: {
|
|
58
|
-
readonly [x: string]: unknown;
|
|
59
|
-
} | undefined;
|
|
60
|
-
} & {
|
|
61
|
-
readonly authentication_succeeded: false | null;
|
|
62
|
-
readonly functions?: readonly unknown[] | undefined;
|
|
63
|
-
}), never, never, never> | HttpApiEndpoint.HttpApiEndpoint<"register", "PUT", never, never, never, never, {
|
|
64
|
-
readonly message?: string | undefined;
|
|
65
|
-
}, never, never, never> | HttpApiEndpoint.HttpApiEndpoint<"execute", "POST", never, {
|
|
66
|
-
readonly fnId: string;
|
|
67
|
-
readonly stepId?: string | undefined;
|
|
68
|
-
}, never, never, unknown, never, never, never>, FunctionNotFoundError | InvalidRequestError | SignatureError, never, false>;
|
|
63
|
+
declare class InngestApiGroup extends InngestApiGroup_base {}
|
|
69
64
|
/**
|
|
70
65
|
* @since 0.1.0
|
|
71
66
|
* @category layers
|
|
72
67
|
*/
|
|
73
|
-
declare const layerGroup: <ApiId extends string, Groups extends HttpApiGroup.
|
|
68
|
+
declare const layerGroup: <ApiId extends string, Groups extends HttpApiGroup.Any>(api: HttpApi.HttpApi<ApiId, Groups>, group: InngestGroup.Any) => Layer.Layer<HttpApiGroup.ApiGroup<ApiId, "inngest">, never, InngestClient | HttpClient.HttpClient>;
|
|
74
69
|
//#endregion
|
|
75
70
|
export { HttpApi_d_exports, InngestApiGroup, layerGroup };
|
package/dist/HttpApi.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { __exportAll } from "./_virtual/
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { IntrospectionResponse, RegisterResponse } from "./internal/protocol.js";
|
|
3
|
-
import { SignatureError, SignatureLive } from "./internal/
|
|
3
|
+
import { SignatureError, SignatureLive } from "./internal/serve/Signature.js";
|
|
4
4
|
import { InvalidRequestError, handleExecution, handleIntrospection, handleRegistration, verifyAndParseRequestBody } from "./internal/handler.js";
|
|
5
|
-
import "
|
|
6
|
-
import
|
|
7
|
-
import * as
|
|
8
|
-
import "effect/
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
11
|
-
import "
|
|
12
|
-
import * as HttpApiBuilder from "@effect/platform/HttpApiBuilder";
|
|
13
|
-
import * as HttpApiEndpoint from "@effect/platform/HttpApiEndpoint";
|
|
14
|
-
import * as HttpApiGroup from "@effect/platform/HttpApiGroup";
|
|
15
|
-
|
|
5
|
+
import { Effect, Layer, Option, Schema } from "effect";
|
|
6
|
+
import "effect/unstable/http/HttpClient";
|
|
7
|
+
import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
|
8
|
+
import "effect/unstable/httpapi/HttpApi";
|
|
9
|
+
import * as HttpApiBuilder from "effect/unstable/httpapi/HttpApiBuilder";
|
|
10
|
+
import * as HttpApiEndpoint from "effect/unstable/httpapi/HttpApiEndpoint";
|
|
11
|
+
import * as HttpApiGroup from "effect/unstable/httpapi/HttpApiGroup";
|
|
16
12
|
//#region src/HttpApi.ts
|
|
17
13
|
var HttpApi_exports = /* @__PURE__ */ __exportAll({
|
|
18
14
|
InngestApiGroup: () => InngestApiGroup,
|
|
@@ -22,15 +18,30 @@ const ExecuteParams = Schema.Struct({
|
|
|
22
18
|
fnId: Schema.String,
|
|
23
19
|
stepId: Schema.optional(Schema.String)
|
|
24
20
|
});
|
|
25
|
-
var FunctionNotFoundError = class extends Schema.
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
var FunctionNotFoundError = class extends Schema.TaggedErrorClass()("FunctionNotFoundError", { message: Schema.String }) {};
|
|
22
|
+
const CommonErrors = [
|
|
23
|
+
FunctionNotFoundError,
|
|
24
|
+
InvalidRequestError,
|
|
25
|
+
SignatureError
|
|
26
|
+
];
|
|
27
|
+
const IntrospectEndpoint = HttpApiEndpoint.get("introspect", "/", {
|
|
28
|
+
success: IntrospectionResponse,
|
|
29
|
+
error: CommonErrors
|
|
30
|
+
});
|
|
31
|
+
const RegisterEndpoint = HttpApiEndpoint.put("register", "/", {
|
|
32
|
+
success: RegisterResponse,
|
|
33
|
+
error: CommonErrors
|
|
34
|
+
});
|
|
35
|
+
const ExecuteEndpoint = HttpApiEndpoint.post("execute", "/", {
|
|
36
|
+
query: ExecuteParams,
|
|
37
|
+
success: Schema.Unknown,
|
|
38
|
+
error: CommonErrors
|
|
39
|
+
});
|
|
29
40
|
/**
|
|
30
41
|
* @since 0.1.0
|
|
31
42
|
* @category api
|
|
32
43
|
*/
|
|
33
|
-
|
|
44
|
+
var InngestApiGroup = class extends HttpApiGroup.make("inngest").add(IntrospectEndpoint).add(RegisterEndpoint).add(ExecuteEndpoint) {};
|
|
34
45
|
/**
|
|
35
46
|
* @since 0.1.0
|
|
36
47
|
* @category layers
|
|
@@ -40,8 +51,14 @@ const layerGroup = (api, group) => {
|
|
|
40
51
|
onNone: () => req.url,
|
|
41
52
|
onSome: (url) => url.toString()
|
|
42
53
|
});
|
|
43
|
-
return HttpApiBuilder.group(api, "inngest",
|
|
54
|
+
return HttpApiBuilder.group(api, "inngest", Effect.fn(function* (handlers) {
|
|
55
|
+
return handlers.handle("introspect", ({ request }) => handleIntrospection(group, toUrl(request)).pipe(Effect.map((r) => r.body))).handle("register", ({ request }) => handleRegistration(group, toUrl(request)).pipe(Effect.map((r) => r.body))).handleRaw("execute", ({ query, request }) => verifyAndParseRequestBody(request).pipe(Effect.flatMap((payload) => handleExecution({
|
|
56
|
+
group,
|
|
57
|
+
fnId: query.fnId,
|
|
58
|
+
urlStepId: query.stepId,
|
|
59
|
+
body: payload
|
|
60
|
+
})), Effect.map((r) => r.body)));
|
|
61
|
+
})).pipe(Layer.provide(SignatureLive));
|
|
44
62
|
};
|
|
45
|
-
|
|
46
63
|
//#endregion
|
|
47
|
-
export { HttpApi_exports, InngestApiGroup, layerGroup };
|
|
64
|
+
export { HttpApi_exports, InngestApiGroup, layerGroup };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Client_d_exports } from "./Client.js";
|
|
2
|
+
import { Event_d_exports } from "./Event.js";
|
|
2
3
|
import { Events_d_exports } from "./Events.js";
|
|
3
4
|
import { Function_d_exports } from "./Function.js";
|
|
4
5
|
import { NonRetriableError, RetryAfterError } from "./internal/errors.js";
|
|
5
6
|
import { Group_d_exports } from "./Group.js";
|
|
6
7
|
import { HttpApi_d_exports } from "./HttpApi.js";
|
|
7
|
-
export { Client_d_exports as InngestClient, Events_d_exports as InngestEvents, Function_d_exports as InngestFunction, Group_d_exports as InngestGroup, HttpApi_d_exports as InngestHttpApi, NonRetriableError, RetryAfterError };
|
|
8
|
+
export { Client_d_exports as InngestClient, Event_d_exports as InngestEvent, Events_d_exports as InngestEvents, Function_d_exports as InngestFunction, Group_d_exports as InngestGroup, HttpApi_d_exports as InngestHttpApi, NonRetriableError, RetryAfterError };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Function_exports } from "./Function.js";
|
|
2
|
+
import { Event_exports } from "./Event.js";
|
|
2
3
|
import { Client_exports } from "./Client.js";
|
|
3
4
|
import { NonRetriableError, RetryAfterError } from "./internal/errors.js";
|
|
5
|
+
import { Events_exports } from "./Events.js";
|
|
4
6
|
import { Group_exports } from "./Group.js";
|
|
5
7
|
import { HttpApi_exports } from "./HttpApi.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export { Client_exports as InngestClient, Events_exports as InngestEvents, Function_exports as InngestFunction, Group_exports as InngestGroup, HttpApi_exports as InngestHttpApi, NonRetriableError, RetryAfterError };
|
|
8
|
+
export { Client_exports as InngestClient, Event_exports as InngestEvent, Events_exports as InngestEvents, Function_exports as InngestFunction, Group_exports as InngestGroup, HttpApi_exports as InngestHttpApi, NonRetriableError, RetryAfterError };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Duration } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/checkpoint/Config.d.ts
|
|
4
|
+
type CheckpointingOption = boolean | {
|
|
5
|
+
readonly bufferedSteps?: number;
|
|
6
|
+
readonly maxInterval?: Duration.Input;
|
|
7
|
+
readonly maxRuntime?: Duration.Input;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { CheckpointingOption };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InngestDuration } from "../wire/Duration.js";
|
|
2
|
+
import { Duration, Predicate, Schema } from "effect";
|
|
3
|
+
//#region src/internal/checkpoint/Config.ts
|
|
4
|
+
const DEFAULTS = {
|
|
5
|
+
bufferedSteps: 1,
|
|
6
|
+
maxInterval: Duration.millis(0),
|
|
7
|
+
maxRuntime: Duration.seconds(10)
|
|
8
|
+
};
|
|
9
|
+
const normalize = (option) => ({
|
|
10
|
+
bufferedSteps: option.bufferedSteps ?? DEFAULTS.bufferedSteps,
|
|
11
|
+
maxInterval: Predicate.isNotUndefined(option.maxInterval) ? Duration.fromInputUnsafe(option.maxInterval) : DEFAULTS.maxInterval,
|
|
12
|
+
maxRuntime: Predicate.isNotUndefined(option.maxRuntime) ? Duration.fromInputUnsafe(option.maxRuntime) : DEFAULTS.maxRuntime
|
|
13
|
+
});
|
|
14
|
+
const resolveConfig = (fnLevel, clientLevel) => {
|
|
15
|
+
if (fnLevel === false) return;
|
|
16
|
+
if (fnLevel === true) return DEFAULTS;
|
|
17
|
+
if (Predicate.isNotUndefined(fnLevel)) return normalize(fnLevel);
|
|
18
|
+
if (clientLevel === false) return;
|
|
19
|
+
if (clientLevel === true) return DEFAULTS;
|
|
20
|
+
if (Predicate.isNotUndefined(clientLevel)) return normalize(clientLevel);
|
|
21
|
+
return DEFAULTS;
|
|
22
|
+
};
|
|
23
|
+
const toRegistration = (cfg) => ({
|
|
24
|
+
batch_steps: cfg.bufferedSteps,
|
|
25
|
+
batch_interval: Schema.encodeSync(InngestDuration)(cfg.maxInterval),
|
|
26
|
+
max_runtime: Schema.encodeSync(InngestDuration)(cfg.maxRuntime)
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
export { resolveConfig, toRegistration };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import * as _$effect_Cause0 from "effect/Cause";
|
|
3
|
+
|
|
4
|
+
//#region src/internal/checkpoint/Error.d.ts
|
|
5
|
+
declare const CheckpointApiError_base: Schema.Class<CheckpointApiError, Schema.TaggedStruct<"CheckpointApiError", {
|
|
6
|
+
readonly message: Schema.String;
|
|
7
|
+
readonly status: Schema.optionalKey<Schema.Number>;
|
|
8
|
+
}>, _$effect_Cause0.YieldableError>;
|
|
9
|
+
declare class CheckpointApiError extends CheckpointApiError_base {}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { CheckpointApiError };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region src/internal/checkpoint/Error.ts
|
|
3
|
+
var CheckpointApiError = class extends Schema.TaggedErrorClass()("CheckpointApiError", {
|
|
4
|
+
message: Schema.String,
|
|
5
|
+
status: Schema.optionalKey(Schema.Number)
|
|
6
|
+
}) {};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { CheckpointApiError };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Array, Clock, Duration, Effect, Option, Ref, Result } from "effect";
|
|
2
|
+
//#region src/internal/checkpoint/State.ts
|
|
3
|
+
const make = (args) => Effect.sync(() => {
|
|
4
|
+
const buffer = Ref.makeUnsafe(Array.empty());
|
|
5
|
+
const plannedBuffer = Ref.makeUnsafe(Array.empty());
|
|
6
|
+
const intervalStartedAt = Ref.makeUnsafe(Option.none());
|
|
7
|
+
const runtimeExceeded = Ref.makeUnsafe(false);
|
|
8
|
+
const maxIntervalMs = Duration.toMillis(args.config.maxInterval);
|
|
9
|
+
const flushInner = Effect.gen(function* () {
|
|
10
|
+
const steps = yield* Ref.modify(buffer, (current) => [current, Array.empty()]);
|
|
11
|
+
if (steps.length === 0) return;
|
|
12
|
+
const result = yield* Effect.result(args.checkpointAsync(steps));
|
|
13
|
+
if (Result.isFailure(result)) {
|
|
14
|
+
yield* Ref.update(buffer, (current) => [...steps, ...current]);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
yield* Ref.set(intervalStartedAt, Option.none());
|
|
18
|
+
});
|
|
19
|
+
const record = (op) => Effect.gen(function* () {
|
|
20
|
+
const len = yield* Ref.modify(buffer, (current) => {
|
|
21
|
+
const next = [...current, op];
|
|
22
|
+
return [next.length, next];
|
|
23
|
+
});
|
|
24
|
+
const now = yield* Clock.currentTimeMillis;
|
|
25
|
+
const start = yield* Ref.get(intervalStartedAt);
|
|
26
|
+
if (len >= args.config.bufferedSteps) {
|
|
27
|
+
yield* flushInner;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (Option.isSome(start) && maxIntervalMs > 0 && now - start.value >= maxIntervalMs) {
|
|
31
|
+
yield* flushInner;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (Option.isNone(start) && maxIntervalMs > 0) yield* Ref.set(intervalStartedAt, Option.some(now));
|
|
35
|
+
});
|
|
36
|
+
const takeCompleted = () => Ref.modify(buffer, (current) => [current, Array.empty()]);
|
|
37
|
+
const plan = (planned) => Ref.update(plannedBuffer, (current) => [...current, planned]);
|
|
38
|
+
const takePlanned = () => Ref.modify(plannedBuffer, (current) => [[...current].sort((a, b) => a.sequence - b.sequence).map((entry) => entry.opcode), Array.empty()]);
|
|
39
|
+
return {
|
|
40
|
+
config: args.config,
|
|
41
|
+
runId: args.runId,
|
|
42
|
+
fnId: args.fnId,
|
|
43
|
+
qiId: args.qiId,
|
|
44
|
+
plan,
|
|
45
|
+
takePlanned,
|
|
46
|
+
record,
|
|
47
|
+
flush: flushInner,
|
|
48
|
+
takeCompleted,
|
|
49
|
+
markRuntimeExceeded: Ref.set(runtimeExceeded, true),
|
|
50
|
+
isRuntimeExceeded: Ref.get(runtimeExceeded)
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
//#endregion
|
|
54
|
+
export { make };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FunctionInvoked } from "../../Events.js";
|
|
2
|
+
import { eventSchemaFor, eventSchemas } from "../domain/FunctionDefinition.js";
|
|
3
|
+
import { Array, Effect, Function, Option, Predicate, Schema } from "effect";
|
|
4
|
+
//#region src/internal/codec/EventPayload.ts
|
|
5
|
+
var EventDecodeError = class extends Schema.TaggedErrorClass()("EventDecodeError", {
|
|
6
|
+
eventName: Schema.String,
|
|
7
|
+
cause: Schema.Unknown
|
|
8
|
+
}) {};
|
|
9
|
+
const isFunctionInvoked = Schema.is(FunctionInvoked);
|
|
10
|
+
const envelope = (event) => Schema.Struct({
|
|
11
|
+
name: Schema.tag(event.identifier),
|
|
12
|
+
data: event.schema,
|
|
13
|
+
id: Schema.optional(Schema.String),
|
|
14
|
+
ts: Schema.optional(Schema.Number),
|
|
15
|
+
v: Schema.optional(Schema.String)
|
|
16
|
+
});
|
|
17
|
+
const decodeEnvelope = Function.dual(2, (value, event) => {
|
|
18
|
+
const eventEnvelope = envelope(event);
|
|
19
|
+
return Schema.decodeUnknownEffect(Schema.toCodecJson(eventEnvelope))(value).pipe(Effect.mapError((cause) => EventDecodeError.make({
|
|
20
|
+
eventName: event.identifier,
|
|
21
|
+
cause
|
|
22
|
+
})));
|
|
23
|
+
});
|
|
24
|
+
const decodeMemoData = Function.dual(2, (value, event) => {
|
|
25
|
+
if (Predicate.isObject(value) && Predicate.hasProperty(value, "name")) return decodeEnvelope(event)(value);
|
|
26
|
+
return decodeEnvelope(event)({
|
|
27
|
+
name: event.identifier,
|
|
28
|
+
data: value
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
const decodeTriggerEvent = Function.dual(2, (event, fn) => Option.match(eventSchemaFor({
|
|
32
|
+
fn,
|
|
33
|
+
eventName: event.name
|
|
34
|
+
}), {
|
|
35
|
+
onNone: () => Effect.fail(EventDecodeError.make({
|
|
36
|
+
eventName: event.name,
|
|
37
|
+
cause: "No matching event trigger schema"
|
|
38
|
+
})),
|
|
39
|
+
onSome: (eventSchema) => decodeEnvelope(eventSchema)(event)
|
|
40
|
+
}));
|
|
41
|
+
function decodeInvocation(args) {
|
|
42
|
+
const { fn, input } = args;
|
|
43
|
+
if (Predicate.isNotNullish(fn.options?.batchEvents)) return Effect.forEach(input.events, decodeTriggerEvent(fn));
|
|
44
|
+
if (isFunctionInvoked(input.event)) {
|
|
45
|
+
const { _inngest, ...payload } = input.event.data;
|
|
46
|
+
return Option.match(Array.head(eventSchemas(fn)), {
|
|
47
|
+
onNone: () => Effect.fail(EventDecodeError.make({
|
|
48
|
+
eventName: input.event.name,
|
|
49
|
+
cause: "No event trigger schema for invocation"
|
|
50
|
+
})),
|
|
51
|
+
onSome: (event) => decodeEnvelope(event)({
|
|
52
|
+
name: event.identifier,
|
|
53
|
+
data: payload
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return decodeTriggerEvent(fn)(input.event);
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { decodeInvocation, decodeMemoData };
|