UNPKG

inngest

Version:

Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.

153 lines (152 loc) 5.59 kB
import { ExecutionVersion } from "../../helpers/consts.cjs"; import { MaybePromise, Simplify } from "../../helpers/types.cjs"; import { ServerTiming } from "../../helpers/ServerTiming.cjs"; import { Middleware } from "../middleware/middleware.cjs"; import { MetadataKind, MetadataOpcode, MetadataScope } from "../InngestMetadata.cjs"; import { InngestFunction } from "../InngestFunction.cjs"; import { Context, IncomingOp, InternalCheckpointingOptions, OutgoingOp, StepMode } from "../../types.cjs"; import { Inngest } from "../Inngest.cjs"; import { ActionResponse } from "../InngestCommHandler.cjs"; import { Debugger } from "debug"; //#region src/components/execution/InngestExecution.d.ts declare namespace InngestExecution_d_exports { export { BasicFoundStep, ExecutionResult, ExecutionResultHandler, ExecutionResultHandlers, ExecutionResults, ExecutionVersion, IInngestExecution, InngestExecution, InngestExecutionFactory, InngestExecutionOptions, MemoizedOp, PREFERRED_ASYNC_EXECUTION_VERSION }; } /** * The possible results of an execution. */ interface ExecutionResults { "function-resolved": { data: unknown; }; "step-ran": { step: OutgoingOp; retriable?: boolean | string; }; "function-rejected": { error: unknown; retriable: boolean | string; }; "steps-found": { steps: [OutgoingOp, ...OutgoingOp[]]; }; "step-not-found": { step: OutgoingOp; foundSteps: BasicFoundStep[]; totalFoundSteps: number; }; /** * Indicates that we need to relinquish control back to Inngest in order to * change step modes. */ "change-mode": { to: StepMode; token: string; }; } type ExecutionResult = { [K in keyof ExecutionResults]: Simplify<{ type: K; ctx: Context.Any; ops: Record<string, MemoizedOp>; } & ExecutionResults[K]> }[keyof ExecutionResults]; interface BasicFoundStep { id: string; displayName?: string; } type ExecutionResultHandler<T = ActionResponse> = (result: ExecutionResult) => MaybePromise<T>; type ExecutionResultHandlers<T = ActionResponse> = { [E in ExecutionResult as E["type"]]: (result: E) => MaybePromise<T> }; interface MemoizedOp extends IncomingOp { /** * If the step has been hit during this run, these will be the arguments * passed to it. */ rawArgs?: unknown[]; fulfilled?: boolean; /** * The promise that has been returned to userland code. */ promise?: Promise<unknown>; seen?: boolean; } /** * The preferred execution version that will be used by the SDK when handling * brand new runs where the Executor is allowing us to choose. * * Changing this should not ever be a breaking change, as this will only change * new runs, not existing ones. */ declare const PREFERRED_ASYNC_EXECUTION_VERSION = ExecutionVersion.V2; /** * Options for creating a new {@link InngestExecution} instance. */ interface InngestExecutionOptions { client: Inngest.Any; fn: InngestFunction.Any; /** * The UUID that represents this function in Inngest. * * This is used to reference the function during async checkpointing, when we * know the function/run already exists and just wish to reference it * directly. */ internalFnId?: string; reqArgs: unknown[]; runId: string; data: Omit<Context.Any, "step" | "group" | "publish">; stepState: Record<string, MemoizedOp>; stepCompletionOrder: string[]; stepMode: StepMode; checkpointingConfig?: InternalCheckpointingOptions; /** * If this execution is being run from a queue job, this will be an identifier * used to reference this execution in Inngest. SDKs are expected to parrot * this back in some responses to correctly attribute actions to this queue * item. */ queueItemId?: string; /** * Headers to be sent with any request to Inngest during this execution. */ headers: Record<string, string>; requestedRunStep?: string; timer?: ServerTiming; isFailureHandler?: boolean; disableImmediateExecution?: boolean; /** * Information about the incoming HTTP request that triggered this execution. * Used by middleware `wrapRequest` hooks. */ requestInfo?: Middleware.Request; /** * Pre-created middleware instances to use for this execution. When provided, * the execution will use these instead of instantiating new ones from the * client. This ensures `wrapRequest` and other hooks share state on `this`. */ middlewareInstances?: Middleware.BaseMiddleware[]; /** * Provide the ability to transform the context passed to the function before * the execution starts. */ transformCtx?: (ctx: Readonly<Context.Any>) => Context.Any; /** * A hook that is called to create an {@link ActionResponse} from the returned * value of an execution. * * This is required for checkpointing executions. */ createResponse?: (data: unknown) => MaybePromise<ActionResponse>; } type InngestExecutionFactory = (options: InngestExecutionOptions) => IInngestExecution; declare class InngestExecution { protected options: InngestExecutionOptions; protected devDebug: Debugger; constructor(options: InngestExecutionOptions); } interface IInngestExecution { version: ExecutionVersion; start(): Promise<ExecutionResult>; addMetadata(stepId: string, kind: MetadataKind, scope: MetadataScope, op: MetadataOpcode, values: Record<string, unknown>): boolean; } //#endregion export { BasicFoundStep, ExecutionResult, IInngestExecution, InngestExecution, InngestExecutionFactory, InngestExecutionOptions, InngestExecution_d_exports, MemoizedOp }; //# sourceMappingURL=InngestExecution.d.cts.map