import "dotenv/config"; import { ChannelReader, ChannelReader as ChannelReader$1, ChannelWriter, ISdk, InitOptions, Logger, Logger as Logger$1 } from "iii-sdk"; import * as z from "zod"; import { ZodType } from "zod"; import { StreamAuthInput, StreamAuthResult, StreamAuthResult as StreamAuthResult$1, StreamContext, StreamContext as StreamContext$1, StreamJoinResult, StreamJoinResult as StreamJoinResult$1, StreamSetInput, StreamSetResult, StreamSetResult as StreamSetResult$1, UpdateOp, UpdateOp as UpdateOp$1 } from "iii-sdk/stream"; import { FromSchema } from "json-schema-to-ts"; import { JSONSchema } from "zod/v4/core"; //#region src/types/schema.types.d.ts type JsonSchema = JSONSchema.BaseSchema; //#endregion //#region src/types.d.ts type ZodInput = ZodType; type TypedJsonSchema = JsonSchema & { readonly __phantomType?: T$1; }; type StepSchemaInput = ZodInput | JsonSchema | TypedJsonSchema; declare function jsonSchema(schema: T$1): TypedJsonSchema>; type InternalStateManager = { get(groupId: string, key: string): Promise; set(groupId: string, key: string, value: T$1): Promise | null>; update(groupId: string, key: string, ops: UpdateOp$1[]): Promise | null>; delete(groupId: string, key: string): Promise; list(groupId: string): Promise; clear(groupId: string): Promise; }; type EnqueueData = { topic: string; data: T$1; messageGroupId?: string; }; type Enqueuer = (event: TData) => Promise; type ExtractQueueInput = Exclude, MotiaHttpArgs>, undefined>; type ExtractApiInput = Extract; type ExtractStateInput = Extract>; type ExtractStreamInput = Extract>; type ExtractDataPayload = TInput extends ApiRequest ? TBody : TInput extends MotiaHttpArgs ? TBody : TInput extends undefined ? undefined : TInput; type MatchHandlers = { queue?: (input: ExtractQueueInput) => Promise; http?: (request: ExtractApiInput) => Promise; cron?: () => Promise; state?: (input: ExtractStateInput) => Promise; stream?: (input: ExtractStreamInput) => Promise; default?: (input: TInput) => Promise; }; interface FlowContext { traceId: string; trigger: TriggerInfo; is: { queue: (input: TInput) => input is ExtractQueueInput; http: (input: TInput) => input is ExtractApiInput; cron: (input: TInput) => input is never; state: (input: TInput) => input is ExtractStateInput; stream: (input: TInput) => input is ExtractStreamInput; }; /** * Extracts the data payload from the input, regardless of trigger type. * Useful when multiple triggers (e.g., queue and API) share the same data schema. * * - For API triggers: returns `request.body` * - For queue triggers: returns the queue data directly * - For cron triggers: returns `undefined` * * @example * ```ts * // When queue and API triggers have the same schema * const orderData = ctx.getData() // Works for both triggers * ``` */ getData: () => ExtractDataPayload; match: (handlers: MatchHandlers) => Promise; } type Enqueue = string | { topic: string; label?: string; conditional?: boolean; }; type TriggerType = 'http' | 'queue' | 'cron' | 'state' | 'stream'; type TriggerInfo = { type: TriggerType; index?: number; path?: string; method?: string; topic?: string; expression?: string; }; type QueueTriggerInput = T$1; type ApiTriggerInput = ApiRequest; type CronTriggerInput = undefined; type StateTriggerInput = { type: 'state'; group_id: string; item_id: string; old_value?: T$1; new_value?: T$1; }; type StreamEvent = { type: 'create'; data: TData; } | { type: 'update'; data: TData; } | { type: 'delete'; data: TData; }; type StreamTriggerInput = { type: 'stream'; timestamp: number; streamName: string; groupId: string; id: string; event: StreamEvent; }; type TriggerInput = QueueTriggerInput | ApiTriggerInput | CronTriggerInput | StateTriggerInput | StreamTriggerInput; type TriggerCondition = (input: TriggerInput, ctx: FlowContext>) => boolean | Promise; type HandlerConfig = { ram: number; cpu?: number; timeout: number; }; type QueueConfig = { type: 'fifo' | 'standard'; maxRetries: number; visibilityTimeout: number; delaySeconds: number; concurrency?: number; backoffType?: string; backoffDelayMs?: number; }; type ApiRouteMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD'; type ApiMiddleware = (req: MotiaHttpArgs, ctx: FlowContext>, next: () => Promise) => Promise; interface QueryParam { name: string; description: string; } type StateTrigger = { type: 'state'; condition?: TriggerCondition>; }; type StreamTrigger = { type: 'stream'; streamName: string; groupId?: string; itemId?: string; condition?: TriggerCondition>; }; type QueueTrigger = { type: 'queue'; topic: string; input?: TSchema; condition?: TriggerCondition : unknown>; config?: Partial; }; type ApiTrigger = { type: 'http'; path: string; method: ApiRouteMethod; bodySchema?: TSchema; responseSchema?: Record; queryParams?: readonly QueryParam[]; middleware?: readonly ApiMiddleware[]; condition?: TriggerCondition : unknown>; }; type CronTrigger = { type: 'cron'; expression: string; input?: never; condition?: TriggerCondition; }; type TriggerConfig = QueueTrigger | ApiTrigger | CronTrigger | StateTrigger | StreamTrigger; type StepConfig = { name: string; description?: string; triggers: readonly TriggerConfig[]; enqueues?: readonly Enqueue[]; virtualEnqueues?: readonly Enqueue[]; virtualSubscribes?: readonly string[]; flows?: readonly string[]; includeFiles?: readonly string[]; }; type MotiaHttpResponse = { status: (statusCode: number) => void; headers: (headers: Record) => void; stream: NodeJS.WritableStream; close: () => void; }; interface ApiRequest { pathParams: Record; queryParams: Record; body: TBody; headers: Record; } interface MotiaHttpRequest { pathParams: Record; queryParams: Record; body: TBody; headers: Record; method: string; requestBody: ChannelReader$1; } interface MotiaHttpArgs { request: MotiaHttpRequest; response: MotiaHttpResponse; } type ApiResponse = { status: TStatus; headers?: Record; body: TBody; }; type StepHandler = (input: TriggerInput, ctx: FlowContext>) => Promise; type Event = { topic: string; data: TData; traceId: string; flows?: string[]; logger: Logger$1; messageGroupId?: string; }; type Handler = (event: Event) => Promise; type SubscribeConfig = { queue: string; handlerName: string; filePath: string; handler: Handler; }; type UnsubscribeConfig = { filePath: string; queue: string; }; type Step = { filePath: string; config: StepConfig; }; type Flow = { name: string; description?: string; steps: Step[]; }; interface Streams {} interface Enqueues {} type InferSchema = T$1 extends TypedJsonSchema ? O : T$1 extends ZodInput ? z.infer : T$1 extends { readonly type: string; } ? FromSchema : T$1 extends { readonly anyOf: readonly any[]; } ? FromSchema : T$1 extends { readonly allOf: readonly any[]; } ? FromSchema : T$1 extends { readonly oneOf: readonly any[]; } ? FromSchema : T$1 extends undefined ? unknown : TFallback; type InferBodySchema = S$1 extends ZodInput ? z.infer : S$1 extends StepSchemaInput ? InferSchema : unknown; type TriggerToInput = TTrigger extends { type: 'queue'; input?: infer S; } ? S extends ZodInput ? z.infer : S extends StepSchemaInput ? InferSchema : unknown : TTrigger extends { type: 'http'; bodySchema?: infer S; } ? MotiaHttpArgs> : TTrigger extends { type: 'state'; } ? StateTriggerInput : TTrigger extends { type: 'stream'; } ? StreamTriggerInput : TTrigger extends { type: 'cron'; } ? undefined : never; type InferHandlerInput$1 = TriggerToInput; type InferReturnType = Promise; type EnqueueTopic = T$1 extends keyof Enqueues ? Enqueues[T$1] : unknown; type NormalizeEnqueue = E extends string ? { topic: E; } : E extends { topic: infer T extends string; } ? { topic: T; } : never; type EnqueueElement = NormalizeEnqueue extends { topic: infer T extends string; } ? { topic: T; data: EnqueueTopic; } : never; type InferEnqueues = T$1 extends { enqueues: readonly unknown[]; } ? EnqueueElement : never; type Handlers = (input: InferHandlerInput$1, ctx: FlowContext, InferHandlerInput$1>) => InferReturnType; //#endregion //#region src/guards.d.ts type ApiTriggerType = Extract; type QueueTriggerType = Extract; type CronTriggerType = Extract; type StateTriggerType = Extract; type StreamTriggerType = Extract; declare const isApiTrigger: (trigger: TriggerConfig) => trigger is ApiTriggerType; declare const isQueueTrigger: (trigger: TriggerConfig) => trigger is QueueTriggerType; declare const isCronTrigger: (trigger: TriggerConfig) => trigger is CronTriggerType; declare const isStateTrigger: (trigger: TriggerConfig) => trigger is StateTriggerType; declare const isStreamTrigger: (trigger: TriggerConfig) => trigger is StreamTriggerType; declare const getApiTriggers: (step: Step) => ApiTriggerType[]; declare const getQueueTriggers: (step: Step) => QueueTriggerType[]; declare const getCronTriggers: (step: Step) => CronTriggerType[]; declare const getStateTriggers: (step: Step) => StateTriggerType[]; declare const getStreamTriggers: (step: Step) => StreamTriggerType[]; //#endregion //#region src/multi-trigger.d.ts type StepDefinition$1 = { config: TConfig; handler: Handlers; }; type InferHandlerInput = TConfig extends StepConfig ? Parameters>[0] : never; type TriggerHandlers = { queue?: (input: ExtractQueueInput>, ctx: Omit, 'match'>) => Promise; http?: (request: ExtractApiInput>, ctx: Omit, 'match'>) => Promise; cron?: (ctx: Omit, 'match'>) => Promise; state?: (input: ExtractStateInput>, ctx: Omit, 'match'>) => Promise; stream?: (input: ExtractStreamInput>, ctx: Omit, 'match'>) => Promise; }; type MultiTriggerStepBuilder = { config: TConfig; handlers: (handlers: TriggerHandlers) => StepDefinition$1; onQueue: (handler: TriggerHandlers['queue']) => MultiTriggerStepBuilder & { handlers: () => StepDefinition$1; }; onHttp: (handler: TriggerHandlers['http']) => MultiTriggerStepBuilder & { handlers: () => StepDefinition$1; }; onCron: (handler: TriggerHandlers['cron']) => MultiTriggerStepBuilder & { handlers: () => StepDefinition$1; }; onState: (handler: TriggerHandlers['state']) => MultiTriggerStepBuilder & { handlers: () => StepDefinition$1; }; onStream: (handler: TriggerHandlers['stream']) => MultiTriggerStepBuilder & { handlers: () => StepDefinition$1; }; }; declare function multiTriggerStep(config: TConfig): MultiTriggerStepBuilder; //#endregion //#region src/types-stream.d.ts type StreamSubscription = { groupId: string; id?: string; }; interface StreamAuthInput$1 { headers: Record; path: string; queryParams: Record; addr: string; } type AuthenticateStream = (input: StreamAuthInput$1, context: FlowContext) => Promise; type PromiseOrValue = T$1 | Promise; interface StreamConfig { name: string; schema: StepSchemaInput; baseConfig: { storageType: 'default'; }; onJoin?: (subscription: StreamSubscription, context: FlowContext, authContext?: StreamContext$1) => PromiseOrValue; onLeave?: (subscription: StreamSubscription, context: FlowContext, authContext?: StreamContext$1) => PromiseOrValue; } type StateStreamEventChannel = { groupId: string; id?: string; }; type StateStreamEvent = { type: string; data: TData; }; type BaseStreamItem = TData & { id: string; }; interface MotiaStream { get(groupId: string, id: string): Promise | null>; set(groupId: string, id: string, data: TData): Promise>>; delete(groupId: string, id: string): Promise | null>; getGroup(groupId: string): Promise[]>; update(groupId: string, id: string, data: UpdateOp$1[]): Promise>>; send(channel: StateStreamEventChannel, event: StateStreamEvent): Promise; } //#endregion //#region src/new/build/loader.d.ts declare const generateStepId: (filePath: string) => string; //#endregion //#region src/new/stream.d.ts type InferStreamData = StreamConfig extends TConfig ? unknown : InferSchema; declare class Stream { readonly config: TConfig; constructor(config: TConfig); get(groupId: string, itemId: string): Promise | null>; set(groupId: string, itemId: string, data: InferStreamData): Promise>>; delete(groupId: string, itemId: string): Promise; list(groupId: string): Promise[]>; update(groupId: string, itemId: string, ops: UpdateOp$1[]): Promise>>; listGroups(): Promise; send(channel: StateStreamEventChannel, event: StateStreamEvent): Promise; } //#endregion //#region src/new/build/utils.d.ts declare class Motia { streams: Record; private authenticateStream; addStep(config: StepConfig, stepPath: string, handler: StepHandler, filePath: string): void; addStream(config: StreamConfig, _streamPath: string): void; initialize(): void; } //#endregion //#region src/new/iii.d.ts type OtelConfig = NonNullable; declare const getInstance: () => ISdk; declare const initIII: (otelConfig?: Partial) => ISdk; //#endregion //#region src/new/setup-step-endpoint.d.ts declare function setupStepEndpoint(iii: ISdk): void; //#endregion //#region src/new/state.d.ts declare class StateManager implements InternalStateManager { get(scope: string, key: string): Promise; set(scope: string, key: string, value: T$1): Promise | null>; delete(scope: string, key: string): Promise; list(scope: string): Promise; listGroups(): Promise; update(scope: string, key: string, ops: UpdateOp$1[]): Promise | null>; clear(scope: string): Promise; } declare const stateManager: StateManager; //#endregion //#region src/new/enqueue.d.ts declare const enqueue: Enqueuer; //#endregion //#region src/new/logger.d.ts declare const logger: Logger$1; //#endregion //#region src/step.d.ts type StepDefinition = { config: TConfig; handler: Handlers; }; type StepBuilder = { config: TConfig; handle: (handler: Handlers) => StepDefinition; }; declare function step(config: TConfig, handler: Handlers): StepDefinition; declare function step(config: TConfig): StepBuilder; //#endregion //#region src/triggers.d.ts type ApiOptions = { bodySchema?: TSchema; responseSchema?: Record; queryParams?: readonly QueryParam[]; middleware?: readonly ApiMiddleware[]; }; type QueueOptions = { input?: TSchema; config?: Partial; }; declare function http | undefined = undefined>(method: ApiRouteMethod, path: string, options?: TOptions, condition?: TriggerCondition): ApiTrigger ? S : undefined>; /** @deprecated Use http() instead. Will be removed in a future version. */ declare function api | undefined = undefined>(method: ApiRouteMethod, path: string, options?: TOptions, condition?: TriggerCondition): ApiTrigger ? S : undefined>; declare function queue | undefined = undefined>(topic: string, options?: TOptions, condition?: TriggerCondition): QueueTrigger ? S : undefined>; declare function cron(expression: string, condition?: TriggerCondition): CronTrigger; declare function state(condition?: TriggerCondition): StateTrigger; type StreamOptions = { groupId?: string; itemId?: string; condition?: TriggerCondition; }; declare function stream(streamName: string, optionsOrCondition?: StreamOptions | TriggerCondition): StreamTrigger; //#endregion export { ApiMiddleware, ApiRequest, ApiResponse, ApiRouteMethod, ApiTrigger, AuthenticateStream, BaseStreamItem, ChannelReader, ChannelWriter, CronTrigger, Enqueue, EnqueueData, Enqueuer, Enqueues, Event, ExtractApiInput, ExtractDataPayload, ExtractQueueInput, ExtractStateInput, ExtractStreamInput, Flow, FlowContext, Handler, HandlerConfig, Handlers, InferSchema, InternalStateManager, Logger, MatchHandlers, Motia, MotiaHttpArgs, MotiaHttpRequest, MotiaHttpResponse, MotiaStream, QueryParam, QueueConfig, QueueTrigger, StateManager, StateStreamEvent, StateStreamEventChannel, StateTrigger, StateTriggerInput, Step, StepConfig, StepHandler, StepSchemaInput, Stream, type StreamAuthInput, type StreamAuthResult, StreamConfig, type StreamContext, StreamEvent, type StreamJoinResult, type StreamSetInput, type StreamSetResult, StreamSubscription, StreamTrigger, StreamTriggerInput, Streams, SubscribeConfig, TriggerCondition, TriggerConfig, TriggerInfo, TriggerInput, TypedJsonSchema, UnsubscribeConfig, type UpdateOp, ZodInput, api, cron, enqueue, generateStepId, getApiTriggers, getCronTriggers, getInstance, getQueueTriggers, getStateTriggers, getStreamTriggers, http, initIII, isApiTrigger, isCronTrigger, isQueueTrigger, isStateTrigger, isStreamTrigger, jsonSchema, logger, multiTriggerStep, queue, setupStepEndpoint, state, stateManager, step, stream }; //# sourceMappingURL=index.d.mts.map