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
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import { Predicate, Struct } from "effect";
|
|
2
|
-
import * as Schema$1 from "effect/Schema";
|
|
3
|
-
|
|
1
|
+
import { Effect, Predicate, Schema, SchemaTransformation, Struct } from "effect";
|
|
4
2
|
//#region src/internal/protocol.ts
|
|
5
|
-
/**
|
|
6
|
-
* Wire protocol schemas and opcode factories for Inngest communication.
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
3
|
const stripTopLevelTag = (value) => {
|
|
10
|
-
if (Predicate.
|
|
4
|
+
if (Predicate.isObject(value)) return Struct.omit(value, ["_tag"]);
|
|
11
5
|
return value;
|
|
12
6
|
};
|
|
13
|
-
const WireUnknown = Schema
|
|
14
|
-
strict: true,
|
|
7
|
+
const WireUnknown = Schema.Unknown.pipe(Schema.decodeTo(Schema.Unknown, SchemaTransformation.transform({
|
|
15
8
|
decode: (value) => value,
|
|
16
9
|
encode: (value) => stripTopLevelTag(value)
|
|
17
|
-
});
|
|
10
|
+
})));
|
|
18
11
|
const Opcode = {
|
|
19
12
|
None: "None",
|
|
20
13
|
Step: "Step",
|
|
@@ -32,64 +25,60 @@ const Opcode = {
|
|
|
32
25
|
SyncRunComplete: "SyncRunComplete",
|
|
33
26
|
DiscoveryRequest: "DiscoveryRequest"
|
|
34
27
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
const RUN_COMPLETE_ID = "0737c22d3bfae812339732d14d8c7dbd6dc4e09c";
|
|
29
|
+
var UserError = class UserError extends Schema.Class("UserError")({
|
|
30
|
+
name: Schema.String,
|
|
31
|
+
message: Schema.String,
|
|
32
|
+
stack: Schema.optional(Schema.String),
|
|
33
|
+
data: Schema.optional(Schema.Unknown),
|
|
34
|
+
noRetry: Schema.optional(Schema.Boolean),
|
|
35
|
+
cause: Schema.optional(Schema.Unknown)
|
|
36
|
+
}) {
|
|
37
|
+
static fromUnknown(error) {
|
|
38
|
+
return UserError.make({
|
|
39
|
+
name: Predicate.hasProperty(error, "name") ? String(error.name) : "Error",
|
|
40
|
+
message: Predicate.hasProperty(error, "message") ? String(error.message) : String(error),
|
|
41
|
+
stack: Predicate.hasProperty(error, "stack") ? String(error.stack) : void 0
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const StepResult = Schema.NullOr(Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.annotate({ identifier: "StepResultObject" })));
|
|
46
|
+
var FunctionStack = class extends Schema.Class("FunctionStack")({
|
|
47
|
+
stack: Schema.Array(Schema.String),
|
|
48
|
+
current: Schema.Number
|
|
50
49
|
}) {};
|
|
51
|
-
var InngestEvent = class extends Schema
|
|
52
|
-
id: Schema
|
|
53
|
-
name: Schema
|
|
54
|
-
data: Schema
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
default: () => ({}),
|
|
59
|
-
nullable: true
|
|
60
|
-
}),
|
|
61
|
-
ts: Schema$1.optional(Schema$1.Number),
|
|
62
|
-
user: Schema$1.optional(Schema$1.Record({
|
|
63
|
-
key: Schema$1.String,
|
|
64
|
-
value: Schema$1.Unknown
|
|
65
|
-
})),
|
|
66
|
-
v: Schema$1.optional(Schema$1.String)
|
|
50
|
+
var InngestEvent = class extends Schema.Class("InngestEvent")({
|
|
51
|
+
id: Schema.optional(Schema.String),
|
|
52
|
+
name: Schema.String,
|
|
53
|
+
data: Schema.NullOr(Schema.Record(Schema.String, Schema.Unknown)).pipe(Schema.withDecodingDefaultType(Effect.succeed({}))),
|
|
54
|
+
ts: Schema.optional(Schema.Number),
|
|
55
|
+
user: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
56
|
+
v: Schema.optional(Schema.String)
|
|
67
57
|
}) {};
|
|
68
|
-
var SDKRequestContext = class extends Schema
|
|
69
|
-
fn_id: Schema
|
|
70
|
-
run_id: Schema
|
|
71
|
-
env: Schema
|
|
72
|
-
step_id: Schema
|
|
73
|
-
attempt: Schema
|
|
74
|
-
max_attempts: Schema
|
|
75
|
-
stack: Schema
|
|
58
|
+
var SDKRequestContext = class extends Schema.Class("SDKRequestContext")({
|
|
59
|
+
fn_id: Schema.String,
|
|
60
|
+
run_id: Schema.String,
|
|
61
|
+
env: Schema.String.pipe(Schema.withDecodingDefault(Effect.succeed("dev"))),
|
|
62
|
+
step_id: Schema.String.pipe(Schema.withDecodingDefault(Effect.succeed("step"))),
|
|
63
|
+
attempt: Schema.Number.pipe(Schema.withDecodingDefault(Effect.succeed(0))),
|
|
64
|
+
max_attempts: Schema.Number.pipe(Schema.withDecodingDefault(Effect.succeed(4))),
|
|
65
|
+
stack: FunctionStack.pipe(Schema.withDecodingDefaultType(Effect.succeed(FunctionStack.make({
|
|
76
66
|
stack: [],
|
|
77
67
|
current: 0
|
|
78
|
-
})
|
|
79
|
-
qi_id: Schema
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
})))),
|
|
69
|
+
qi_id: Schema.String.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
|
|
70
|
+
request_id: Schema.optionalKey(Schema.String),
|
|
71
|
+
generation_id: Schema.optionalKey(Schema.Number),
|
|
72
|
+
disable_immediate_execution: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
|
|
73
|
+
use_api: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false)))
|
|
82
74
|
}) {};
|
|
83
|
-
var SDKRequestBody = class extends Schema
|
|
75
|
+
var SDKRequestBody = class extends Schema.Class("SDKRequestBody")({
|
|
84
76
|
event: InngestEvent,
|
|
85
|
-
events: Schema
|
|
86
|
-
steps: Schema
|
|
87
|
-
key: Schema$1.String,
|
|
88
|
-
value: StepResult
|
|
89
|
-
}), { default: () => ({}) }),
|
|
77
|
+
events: Schema.Array(InngestEvent),
|
|
78
|
+
steps: Schema.Record(Schema.String, StepResult).pipe(Schema.withDecodingDefault(Effect.succeed({}))),
|
|
90
79
|
ctx: SDKRequestContext,
|
|
91
|
-
version: Schema
|
|
92
|
-
use_api: Schema
|
|
80
|
+
version: Schema.Number.pipe(Schema.withDecodingDefault(Effect.succeed(1))),
|
|
81
|
+
use_api: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false)))
|
|
93
82
|
}) {};
|
|
94
83
|
const Headers = {
|
|
95
84
|
SDK: "X-Inngest-SDK",
|
|
@@ -97,6 +86,8 @@ const Headers = {
|
|
|
97
86
|
RequestVersion: "x-inngest-req-version",
|
|
98
87
|
NoRetry: "X-Inngest-No-Retry",
|
|
99
88
|
RetryAfter: "Retry-After",
|
|
89
|
+
SDKHandled: "x-inngest-sdk-handled",
|
|
90
|
+
SyncKind: "x-inngest-sync-kind",
|
|
100
91
|
ServerKind: "X-Inngest-Server-Kind",
|
|
101
92
|
ExpectedServerKind: "X-Inngest-Expected-Server-Kind",
|
|
102
93
|
RunID: "X-Run-ID",
|
|
@@ -104,84 +95,288 @@ const Headers = {
|
|
|
104
95
|
Platform: "X-Inngest-Platform",
|
|
105
96
|
Env: "X-Inngest-Env"
|
|
106
97
|
};
|
|
107
|
-
var GeneratorOpcode = class extends Schema
|
|
108
|
-
op: Schema
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const sleep = (info, duration) => GeneratorOpcode.make({
|
|
137
|
-
op: Opcode.Sleep,
|
|
138
|
-
id: info.hash,
|
|
139
|
-
name: duration,
|
|
140
|
-
displayName: info.name,
|
|
141
|
-
mode: "async"
|
|
142
|
-
});
|
|
143
|
-
const waitForEvent = (info, opts) => mkOpcode(info, Opcode.WaitForEvent, {
|
|
144
|
-
mode: "async",
|
|
145
|
-
opts
|
|
146
|
-
});
|
|
147
|
-
const invokeFunction = (info, opts) => mkOpcode(info, Opcode.InvokeFunction, {
|
|
148
|
-
mode: "async",
|
|
149
|
-
opts,
|
|
150
|
-
userland: { id: info.id }
|
|
151
|
-
});
|
|
152
|
-
const IntrospectionBase = Schema$1.Struct({
|
|
153
|
-
function_count: Schema$1.Number,
|
|
154
|
-
has_event_key: Schema$1.Boolean,
|
|
155
|
-
has_signing_key: Schema$1.Boolean,
|
|
156
|
-
has_signing_key_fallback: Schema$1.Boolean,
|
|
157
|
-
mode: Schema$1.Literal("cloud", "dev"),
|
|
158
|
-
schema_version: Schema$1.Literal("2024-05-24"),
|
|
159
|
-
extra: Schema$1.optional(Schema$1.Record({
|
|
160
|
-
key: Schema$1.String,
|
|
161
|
-
value: Schema$1.Unknown
|
|
98
|
+
var GeneratorOpcode = class GeneratorOpcode extends Schema.Class("GeneratorOpcode")({
|
|
99
|
+
op: Schema.Literals([
|
|
100
|
+
Opcode.None,
|
|
101
|
+
Opcode.Step,
|
|
102
|
+
Opcode.StepRun,
|
|
103
|
+
Opcode.StepError,
|
|
104
|
+
Opcode.StepPlanned,
|
|
105
|
+
Opcode.Sleep,
|
|
106
|
+
Opcode.WaitForEvent,
|
|
107
|
+
Opcode.InvokeFunction,
|
|
108
|
+
Opcode.AIGateway,
|
|
109
|
+
Opcode.Gateway,
|
|
110
|
+
Opcode.WaitForSignal,
|
|
111
|
+
Opcode.RunComplete,
|
|
112
|
+
Opcode.StepFailed,
|
|
113
|
+
Opcode.SyncRunComplete,
|
|
114
|
+
Opcode.DiscoveryRequest
|
|
115
|
+
]),
|
|
116
|
+
id: Schema.String,
|
|
117
|
+
name: Schema.optional(Schema.String),
|
|
118
|
+
mode: Schema.optional(Schema.Literals(["sync", "async"])),
|
|
119
|
+
opts: Schema.optional(WireUnknown),
|
|
120
|
+
data: Schema.optional(WireUnknown),
|
|
121
|
+
error: Schema.optional(UserError),
|
|
122
|
+
displayName: Schema.optional(Schema.String),
|
|
123
|
+
userland: Schema.optional(Schema.Struct({ id: Schema.String })),
|
|
124
|
+
timing: Schema.optional(Schema.Struct({
|
|
125
|
+
a: Schema.Number,
|
|
126
|
+
b: Schema.Number
|
|
162
127
|
}))
|
|
128
|
+
}) {
|
|
129
|
+
static makeStep(args) {
|
|
130
|
+
return GeneratorOpcode.make({
|
|
131
|
+
op: args.op,
|
|
132
|
+
id: args.info.hash,
|
|
133
|
+
name: args.info.id,
|
|
134
|
+
displayName: args.info.name,
|
|
135
|
+
...args.extra
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
static stepPlanned(info) {
|
|
139
|
+
return GeneratorOpcode.makeStep({
|
|
140
|
+
info,
|
|
141
|
+
op: Opcode.StepPlanned,
|
|
142
|
+
extra: {
|
|
143
|
+
opts: {},
|
|
144
|
+
userland: { id: info.id },
|
|
145
|
+
data: null
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
static sendEventStepPlanned(info) {
|
|
150
|
+
return GeneratorOpcode.makeStep({
|
|
151
|
+
info,
|
|
152
|
+
op: Opcode.StepPlanned,
|
|
153
|
+
extra: {
|
|
154
|
+
name: "sendEvent",
|
|
155
|
+
opts: { type: "step.sendEvent" },
|
|
156
|
+
userland: { id: info.id },
|
|
157
|
+
data: null
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
static stepRun(args) {
|
|
162
|
+
return GeneratorOpcode.makeStep({
|
|
163
|
+
info: args.info,
|
|
164
|
+
op: Opcode.StepRun,
|
|
165
|
+
extra: {
|
|
166
|
+
mode: "sync",
|
|
167
|
+
opts: {},
|
|
168
|
+
userland: { id: args.info.id },
|
|
169
|
+
rawArgs: [args.info.rawStepArg ?? args.info.id, null],
|
|
170
|
+
hashedId: args.info.hash,
|
|
171
|
+
fulfilled: true,
|
|
172
|
+
hasStepState: true,
|
|
173
|
+
handled: true,
|
|
174
|
+
promise: {},
|
|
175
|
+
middleware: { stepInfo: {
|
|
176
|
+
hashedId: args.info.hash,
|
|
177
|
+
memoized: false,
|
|
178
|
+
options: {
|
|
179
|
+
id: args.info.id,
|
|
180
|
+
name: args.info.name
|
|
181
|
+
},
|
|
182
|
+
stepType: "run"
|
|
183
|
+
} },
|
|
184
|
+
memoizationDeferred: { promise: {} },
|
|
185
|
+
transformedResultPromise: {},
|
|
186
|
+
...Predicate.isNotUndefined(args.data) ? { data: args.data } : {},
|
|
187
|
+
timing: {
|
|
188
|
+
a: Date.now() * 1e6,
|
|
189
|
+
b: 0
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
static sendEventStepRun(args) {
|
|
195
|
+
return GeneratorOpcode.makeStep({
|
|
196
|
+
info: args.info,
|
|
197
|
+
op: Opcode.StepRun,
|
|
198
|
+
extra: {
|
|
199
|
+
name: "sendEvent",
|
|
200
|
+
mode: "sync",
|
|
201
|
+
userland: { id: args.info.id },
|
|
202
|
+
opts: { type: "step.sendEvent" },
|
|
203
|
+
rawArgs: [args.info.id, args.rawPayload],
|
|
204
|
+
hashedId: args.info.hash,
|
|
205
|
+
promise: {},
|
|
206
|
+
fulfilled: true,
|
|
207
|
+
hasStepState: true,
|
|
208
|
+
handled: true,
|
|
209
|
+
middleware: { stepInfo: {
|
|
210
|
+
hashedId: args.info.hash,
|
|
211
|
+
memoized: false,
|
|
212
|
+
options: {
|
|
213
|
+
id: args.info.id,
|
|
214
|
+
name: args.info.name
|
|
215
|
+
},
|
|
216
|
+
stepType: "sendEvent"
|
|
217
|
+
} },
|
|
218
|
+
memoizationDeferred: { promise: {} },
|
|
219
|
+
transformedResultPromise: {},
|
|
220
|
+
data: args.data,
|
|
221
|
+
timing: {
|
|
222
|
+
a: Date.now() * 1e6,
|
|
223
|
+
b: 0
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
static stepRunResponse(args) {
|
|
229
|
+
return GeneratorOpcode.makeStep({
|
|
230
|
+
info: args.info,
|
|
231
|
+
op: Opcode.StepRun,
|
|
232
|
+
extra: {
|
|
233
|
+
opts: {},
|
|
234
|
+
userland: { id: args.info.id },
|
|
235
|
+
...Predicate.isNotUndefined(args.data) ? { data: args.data } : {},
|
|
236
|
+
timing: {
|
|
237
|
+
a: Date.now() * 1e6,
|
|
238
|
+
b: 0
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
static sendEventStepRunResponse(args) {
|
|
244
|
+
return GeneratorOpcode.makeStep({
|
|
245
|
+
info: args.info,
|
|
246
|
+
op: Opcode.StepRun,
|
|
247
|
+
extra: {
|
|
248
|
+
name: "sendEvent",
|
|
249
|
+
opts: { type: "step.sendEvent" },
|
|
250
|
+
userland: { id: args.info.id },
|
|
251
|
+
data: args.data,
|
|
252
|
+
timing: {
|
|
253
|
+
a: Date.now() * 1e6,
|
|
254
|
+
b: 0
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
static stepError(args) {
|
|
260
|
+
const error = Predicate.isNotUndefined(args.noRetry) ? UserError.make({
|
|
261
|
+
name: args.error.name,
|
|
262
|
+
message: args.error.message,
|
|
263
|
+
stack: args.error.stack,
|
|
264
|
+
noRetry: args.noRetry
|
|
265
|
+
}) : args.error;
|
|
266
|
+
return GeneratorOpcode.makeStep({
|
|
267
|
+
info: args.info,
|
|
268
|
+
op: Opcode.StepError,
|
|
269
|
+
extra: { error }
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
static stepFailed(args) {
|
|
273
|
+
return GeneratorOpcode.makeStep({
|
|
274
|
+
info: args.info,
|
|
275
|
+
op: Opcode.StepFailed,
|
|
276
|
+
extra: {
|
|
277
|
+
opts: {},
|
|
278
|
+
userland: { id: args.info.id },
|
|
279
|
+
error: args.error,
|
|
280
|
+
data: {
|
|
281
|
+
__serialized: true,
|
|
282
|
+
name: args.error.name,
|
|
283
|
+
message: args.error.message,
|
|
284
|
+
stack: ""
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
static sleep(args) {
|
|
290
|
+
return GeneratorOpcode.make({
|
|
291
|
+
op: Opcode.Sleep,
|
|
292
|
+
id: args.info.hash,
|
|
293
|
+
name: args.duration,
|
|
294
|
+
displayName: args.info.name,
|
|
295
|
+
opts: {},
|
|
296
|
+
userland: { id: args.info.id },
|
|
297
|
+
data: null
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
static waitForEvent(args) {
|
|
301
|
+
return GeneratorOpcode.make({
|
|
302
|
+
op: Opcode.WaitForEvent,
|
|
303
|
+
id: args.info.hash,
|
|
304
|
+
name: args.event,
|
|
305
|
+
displayName: args.info.name,
|
|
306
|
+
opts: {
|
|
307
|
+
timeout: args.timeout,
|
|
308
|
+
...Predicate.isNotUndefined(args.if) ? { if: args.if } : {}
|
|
309
|
+
},
|
|
310
|
+
userland: { id: args.info.id },
|
|
311
|
+
data: null
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
static invokeFunction(args) {
|
|
315
|
+
return GeneratorOpcode.make({
|
|
316
|
+
op: Opcode.InvokeFunction,
|
|
317
|
+
id: args.info.hash,
|
|
318
|
+
displayName: args.info.name,
|
|
319
|
+
opts: {
|
|
320
|
+
payload: args.payload,
|
|
321
|
+
function_id: args.functionId,
|
|
322
|
+
...Predicate.isNotUndefined(args.timeout) ? { timeout: args.timeout } : {}
|
|
323
|
+
},
|
|
324
|
+
userland: { id: args.info.id },
|
|
325
|
+
data: null
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
static runComplete(data) {
|
|
329
|
+
return GeneratorOpcode.make({
|
|
330
|
+
op: Opcode.RunComplete,
|
|
331
|
+
id: RUN_COMPLETE_ID,
|
|
332
|
+
data
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
static discoveryRequest() {
|
|
336
|
+
return GeneratorOpcode.make({
|
|
337
|
+
op: Opcode.DiscoveryRequest,
|
|
338
|
+
id: "step",
|
|
339
|
+
name: "step"
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const IntrospectionBase = Schema.Struct({
|
|
344
|
+
function_count: Schema.Number,
|
|
345
|
+
has_event_key: Schema.Boolean,
|
|
346
|
+
has_signing_key: Schema.Boolean,
|
|
347
|
+
has_signing_key_fallback: Schema.optional(Schema.Boolean),
|
|
348
|
+
mode: Schema.Literals(["cloud", "dev"]),
|
|
349
|
+
schema_version: Schema.Literal("2024-05-24"),
|
|
350
|
+
extra: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
163
351
|
});
|
|
164
|
-
const IntrospectionUnauthenticated =
|
|
165
|
-
authentication_succeeded: Schema
|
|
166
|
-
|
|
352
|
+
const IntrospectionUnauthenticated = IntrospectionBase.pipe(Schema.fieldsAssign({
|
|
353
|
+
authentication_succeeded: Schema.optional(Schema.Union([Schema.Literal(false), Schema.Null])),
|
|
354
|
+
capabilities: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
355
|
+
functions: Schema.optionalKey(Schema.Array(Schema.Unknown))
|
|
167
356
|
}));
|
|
168
|
-
const IntrospectionAuthenticated =
|
|
169
|
-
authentication_succeeded: Schema
|
|
170
|
-
api_origin: Schema
|
|
171
|
-
app_id: Schema
|
|
172
|
-
env: Schema
|
|
173
|
-
event_api_origin: Schema
|
|
174
|
-
event_key_hash: Schema
|
|
175
|
-
framework: Schema
|
|
176
|
-
sdk_language: Schema
|
|
177
|
-
sdk_version: Schema
|
|
178
|
-
serve_origin: Schema
|
|
179
|
-
serve_path: Schema
|
|
180
|
-
signing_key_fallback_hash: Schema
|
|
181
|
-
signing_key_hash: Schema
|
|
357
|
+
const IntrospectionAuthenticated = IntrospectionBase.pipe(Schema.fieldsAssign({
|
|
358
|
+
authentication_succeeded: Schema.Literal(true),
|
|
359
|
+
api_origin: Schema.String,
|
|
360
|
+
app_id: Schema.String,
|
|
361
|
+
env: Schema.NullOr(Schema.String),
|
|
362
|
+
event_api_origin: Schema.String,
|
|
363
|
+
event_key_hash: Schema.NullOr(Schema.String),
|
|
364
|
+
framework: Schema.String,
|
|
365
|
+
sdk_language: Schema.String,
|
|
366
|
+
sdk_version: Schema.String,
|
|
367
|
+
serve_origin: Schema.NullOr(Schema.String),
|
|
368
|
+
serve_path: Schema.NullOr(Schema.String),
|
|
369
|
+
signing_key_fallback_hash: Schema.NullOr(Schema.String),
|
|
370
|
+
signing_key_hash: Schema.NullOr(Schema.String)
|
|
182
371
|
}));
|
|
183
|
-
const IntrospectionResponse = Schema
|
|
184
|
-
const RegisterResponse = Schema
|
|
185
|
-
|
|
372
|
+
const IntrospectionResponse = Schema.Union([IntrospectionAuthenticated, IntrospectionUnauthenticated]);
|
|
373
|
+
const RegisterResponse = Schema.Struct({
|
|
374
|
+
message: Schema.String,
|
|
375
|
+
modified: Schema.Boolean
|
|
376
|
+
});
|
|
377
|
+
const RegisterServerResponse = Schema.Union([Schema.Struct({
|
|
378
|
+
ok: Schema.Literal(true),
|
|
379
|
+
modified: Schema.optional(Schema.Boolean)
|
|
380
|
+
}), Schema.Struct({ error: Schema.optional(Schema.String) })]);
|
|
186
381
|
//#endregion
|
|
187
|
-
export { GeneratorOpcode, Headers, IntrospectionResponse,
|
|
382
|
+
export { GeneratorOpcode, Headers, IntrospectionResponse, RegisterResponse, RegisterServerResponse, SDKRequestBody, SDKRequestContext, UserError };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Context, Option } from "effect";
|
|
2
|
+
//#region src/internal/runtime/CheckpointContext.ts
|
|
3
|
+
const CurrentCheckpoint = Context.Reference("effect-inngest/internal/runtime/CurrentCheckpoint", { defaultValue: Option.none });
|
|
4
|
+
//#endregion
|
|
5
|
+
export { CurrentCheckpoint };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InngestFunction } from "../../Function.js";
|
|
2
|
+
import { ExecutionInput } from "../domain/ExecutionInput.js";
|
|
3
|
+
import { StepTools } from "./StepTools.js";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
|
|
6
|
+
//#region src/internal/runtime/HandlerContext.d.ts
|
|
7
|
+
interface HandlerContext<F extends InngestFunction.Any = InngestFunction.Any> {
|
|
8
|
+
readonly event: InngestFunction.EventType<F>;
|
|
9
|
+
readonly step: StepTools.Service;
|
|
10
|
+
readonly run: ExecutionInput["run"];
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { HandlerContext };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CurrentExecutionInput } from "../domain/ExecutionInput.js";
|
|
2
|
+
import { decodeInvocation } from "../codec/EventPayload.js";
|
|
3
|
+
import { StepTools } from "./StepTools.js";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
//#region src/internal/runtime/HandlerContext.ts
|
|
6
|
+
const make = (args) => Effect.gen(function* () {
|
|
7
|
+
const input = yield* CurrentExecutionInput;
|
|
8
|
+
const step = yield* StepTools;
|
|
9
|
+
return {
|
|
10
|
+
event: yield* decodeInvocation({
|
|
11
|
+
fn: args.fn,
|
|
12
|
+
input
|
|
13
|
+
}),
|
|
14
|
+
step,
|
|
15
|
+
run: input.run
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
//#endregion
|
|
19
|
+
export { make };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context, Effect } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/runtime/HandlerFiberScope.d.ts
|
|
4
|
+
interface Service {
|
|
5
|
+
readonly isForkedFromHandlerRoot: Effect.Effect<boolean>;
|
|
6
|
+
}
|
|
7
|
+
declare const HandlerFiberScope_base: Context.ServiceClass<HandlerFiberScope, "effect-inngest/internal/runtime/HandlerFiberScope", Service>;
|
|
8
|
+
declare class HandlerFiberScope extends HandlerFiberScope_base {}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { HandlerFiberScope };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ErrorCommand, PlanCommand, ResultCommand, YieldCommand } from "../domain/StepCommand.js";
|
|
2
|
+
import { CurrentExecutionInput } from "../domain/ExecutionInput.js";
|
|
3
|
+
import { HandlerFiberScope } from "./HandlerFiberScope.js";
|
|
4
|
+
import { ExecutionSuspension, GeneratorOpcode } from "../domain/ExecutionSuspension.js";
|
|
5
|
+
import { Context, Effect, Layer } from "effect";
|
|
6
|
+
|
|
7
|
+
//#region src/internal/runtime/StepCommandBus.d.ts
|
|
8
|
+
declare namespace StepCommandBus {
|
|
9
|
+
interface Service {
|
|
10
|
+
readonly suspend: (command: YieldCommand) => Effect.Effect<void>;
|
|
11
|
+
readonly complete: (command: ResultCommand) => Effect.Effect<void>;
|
|
12
|
+
readonly plan: (command: PlanCommand) => Effect.Effect<void>;
|
|
13
|
+
readonly planCheckpointedFork: (command: PlanCommand) => Effect.Effect<boolean, never, CurrentExecutionInput | HandlerFiberScope>;
|
|
14
|
+
readonly planCheckpointedRunBoundary: (command: PlanCommand) => Effect.Effect<boolean, never, CurrentExecutionInput | HandlerFiberScope>;
|
|
15
|
+
readonly fail: (command: ErrorCommand) => Effect.Effect<void>;
|
|
16
|
+
readonly takePlanned: () => Effect.Effect<ReadonlyArray<GeneratorOpcode>>;
|
|
17
|
+
readonly takeCompleted: () => Effect.Effect<ReadonlyArray<GeneratorOpcode>>;
|
|
18
|
+
readonly takeSuspension: () => Effect.Effect<ExecutionSuspension>;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
declare const StepCommandBus_base: Context.ServiceClass<StepCommandBus, "effect-inngest/internal/runtime/StepCommandBus", StepCommandBus.Service>;
|
|
22
|
+
declare class StepCommandBus extends StepCommandBus_base {
|
|
23
|
+
static readonly make: Effect.Effect<StepCommandBus.Service, never, never>;
|
|
24
|
+
static readonly layer: Layer.Layer<StepCommandBus, never, never>;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { StepCommandBus };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CurrentExecutionInput } from "../domain/ExecutionInput.js";
|
|
2
|
+
import { CurrentCheckpoint } from "./CheckpointContext.js";
|
|
3
|
+
import { HandlerFiberScope } from "./HandlerFiberScope.js";
|
|
4
|
+
import { ExecutionSuspension, SuspendedCommand } from "../domain/ExecutionSuspension.js";
|
|
5
|
+
import { checkpoint, completion, failure, plan } from "../domain/StepCommand.js";
|
|
6
|
+
import { Array, Context, Effect, Layer, Option, Ref } from "effect";
|
|
7
|
+
//#region src/internal/runtime/StepCommandBus.ts
|
|
8
|
+
const plannedFromCheckpoint = CurrentCheckpoint.pipe(Effect.flatMap(Option.match({
|
|
9
|
+
onNone: () => Effect.succeed(Array.empty()),
|
|
10
|
+
onSome: (state) => state.takePlanned()
|
|
11
|
+
})));
|
|
12
|
+
const completedFromCheckpoint = CurrentCheckpoint.pipe(Effect.flatMap(Option.match({
|
|
13
|
+
onNone: () => Effect.succeed(Array.empty()),
|
|
14
|
+
onSome: (state) => state.takeCompleted()
|
|
15
|
+
})));
|
|
16
|
+
var StepCommandBus = class StepCommandBus extends Context.Service()("effect-inngest/internal/runtime/StepCommandBus") {
|
|
17
|
+
static make = Effect.gen(function* () {
|
|
18
|
+
const suspended = yield* Ref.make(Array.empty());
|
|
19
|
+
const suspendExecution = (command) => Ref.update(suspended, Array.append(command)).pipe(Effect.andThen(Effect.interrupt));
|
|
20
|
+
const takeSuspended = Ref.modify(suspended, (current) => [current, Array.empty()]);
|
|
21
|
+
const takeSuspension = () => Effect.gen(function* () {
|
|
22
|
+
const completed = yield* completedFromCheckpoint;
|
|
23
|
+
const commands = yield* takeSuspended;
|
|
24
|
+
return ExecutionSuspension.from({
|
|
25
|
+
completed,
|
|
26
|
+
suspended: commands
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
const plan$1 = (command) => Effect.gen(function* () {
|
|
30
|
+
const checkpoint = yield* CurrentCheckpoint;
|
|
31
|
+
const planned = plan(command);
|
|
32
|
+
if (Option.isNone(checkpoint)) return yield* suspendExecution(SuspendedCommand.fromPlanned(planned));
|
|
33
|
+
return yield* checkpoint.value.plan(planned);
|
|
34
|
+
});
|
|
35
|
+
const planCheckpointedFork = (command) => Effect.gen(function* () {
|
|
36
|
+
const input = yield* CurrentExecutionInput;
|
|
37
|
+
const checkpoint = yield* CurrentCheckpoint;
|
|
38
|
+
const isForkedFromHandlerRoot = yield* (yield* HandlerFiberScope).isForkedFromHandlerRoot;
|
|
39
|
+
if (!input.isFunctionRun() || Option.isNone(checkpoint) || !isForkedFromHandlerRoot) return false;
|
|
40
|
+
yield* plan$1(command);
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
const planCheckpointedRunBoundary = (command) => Effect.gen(function* () {
|
|
44
|
+
const input = yield* CurrentExecutionInput;
|
|
45
|
+
const checkpoint = yield* CurrentCheckpoint;
|
|
46
|
+
if (input.isFunctionRun() && Option.isSome(checkpoint) && (yield* checkpoint.value.isRuntimeExceeded)) {
|
|
47
|
+
yield* checkpoint.value.flush;
|
|
48
|
+
yield* plan$1(command);
|
|
49
|
+
return yield* Effect.interrupt;
|
|
50
|
+
}
|
|
51
|
+
return yield* planCheckpointedFork(command);
|
|
52
|
+
});
|
|
53
|
+
return StepCommandBus.of({
|
|
54
|
+
suspend: (command) => Effect.gen(function* () {
|
|
55
|
+
const checkpoint = yield* CurrentCheckpoint;
|
|
56
|
+
if (Option.isSome(checkpoint)) yield* checkpoint.value.flush;
|
|
57
|
+
return yield* suspendExecution(SuspendedCommand.fromPlanned(plan(command)));
|
|
58
|
+
}),
|
|
59
|
+
complete: (command) => Effect.gen(function* () {
|
|
60
|
+
const checkpoint$1 = yield* CurrentCheckpoint;
|
|
61
|
+
if (Option.isNone(checkpoint$1)) return yield* suspendExecution(SuspendedCommand.fromOpcode(completion(command)));
|
|
62
|
+
return yield* checkpoint$1.value.record(checkpoint(command));
|
|
63
|
+
}),
|
|
64
|
+
plan: plan$1,
|
|
65
|
+
planCheckpointedFork,
|
|
66
|
+
planCheckpointedRunBoundary,
|
|
67
|
+
fail: (command) => suspendExecution(SuspendedCommand.fromFailure(failure(command))),
|
|
68
|
+
takePlanned: () => plannedFromCheckpoint,
|
|
69
|
+
takeCompleted: () => completedFromCheckpoint,
|
|
70
|
+
takeSuspension
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
static layer = Layer.effect(this, this.make);
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
export { StepCommandBus };
|