Function: defineStage()
Implementation — dispatches on arity to handle both call shapes:
defineStage(definition)— the direct, non-curried overloads above.defineStage<TContext>()— called with zero arguments; returns a function that acceptsdefinition(the curried overload above).
Call Signature
defineStage<
TContext>(): <TId,TInput,TOutput,TConfig>(definition) =>Stage<TInputextends"none"?ZodObject<{ },$strip> :TInput,TOutput,TConfig,TContext,TId>
Defined in: packages/workflow-engine/src/core/stage-factory.ts:304
Curried form — supply only TContext and let TypeScript infer TId (as
a string literal), TInput, TOutput, and TConfig from the definition
object passed to the returned function.
Prefer this over the 5-positional-generic overloads below whenever you
need to fix TContext explicitly. Positional generics require spelling
out all five by hand (defineStage<TId, TInput, TOutput, TConfig, TContext>({...})) since TypeScript can't infer a subset from the middle
of a generic list — that duplicates the types already on schemas and
silently loses TId literal inference if any of them are mistyped. The
curried form only ever requires the one generic TypeScript truly can't
infer on its own.
Type Parameters
TContext
TContext extends Record<string, unknown> = Record<string, unknown>
Returns
<TId, TInput, TOutput, TConfig>(definition) => Stage<TInput extends "none" ? ZodObject<{ }, $strip> : TInput, TOutput, TConfig, TContext, TId>
Example
type MyContext = { "previous-stage": { value: string } };
export const myStage = defineStage<MyContext>()({
id: "my-stage", // TId inferred as the literal "my-stage"
name: "My Stage",
schemas: {
input: InputSchema,
output: OutputSchema,
config: ConfigSchema,
},
async execute(ctx) {
const prev = ctx.require("previous-stage"); // typed via MyContext
return { output: { ... } };
},
});
Call Signature
defineStage<
TId,TInput,TOutput,TConfig,TContext>(definition):Stage<TInputextends"none"?ZodObject<{ },$strip> :TInput,TOutput,TConfig,TContext,TId>
Defined in: packages/workflow-engine/src/core/stage-factory.ts:333
Define a sync stage with simplified API
Type Parameters
TId
TId extends string
TInput
TInput extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> | "none"
TOutput
TOutput extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
TConfig
TConfig extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
TContext
TContext extends Record<string, unknown> = Record<string, unknown>
Parameters
definition
SyncStageDefinition<TInput, TOutput, TConfig, TContext, TId>
Returns
Stage<TInput extends "none" ? ZodObject<{ }, $strip> : TInput, TOutput, TConfig, TContext, TId>
Deprecated
Spelling out all five generics positionally is verbose and
throws away TId literal inference if any of them are mistyped. Prefer
the curried form when you need to fix TContext explicitly:
defineStage<TContext>()({ ... }). (This overload isn't going anywhere
— the curried form calls into it — this note is about the positional
generics, not about calling defineStage({ ... }) with inferred types.)
Call Signature
defineStage<
TId,TInput,TOutput,TConfig,TContext>(definition):Stage<TInputextends"none"?ZodObject<{ },$strip> :TInput,TOutput,TConfig,TContext,TId>
Defined in: packages/workflow-engine/src/core/stage-factory.ts:357
Define an async-batch stage with simplified API
Type Parameters
TId
TId extends string
TInput
TInput extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> | "none"
TOutput
TOutput extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
TConfig
TConfig extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
TContext
TContext extends Record<string, unknown> = Record<string, unknown>
Parameters
definition
AsyncBatchStageDefinition<TInput, TOutput, TConfig, TContext, TId>
Returns
Stage<TInput extends "none" ? ZodObject<{ }, $strip> : TInput, TOutput, TConfig, TContext, TId>
Deprecated
Spelling out all five generics positionally is verbose and
throws away TId literal inference if any of them are mistyped. Prefer
the curried form when you need to fix TContext explicitly:
defineStage<TContext>()({ ... }).