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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { StepError } from "../errors.js";
|
|
2
|
+
import { Effect, Function, Option, Predicate, Schema } from "effect";
|
|
3
|
+
//#region src/internal/codec/StepResult.ts
|
|
4
|
+
const messageFromCause = (cause) => {
|
|
5
|
+
if (Predicate.hasProperty(cause, "cause")) {
|
|
6
|
+
const nested = messageFromCause(cause.cause);
|
|
7
|
+
if (nested.length > 0) return nested;
|
|
8
|
+
}
|
|
9
|
+
const message = Predicate.hasProperty(cause, "message") ? String(cause.message) : "";
|
|
10
|
+
if (message.length > 0) return message;
|
|
11
|
+
const rendered = String(cause);
|
|
12
|
+
return rendered.length > 0 ? rendered : "Step result schema decode failed";
|
|
13
|
+
};
|
|
14
|
+
const memoDecodeError = (args) => StepError.make({
|
|
15
|
+
stepId: args.stepId,
|
|
16
|
+
message: messageFromCause(args.cause),
|
|
17
|
+
noRetry: true,
|
|
18
|
+
cause: args.cause
|
|
19
|
+
});
|
|
20
|
+
const failMemoDecode = (stepId, cause) => Effect.fail(memoDecodeError({
|
|
21
|
+
stepId,
|
|
22
|
+
cause
|
|
23
|
+
}));
|
|
24
|
+
const mapMemoDecodeError = Function.dual(2, (effect, stepId) => effect.pipe(Effect.mapError((cause) => memoDecodeError({
|
|
25
|
+
stepId,
|
|
26
|
+
cause
|
|
27
|
+
}))));
|
|
28
|
+
const decodeMemo = Function.dual(3, (value, schema, stepId) => Schema.decodeUnknownEffect(schema)(value).pipe(mapMemoDecodeError(stepId)));
|
|
29
|
+
const encodeMemo = Function.dual(3, (value, schema, stepId) => Schema.encodeUnknownEffect(Schema.toCodecJson(schema))(value).pipe(mapMemoDecodeError(stepId)));
|
|
30
|
+
const decodeStepRunMemo = (schema, stepId) => (value) => Option.match(schema, {
|
|
31
|
+
onNone: () => Effect.void,
|
|
32
|
+
onSome: (codec) => decodeMemo(codec, stepId)(value)
|
|
33
|
+
});
|
|
34
|
+
const encodeStepRunMemo = (schema, stepId) => (value) => Option.match(schema, {
|
|
35
|
+
onNone: () => Predicate.isUndefined(value) ? Effect.succeed(void 0) : decodeMemo(Schema.Json, stepId)(value),
|
|
36
|
+
onSome: (codec) => encodeMemo(codec, stepId)(value)
|
|
37
|
+
});
|
|
38
|
+
const failStepRunMemoError = (stepId, error) => Effect.fail(StepError.make({
|
|
39
|
+
stepId,
|
|
40
|
+
message: Predicate.hasProperty(error, "message") ? String(error.message) : "Step failed",
|
|
41
|
+
noRetry: true,
|
|
42
|
+
cause: error
|
|
43
|
+
}));
|
|
44
|
+
const failStepRunMemoTimeout = (stepId) => Effect.fail(StepError.make({
|
|
45
|
+
stepId,
|
|
46
|
+
message: "Step timed out",
|
|
47
|
+
noRetry: true
|
|
48
|
+
}));
|
|
49
|
+
const failUnexpectedStepRunMemoInput = (stepId, input) => Effect.fail(StepError.make({
|
|
50
|
+
stepId,
|
|
51
|
+
message: "Unexpected step result type: input",
|
|
52
|
+
cause: input
|
|
53
|
+
}));
|
|
54
|
+
//#endregion
|
|
55
|
+
export { decodeMemo, decodeStepRunMemo, encodeStepRunMemo, failMemoDecode, failStepRunMemoError, failStepRunMemoTimeout, failUnexpectedStepRunMemoInput, mapMemoDecodeError };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { StepInfo } from "./StepInfo.js";
|
|
2
|
+
import { SDKRequestBody } from "../protocol.js";
|
|
3
|
+
import { Memo } from "./Memo.js";
|
|
4
|
+
import { Context, Schema } from "effect";
|
|
5
|
+
|
|
6
|
+
//#region src/internal/domain/ExecutionInput.d.ts
|
|
7
|
+
declare const ExecutionEvent_base: Schema.Class<ExecutionEvent, Schema.Struct<{
|
|
8
|
+
readonly id: Schema.optional<Schema.String>;
|
|
9
|
+
readonly name: Schema.String;
|
|
10
|
+
readonly data: Schema.NullOr<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
11
|
+
readonly ts: Schema.optional<Schema.Number>;
|
|
12
|
+
readonly user: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
13
|
+
readonly v: Schema.optional<Schema.String>;
|
|
14
|
+
}>, {}>;
|
|
15
|
+
declare class ExecutionEvent extends ExecutionEvent_base {}
|
|
16
|
+
declare const RunContext_base: Schema.Class<RunContext, Schema.Struct<{
|
|
17
|
+
readonly id: Schema.String;
|
|
18
|
+
readonly attempt: Schema.Number;
|
|
19
|
+
readonly maxAttempts: Schema.Number;
|
|
20
|
+
}>, {}>;
|
|
21
|
+
declare class RunContext extends RunContext_base {}
|
|
22
|
+
declare const ExecutionInput_base: Schema.Class<ExecutionInput, Schema.Struct<{
|
|
23
|
+
readonly event: typeof ExecutionEvent;
|
|
24
|
+
readonly events: Schema.$Array<typeof ExecutionEvent>;
|
|
25
|
+
readonly steps: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
26
|
+
readonly run: typeof RunContext;
|
|
27
|
+
readonly requestedStepHash: Schema.Option<Schema.String>;
|
|
28
|
+
readonly disableImmediateExecution: Schema.Boolean;
|
|
29
|
+
}>, {}>;
|
|
30
|
+
declare class ExecutionInput extends ExecutionInput_base {
|
|
31
|
+
static fromSdkRequestBody(request: SDKRequestBody): ExecutionInput;
|
|
32
|
+
memoForStep(info: StepInfo): Memo;
|
|
33
|
+
shouldExecuteStep(info: StepInfo): boolean;
|
|
34
|
+
shouldPlanStep(info: StepInfo): boolean;
|
|
35
|
+
isFunctionRun(): boolean;
|
|
36
|
+
}
|
|
37
|
+
declare const CurrentExecutionInput_base: Context.ServiceClass<CurrentExecutionInput, "effect-inngest/internal/domain/CurrentExecutionInput", ExecutionInput>;
|
|
38
|
+
declare class CurrentExecutionInput extends CurrentExecutionInput_base {}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { CurrentExecutionInput, ExecutionInput };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { decode } from "./Memo.js";
|
|
2
|
+
import { Context, Equal, Option, Schema } from "effect";
|
|
3
|
+
//#region src/internal/domain/ExecutionInput.ts
|
|
4
|
+
var ExecutionEvent = class extends Schema.Class("effect-inngest/internal/domain/ExecutionEvent")({
|
|
5
|
+
id: Schema.optional(Schema.String),
|
|
6
|
+
name: Schema.String,
|
|
7
|
+
data: Schema.NullOr(Schema.Record(Schema.String, Schema.Unknown)),
|
|
8
|
+
ts: Schema.optional(Schema.Number),
|
|
9
|
+
user: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
10
|
+
v: Schema.optional(Schema.String)
|
|
11
|
+
}) {};
|
|
12
|
+
var RunContext = class extends Schema.Class("effect-inngest/internal/domain/RunContext")({
|
|
13
|
+
id: Schema.String,
|
|
14
|
+
attempt: Schema.Number,
|
|
15
|
+
maxAttempts: Schema.Number
|
|
16
|
+
}) {};
|
|
17
|
+
var ExecutionInput = class ExecutionInput extends Schema.Class("effect-inngest/internal/domain/ExecutionInput")({
|
|
18
|
+
event: ExecutionEvent,
|
|
19
|
+
events: Schema.Array(ExecutionEvent),
|
|
20
|
+
steps: Schema.Record(Schema.String, Schema.Unknown),
|
|
21
|
+
run: RunContext,
|
|
22
|
+
requestedStepHash: Schema.Option(Schema.String),
|
|
23
|
+
disableImmediateExecution: Schema.Boolean
|
|
24
|
+
}) {
|
|
25
|
+
static fromSdkRequestBody(request) {
|
|
26
|
+
return ExecutionInput.make({
|
|
27
|
+
event: ExecutionEvent.make(request.event),
|
|
28
|
+
events: request.events.map((event) => ExecutionEvent.make(event)),
|
|
29
|
+
steps: request.steps,
|
|
30
|
+
run: RunContext.make({
|
|
31
|
+
id: request.ctx.run_id,
|
|
32
|
+
attempt: request.ctx.attempt,
|
|
33
|
+
maxAttempts: request.ctx.max_attempts
|
|
34
|
+
}),
|
|
35
|
+
requestedStepHash: request.ctx.step_id === "step" ? Option.none() : Option.some(request.ctx.step_id),
|
|
36
|
+
disableImmediateExecution: request.ctx.disable_immediate_execution
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
memoForStep(info) {
|
|
40
|
+
return decode(this.steps[info.hash]);
|
|
41
|
+
}
|
|
42
|
+
shouldExecuteStep(info) {
|
|
43
|
+
return Option.match(this.requestedStepHash, {
|
|
44
|
+
onNone: () => true,
|
|
45
|
+
onSome: Equal.equals(info.hash)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
shouldPlanStep(info) {
|
|
49
|
+
return this.shouldExecuteStep(info) && this.isFunctionRun() && this.disableImmediateExecution;
|
|
50
|
+
}
|
|
51
|
+
isFunctionRun() {
|
|
52
|
+
return Option.isNone(this.requestedStepHash);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var CurrentExecutionInput = class extends Context.Service()("effect-inngest/internal/domain/CurrentExecutionInput") {};
|
|
56
|
+
//#endregion
|
|
57
|
+
export { CurrentExecutionInput, ExecutionInput };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { GeneratorOpcode as GeneratorOpcode$1 } from "../protocol.js";
|
|
2
|
+
import { Failure, PlannedOpcode } from "./StepCommand.js";
|
|
3
|
+
import { Option, Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
//#region src/internal/domain/ExecutionSuspension.d.ts
|
|
6
|
+
type GeneratorOpcode = typeof GeneratorOpcode$1.Type;
|
|
7
|
+
declare const SuspendedCommand_base: Schema.Class<SuspendedCommand, Schema.Struct<{
|
|
8
|
+
readonly opcode: typeof GeneratorOpcode$1;
|
|
9
|
+
readonly sequence: Schema.Option<Schema.Number>;
|
|
10
|
+
readonly retryAfterMs: Schema.Option<Schema.Number>;
|
|
11
|
+
readonly isFailure: Schema.Boolean;
|
|
12
|
+
readonly noRetry: Schema.Boolean;
|
|
13
|
+
}>, {}>;
|
|
14
|
+
declare class SuspendedCommand extends SuspendedCommand_base {
|
|
15
|
+
static fromPlanned(planned: PlannedOpcode): SuspendedCommand;
|
|
16
|
+
static fromOpcode(opcode: GeneratorOpcode, retryAfterMs?: Option.Option<number>): SuspendedCommand;
|
|
17
|
+
static fromFailure(failure: Failure): SuspendedCommand;
|
|
18
|
+
}
|
|
19
|
+
declare const ExecutionSuspension_base: Schema.Class<ExecutionSuspension, Schema.Struct<{
|
|
20
|
+
readonly completed: Schema.$Array<typeof GeneratorOpcode$1>;
|
|
21
|
+
readonly opcodes: Schema.$Array<typeof GeneratorOpcode$1>;
|
|
22
|
+
readonly suspendedCount: Schema.Number;
|
|
23
|
+
readonly retryAfterMs: Schema.Option<Schema.Number>;
|
|
24
|
+
readonly hasFailure: Schema.Boolean;
|
|
25
|
+
readonly noRetry: Schema.Boolean;
|
|
26
|
+
}>, {}>;
|
|
27
|
+
declare class ExecutionSuspension extends ExecutionSuspension_base {
|
|
28
|
+
static from(args: {
|
|
29
|
+
readonly completed: ReadonlyArray<GeneratorOpcode>;
|
|
30
|
+
readonly suspended: ReadonlyArray<SuspendedCommand>;
|
|
31
|
+
}): ExecutionSuspension;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { ExecutionSuspension, GeneratorOpcode };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { GeneratorOpcode } from "../protocol.js";
|
|
2
|
+
import { Array, Option, Schema } from "effect";
|
|
3
|
+
//#region src/internal/domain/ExecutionSuspension.ts
|
|
4
|
+
var SuspendedCommand = class SuspendedCommand extends Schema.Class("effect-inngest/internal/domain/SuspendedCommand")({
|
|
5
|
+
opcode: GeneratorOpcode,
|
|
6
|
+
sequence: Schema.Option(Schema.Number),
|
|
7
|
+
retryAfterMs: Schema.Option(Schema.Number),
|
|
8
|
+
isFailure: Schema.Boolean,
|
|
9
|
+
noRetry: Schema.Boolean
|
|
10
|
+
}) {
|
|
11
|
+
static fromPlanned(planned) {
|
|
12
|
+
return SuspendedCommand.make({
|
|
13
|
+
opcode: planned.opcode,
|
|
14
|
+
sequence: Option.some(planned.sequence),
|
|
15
|
+
retryAfterMs: Option.none(),
|
|
16
|
+
isFailure: false,
|
|
17
|
+
noRetry: false
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
static fromOpcode(opcode, retryAfterMs = Option.none()) {
|
|
21
|
+
return SuspendedCommand.make({
|
|
22
|
+
opcode,
|
|
23
|
+
sequence: Option.none(),
|
|
24
|
+
retryAfterMs,
|
|
25
|
+
isFailure: false,
|
|
26
|
+
noRetry: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
static fromFailure(failure) {
|
|
30
|
+
return SuspendedCommand.make({
|
|
31
|
+
opcode: failure.opcode,
|
|
32
|
+
sequence: Option.none(),
|
|
33
|
+
retryAfterMs: failure.retryAfterMs,
|
|
34
|
+
isFailure: true,
|
|
35
|
+
noRetry: failure.noRetry
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var ExecutionSuspension = class ExecutionSuspension extends Schema.Class("effect-inngest/internal/domain/ExecutionSuspension")({
|
|
40
|
+
completed: Schema.Array(GeneratorOpcode),
|
|
41
|
+
opcodes: Schema.Array(GeneratorOpcode),
|
|
42
|
+
suspendedCount: Schema.Number,
|
|
43
|
+
retryAfterMs: Schema.Option(Schema.Number),
|
|
44
|
+
hasFailure: Schema.Boolean,
|
|
45
|
+
noRetry: Schema.Boolean
|
|
46
|
+
}) {
|
|
47
|
+
static from(args) {
|
|
48
|
+
const suspended = args.suspended.toSorted((a, b) => {
|
|
49
|
+
if (Option.isNone(a.sequence) || Option.isNone(b.sequence)) return 0;
|
|
50
|
+
return a.sequence.value - b.sequence.value;
|
|
51
|
+
});
|
|
52
|
+
const opcodes = [...args.completed, ...suspended.map((entry) => entry.opcode)];
|
|
53
|
+
return ExecutionSuspension.make({
|
|
54
|
+
completed: [...args.completed],
|
|
55
|
+
opcodes,
|
|
56
|
+
suspendedCount: args.suspended.length,
|
|
57
|
+
retryAfterMs: Array.findFirst(suspended, (entry) => Option.isSome(entry.retryAfterMs)).pipe(Option.flatMap((entry) => entry.retryAfterMs)),
|
|
58
|
+
hasFailure: suspended.some((entry) => entry.isFailure),
|
|
59
|
+
noRetry: suspended.some((entry) => entry.noRetry)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ExecutionSuspension, SuspendedCommand };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Array, Option, Predicate, Schema } from "effect";
|
|
2
|
+
//#region src/internal/domain/FunctionDefinition.ts
|
|
3
|
+
const EventSchemaShape = Schema.declare((value) => Schema.isSchema(value) && Predicate.hasProperty(value, "identifier") && Predicate.isString(value.identifier));
|
|
4
|
+
const EventTriggerShape = Schema.Struct({ event: EventSchemaShape });
|
|
5
|
+
const isEventTriggerShape = Schema.is(EventTriggerShape);
|
|
6
|
+
const isEventTrigger = (trigger) => isEventTriggerShape(trigger);
|
|
7
|
+
const eventSchemas = (fn) => Array.map(Array.filter(fn.triggers, isEventTrigger), (trigger) => trigger.event);
|
|
8
|
+
const eventSchemaFor = (args) => {
|
|
9
|
+
const events = eventSchemas(args.fn);
|
|
10
|
+
return Option.fromNullishOr(events.find((event) => event.identifier === args.eventName));
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { eventSchemaFor, eventSchemas };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/domain/Memo.d.ts
|
|
4
|
+
declare const MemoData_base: Schema.Class<MemoData, Schema.TaggedStruct<"MemoData", {
|
|
5
|
+
readonly data: Schema.Unknown;
|
|
6
|
+
}>, {}>;
|
|
7
|
+
declare class MemoData extends MemoData_base {}
|
|
8
|
+
declare const MemoError_base: Schema.Class<MemoError, Schema.TaggedStruct<"MemoError", {
|
|
9
|
+
readonly error: Schema.Unknown;
|
|
10
|
+
}>, {}>;
|
|
11
|
+
declare class MemoError extends MemoError_base {}
|
|
12
|
+
declare const MemoInput_base: Schema.Class<MemoInput, Schema.TaggedStruct<"MemoInput", {
|
|
13
|
+
readonly input: Schema.Unknown;
|
|
14
|
+
}>, {}>;
|
|
15
|
+
declare class MemoInput extends MemoInput_base {}
|
|
16
|
+
declare const MemoTimeout_base: Schema.Class<MemoTimeout, Schema.TaggedStruct<"MemoTimeout", {}>, {}>;
|
|
17
|
+
declare class MemoTimeout extends MemoTimeout_base {}
|
|
18
|
+
declare const MemoNone_base: Schema.Class<MemoNone, Schema.TaggedStruct<"MemoNone", {}>, {}>;
|
|
19
|
+
declare class MemoNone extends MemoNone_base {}
|
|
20
|
+
type Memo = MemoData | MemoError | MemoInput | MemoTimeout | MemoNone;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { Memo };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Match, Predicate, Schema } from "effect";
|
|
2
|
+
//#region src/internal/domain/Memo.ts
|
|
3
|
+
const IncomingMemo = Schema.Struct({
|
|
4
|
+
data: Schema.optional(Schema.Unknown),
|
|
5
|
+
error: Schema.optional(Schema.Unknown),
|
|
6
|
+
input: Schema.optional(Schema.Unknown)
|
|
7
|
+
});
|
|
8
|
+
const IncomingMemoData = Schema.Struct({ data: Schema.Unknown });
|
|
9
|
+
const IncomingMemoError = Schema.Struct({ error: Schema.Unknown });
|
|
10
|
+
const IncomingMemoInput = Schema.Struct({ input: Schema.Unknown });
|
|
11
|
+
var MemoData = class extends Schema.TaggedClass()("MemoData", { data: Schema.Unknown }) {};
|
|
12
|
+
var MemoError = class extends Schema.TaggedClass()("MemoError", { error: Schema.Unknown }) {};
|
|
13
|
+
var MemoInput = class extends Schema.TaggedClass()("MemoInput", { input: Schema.Unknown }) {};
|
|
14
|
+
var MemoTimeout = class extends Schema.TaggedClass()("MemoTimeout", {}) {};
|
|
15
|
+
var MemoNone = class extends Schema.TaggedClass()("MemoNone", {}) {};
|
|
16
|
+
const decode = (value) => Match.value(value).pipe(Match.when(Predicate.isNull, () => MemoTimeout.make({})), Match.when(Predicate.not(Schema.is(IncomingMemo)), () => MemoNone.make({})), Match.when(Schema.is(IncomingMemoError), ({ error }) => MemoError.make({ error })), Match.when(Schema.is(IncomingMemoInput), ({ input }) => MemoInput.make({ input })), Match.when(Schema.is(IncomingMemoData), ({ data }) => MemoData.make({ data })), Match.orElse(() => MemoNone.make({})));
|
|
17
|
+
//#endregion
|
|
18
|
+
export { decode };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { StepInfo } from "./StepInfo.js";
|
|
2
|
+
import { GeneratorOpcode } from "../protocol.js";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
//#region src/internal/domain/StepCommand.d.ts
|
|
6
|
+
declare const Sleep_base: Schema.Class<Sleep, Schema.TaggedStruct<"Sleep", {
|
|
7
|
+
readonly info: typeof StepInfo;
|
|
8
|
+
readonly sequence: Schema.Number;
|
|
9
|
+
readonly duration: Schema.String;
|
|
10
|
+
}>, {}>;
|
|
11
|
+
declare class Sleep extends Sleep_base {}
|
|
12
|
+
declare const WaitForEvent_base: Schema.Class<WaitForEvent, Schema.TaggedStruct<"WaitForEvent", {
|
|
13
|
+
readonly info: typeof StepInfo;
|
|
14
|
+
readonly sequence: Schema.Number;
|
|
15
|
+
readonly event: Schema.String;
|
|
16
|
+
readonly timeout: Schema.String;
|
|
17
|
+
readonly if: Schema.optional<Schema.String>;
|
|
18
|
+
}>, {}>;
|
|
19
|
+
declare class WaitForEvent extends WaitForEvent_base {}
|
|
20
|
+
declare const InvokeFunction_base: Schema.Class<InvokeFunction, Schema.TaggedStruct<"InvokeFunction", {
|
|
21
|
+
readonly info: typeof StepInfo;
|
|
22
|
+
readonly sequence: Schema.Number;
|
|
23
|
+
readonly functionId: Schema.String;
|
|
24
|
+
readonly payload: Schema.Unknown;
|
|
25
|
+
readonly timeout: Schema.optional<Schema.String>;
|
|
26
|
+
}>, {}>;
|
|
27
|
+
declare class InvokeFunction extends InvokeFunction_base {}
|
|
28
|
+
declare const StepRunResult_base: Schema.Class<StepRunResult, Schema.TaggedStruct<"StepRunResult", {
|
|
29
|
+
readonly info: typeof StepInfo;
|
|
30
|
+
readonly data: Schema.Unknown;
|
|
31
|
+
}>, {}>;
|
|
32
|
+
declare class StepRunResult extends StepRunResult_base {}
|
|
33
|
+
declare const SendEventResult_base: Schema.Class<SendEventResult, Schema.TaggedStruct<"SendEventResult", {
|
|
34
|
+
readonly info: typeof StepInfo;
|
|
35
|
+
readonly data: Schema.Struct<{
|
|
36
|
+
readonly ids: Schema.$Array<Schema.String>;
|
|
37
|
+
}>;
|
|
38
|
+
readonly rawPayload: Schema.Unknown;
|
|
39
|
+
}>, {}>;
|
|
40
|
+
declare class SendEventResult extends SendEventResult_base {}
|
|
41
|
+
declare const StepRunPlanned_base: Schema.Class<StepRunPlanned, Schema.TaggedStruct<"StepRunPlanned", {
|
|
42
|
+
readonly info: typeof StepInfo;
|
|
43
|
+
readonly sequence: Schema.Number;
|
|
44
|
+
}>, {}>;
|
|
45
|
+
declare class StepRunPlanned extends StepRunPlanned_base {}
|
|
46
|
+
declare const SendEventPlanned_base: Schema.Class<SendEventPlanned, Schema.TaggedStruct<"SendEventPlanned", {
|
|
47
|
+
readonly info: typeof StepInfo;
|
|
48
|
+
readonly sequence: Schema.Number;
|
|
49
|
+
}>, {}>;
|
|
50
|
+
declare class SendEventPlanned extends SendEventPlanned_base {}
|
|
51
|
+
declare const StepRunError_base: Schema.Class<StepRunError, Schema.TaggedStruct<"StepRunError", {
|
|
52
|
+
readonly info: typeof StepInfo;
|
|
53
|
+
readonly error: Schema.Unknown;
|
|
54
|
+
readonly noRetry: Schema.optional<Schema.Boolean>;
|
|
55
|
+
readonly retryAfterMs: Schema.optional<Schema.Number>;
|
|
56
|
+
}>, {}>;
|
|
57
|
+
declare class StepRunError extends StepRunError_base {}
|
|
58
|
+
declare const StepRunFailed_base: Schema.Class<StepRunFailed, Schema.TaggedStruct<"StepRunFailed", {
|
|
59
|
+
readonly info: typeof StepInfo;
|
|
60
|
+
readonly error: Schema.Unknown;
|
|
61
|
+
}>, {}>;
|
|
62
|
+
declare class StepRunFailed extends StepRunFailed_base {}
|
|
63
|
+
declare const Failure_base: Schema.Class<Failure, Schema.Struct<{
|
|
64
|
+
readonly opcode: typeof GeneratorOpcode;
|
|
65
|
+
readonly retryAfterMs: Schema.Option<Schema.Number>;
|
|
66
|
+
readonly noRetry: Schema.Boolean;
|
|
67
|
+
}>, {}>;
|
|
68
|
+
declare class Failure extends Failure_base {}
|
|
69
|
+
declare const PlannedOpcode_base: Schema.Class<PlannedOpcode, Schema.Struct<{
|
|
70
|
+
readonly opcode: typeof GeneratorOpcode;
|
|
71
|
+
readonly sequence: Schema.Number;
|
|
72
|
+
}>, {}>;
|
|
73
|
+
declare class PlannedOpcode extends PlannedOpcode_base {}
|
|
74
|
+
type YieldCommand = Sleep | WaitForEvent | InvokeFunction;
|
|
75
|
+
type ResultCommand = StepRunResult | SendEventResult;
|
|
76
|
+
type PlanCommand = YieldCommand | StepRunPlanned | SendEventPlanned;
|
|
77
|
+
type ErrorCommand = StepRunError | StepRunFailed;
|
|
78
|
+
//#endregion
|
|
79
|
+
export { ErrorCommand, Failure, PlanCommand, PlannedOpcode, ResultCommand, YieldCommand };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { GeneratorOpcode, UserError } from "../protocol.js";
|
|
2
|
+
import { isNonRetriableError, isRetryAfterError } from "../errors.js";
|
|
3
|
+
import { StepInfo } from "./StepInfo.js";
|
|
4
|
+
import { Duration, Match, Option, Schema } from "effect";
|
|
5
|
+
//#region src/internal/domain/StepCommand.ts
|
|
6
|
+
var Sleep = class extends Schema.TaggedClass()("Sleep", {
|
|
7
|
+
info: StepInfo,
|
|
8
|
+
sequence: Schema.Number,
|
|
9
|
+
duration: Schema.String
|
|
10
|
+
}) {};
|
|
11
|
+
var WaitForEvent = class extends Schema.TaggedClass()("WaitForEvent", {
|
|
12
|
+
info: StepInfo,
|
|
13
|
+
sequence: Schema.Number,
|
|
14
|
+
event: Schema.String,
|
|
15
|
+
timeout: Schema.String,
|
|
16
|
+
if: Schema.optional(Schema.String)
|
|
17
|
+
}) {};
|
|
18
|
+
var InvokeFunction = class extends Schema.TaggedClass()("InvokeFunction", {
|
|
19
|
+
info: StepInfo,
|
|
20
|
+
sequence: Schema.Number,
|
|
21
|
+
functionId: Schema.String,
|
|
22
|
+
payload: Schema.Unknown,
|
|
23
|
+
timeout: Schema.optional(Schema.String)
|
|
24
|
+
}) {};
|
|
25
|
+
var StepRunResult = class extends Schema.TaggedClass()("StepRunResult", {
|
|
26
|
+
info: StepInfo,
|
|
27
|
+
data: Schema.Unknown
|
|
28
|
+
}) {};
|
|
29
|
+
var SendEventResult = class extends Schema.TaggedClass()("SendEventResult", {
|
|
30
|
+
info: StepInfo,
|
|
31
|
+
data: Schema.Struct({ ids: Schema.Array(Schema.String) }),
|
|
32
|
+
rawPayload: Schema.Unknown
|
|
33
|
+
}) {};
|
|
34
|
+
var StepRunPlanned = class extends Schema.TaggedClass()("StepRunPlanned", {
|
|
35
|
+
info: StepInfo,
|
|
36
|
+
sequence: Schema.Number
|
|
37
|
+
}) {};
|
|
38
|
+
var SendEventPlanned = class extends Schema.TaggedClass()("SendEventPlanned", {
|
|
39
|
+
info: StepInfo,
|
|
40
|
+
sequence: Schema.Number
|
|
41
|
+
}) {};
|
|
42
|
+
var StepRunError = class extends Schema.TaggedClass()("StepRunError", {
|
|
43
|
+
info: StepInfo,
|
|
44
|
+
error: Schema.Unknown,
|
|
45
|
+
noRetry: Schema.optional(Schema.Boolean),
|
|
46
|
+
retryAfterMs: Schema.optional(Schema.Number)
|
|
47
|
+
}) {};
|
|
48
|
+
var StepRunFailed = class extends Schema.TaggedClass()("StepRunFailed", {
|
|
49
|
+
info: StepInfo,
|
|
50
|
+
error: Schema.Unknown
|
|
51
|
+
}) {};
|
|
52
|
+
var Failure = class extends Schema.Class("effect-inngest/internal/domain/StepCommand/Failure")({
|
|
53
|
+
opcode: GeneratorOpcode,
|
|
54
|
+
retryAfterMs: Schema.Option(Schema.Number),
|
|
55
|
+
noRetry: Schema.Boolean
|
|
56
|
+
}) {};
|
|
57
|
+
var PlannedOpcode = class extends Schema.Class("effect-inngest/internal/domain/StepCommand/PlannedOpcode")({
|
|
58
|
+
opcode: GeneratorOpcode,
|
|
59
|
+
sequence: Schema.Number
|
|
60
|
+
}) {};
|
|
61
|
+
const stepRunFailureForAttempt = (args) => {
|
|
62
|
+
const noRetry = isNonRetriableError(args.error) ? true : void 0;
|
|
63
|
+
const retryAfterMs = isRetryAfterError(args.error) ? Duration.toMillis(args.error.retryAfter) : void 0;
|
|
64
|
+
return noRetry === true || args.attempt >= args.maxAttempts - 1 ? StepRunFailed.make({
|
|
65
|
+
info: args.info,
|
|
66
|
+
error: args.error
|
|
67
|
+
}) : StepRunError.make({
|
|
68
|
+
info: args.info,
|
|
69
|
+
error: args.error,
|
|
70
|
+
noRetry,
|
|
71
|
+
retryAfterMs
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const suspension = (command) => Match.value(command).pipe(Match.tag("Sleep", (cmd) => GeneratorOpcode.sleep({
|
|
75
|
+
info: cmd.info,
|
|
76
|
+
duration: cmd.duration
|
|
77
|
+
})), Match.tag("WaitForEvent", (cmd) => GeneratorOpcode.waitForEvent({
|
|
78
|
+
info: cmd.info,
|
|
79
|
+
event: cmd.event,
|
|
80
|
+
timeout: cmd.timeout,
|
|
81
|
+
if: cmd.if
|
|
82
|
+
})), Match.tag("InvokeFunction", (cmd) => GeneratorOpcode.invokeFunction({
|
|
83
|
+
info: cmd.info,
|
|
84
|
+
functionId: cmd.functionId,
|
|
85
|
+
payload: cmd.payload,
|
|
86
|
+
timeout: cmd.timeout
|
|
87
|
+
})), Match.exhaustive);
|
|
88
|
+
const completion = (command) => Match.value(command).pipe(Match.tag("StepRunResult", (cmd) => GeneratorOpcode.stepRunResponse({
|
|
89
|
+
info: cmd.info,
|
|
90
|
+
data: cmd.data
|
|
91
|
+
})), Match.tag("SendEventResult", (cmd) => GeneratorOpcode.sendEventStepRunResponse({
|
|
92
|
+
info: cmd.info,
|
|
93
|
+
data: cmd.data
|
|
94
|
+
})), Match.exhaustive);
|
|
95
|
+
const checkpoint = (command) => Match.value(command).pipe(Match.tag("StepRunResult", (cmd) => GeneratorOpcode.stepRun({
|
|
96
|
+
info: cmd.info,
|
|
97
|
+
data: cmd.data
|
|
98
|
+
})), Match.tag("SendEventResult", (cmd) => GeneratorOpcode.sendEventStepRun({
|
|
99
|
+
info: cmd.info,
|
|
100
|
+
data: cmd.data,
|
|
101
|
+
rawPayload: cmd.rawPayload
|
|
102
|
+
})), Match.exhaustive);
|
|
103
|
+
const plan = (command) => PlannedOpcode.make({
|
|
104
|
+
opcode: Match.value(command).pipe(Match.tag("Sleep", (cmd) => suspension(cmd)), Match.tag("WaitForEvent", (cmd) => suspension(cmd)), Match.tag("InvokeFunction", (cmd) => suspension(cmd)), Match.tag("StepRunPlanned", (cmd) => GeneratorOpcode.stepPlanned(cmd.info)), Match.tag("SendEventPlanned", (cmd) => GeneratorOpcode.sendEventStepPlanned(cmd.info)), Match.exhaustive),
|
|
105
|
+
sequence: command.sequence
|
|
106
|
+
});
|
|
107
|
+
const failure = (command) => Match.value(command).pipe(Match.tag("StepRunError", (cmd) => Failure.make({
|
|
108
|
+
opcode: GeneratorOpcode.stepError({
|
|
109
|
+
info: cmd.info,
|
|
110
|
+
error: UserError.fromUnknown(cmd.error),
|
|
111
|
+
noRetry: cmd.noRetry
|
|
112
|
+
}),
|
|
113
|
+
retryAfterMs: Option.fromNullishOr(cmd.retryAfterMs),
|
|
114
|
+
noRetry: cmd.noRetry === true
|
|
115
|
+
})), Match.tag("StepRunFailed", (cmd) => Failure.make({
|
|
116
|
+
opcode: GeneratorOpcode.stepFailed({
|
|
117
|
+
info: cmd.info,
|
|
118
|
+
error: UserError.fromUnknown(cmd.error)
|
|
119
|
+
}),
|
|
120
|
+
retryAfterMs: Option.none(),
|
|
121
|
+
noRetry: true
|
|
122
|
+
})), Match.exhaustive);
|
|
123
|
+
//#endregion
|
|
124
|
+
export { InvokeFunction, SendEventPlanned, SendEventResult, Sleep, StepRunError, StepRunPlanned, StepRunResult, WaitForEvent, checkpoint, completion, failure, plan, stepRunFailureForAttempt };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/domain/StepInfo.d.ts
|
|
4
|
+
declare const StepInfo_base: Schema.Class<StepInfo, Schema.Struct<{
|
|
5
|
+
readonly id: Schema.String;
|
|
6
|
+
readonly name: Schema.String;
|
|
7
|
+
readonly hash: Schema.String;
|
|
8
|
+
readonly rawStepArg: Schema.Unknown;
|
|
9
|
+
}>, {}>;
|
|
10
|
+
declare class StepInfo extends StepInfo_base {}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { StepInfo };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region src/internal/domain/StepInfo.ts
|
|
3
|
+
var StepInfo = class extends Schema.Class("effect-inngest/internal/domain/StepInfo")({
|
|
4
|
+
id: Schema.String,
|
|
5
|
+
name: Schema.String,
|
|
6
|
+
hash: Schema.String,
|
|
7
|
+
rawStepArg: Schema.Unknown
|
|
8
|
+
}) {};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { StepInfo };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/domain/StepInput.d.ts
|
|
4
|
+
declare const StepInput: Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
5
|
+
readonly id: Schema.String;
|
|
6
|
+
readonly name: Schema.optional<Schema.String>;
|
|
7
|
+
}>]>;
|
|
8
|
+
type StepInput = typeof StepInput.Type;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { StepInput };
|