import type { StandardSchemaV1 } from "@standard-schema/spec"; /** * Marker embedded in event payload to identify an event type. * Used by isCtx() type guard to determine which event triggered the workflow. */ export declare const EVENT_MARKER = "__event_name"; /** * Type-safe event definition. * Use with Client.emit() to publish events. * * @template TName The literal string type of the event name. * @template TSchema The StandardSchema type for input validation. */ export declare class EventDefinition { readonly name: TName; readonly schema: TSchema; /** * Phantom types for input/output inference. * Do not access at runtime - will throw. */ readonly __types: { input: StandardSchemaV1.InferInput; output: StandardSchemaV1.InferOutput; }; constructor(name: TName, schema: TSchema); /** * Type guard: casts the context input to this event's schema output type * without requiring the event marker to be present. * * Use this for externally sourced events that arrive without the marker * injected by Client.emit(). Schema validation still runs and throws if * the payload is malformed. * * @param ctx The context to check (TaskCtx, WorkflowCtx, HelperCtx, or SDK Context). * @returns True if the context input is a non-null object that passes schema validation. * @throws Error if the payload fails schema validation. */ cast(ctx: C): ctx is C & { input: StandardSchemaV1.InferOutput; }; /** * Type guard: checks if the context was triggered by this event. * Validates the input against the event schema and throws if malformed. * * @param ctx The context to check (TaskCtx, WorkflowCtx, HelperCtx, or SDK Context). * @returns True if the context input contains the event marker matching this event. * @throws Error if the event marker matches but the payload fails schema validation. */ isCtx(ctx: C): ctx is C & { input: StandardSchemaV1.InferOutput & { [EVENT_MARKER]: TName; }; }; } /** * Any event definition, used for generic constraints. */ export type AnyEventDefinition = EventDefinition; /** * Extracts the input type from an event definition. */ export type EventInput = E["__types"]["input"]; /** * Extracts the output type from an event definition. */ export type EventOutput = E["__types"]["output"]; /** * Factory function to create a type-safe event definition. * * @param name The event name (e.g., "user:created"). * @param schema A StandardSchema-compatible schema (e.g., Zod schema). * @returns A new EventDefinition instance. * * @example * ```typescript * import { z } from "zod"; * * const UserCreatedEvent = defineEvent("user:created", z.object({ * userId: z.string(), * email: z.string().email(), * })); * ``` */ export declare const defineEvent: (name: TName, schema: TSchema) => EventDefinition;