/** * This file was generated by @pikku/cli@0.12.89 */ /** * Trigger-specific type definitions for tree-shaking optimization */ import { CorePikkuTriggerFunction, CorePikkuTriggerFunctionConfig, CoreTrigger } from '@pikku/core/trigger'; import type { CoreNodeConfig } from '@pikku/core/node'; import type { SingletonServices } from '../../types/application-types.d.js'; import type { StandardSchemaV1 } from '@standard-schema/spec'; /** * A trigger function that sets up a subscription and returns a teardown function. * The trigger is fired via wire.trigger.invoke(data). * * @template TInput - Input type (configuration passed when wired) * @template TOutput - Output type produced when trigger fires */ export type PikkuTriggerFunction = CorePikkuTriggerFunction; /** * Configuration object for creating a trigger function with metadata */ export type PikkuTriggerFunctionConfig = CorePikkuTriggerFunctionConfig; /** * Helper type to infer the output type from a Standard Schema */ type InferSchemaOutput = T extends StandardSchemaV1 ? Output : never; /** * Configuration object for trigger functions with Zod schema validation. * Use this when you want to define input/output schemas using Zod. * Types are automatically inferred from the schemas. */ export type PikkuTriggerFunctionConfigWithSchema = { title?: string; description?: string; tags?: string[]; func: PikkuTriggerFunction, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput : unknown>; input: InputSchema; output?: OutputSchema; node?: CoreNodeConfig; }; /** * Type definition for trigger wirings. * Declares a trigger name and its target pikku function. */ export type TriggerWiring = CoreTrigger; /** * A trigger source with the subscription function, using project-specific services. * * @template TInput - Input type passed to the trigger function * @template TOutput - Output type produced when trigger fires */ export type TriggerSource = { name: string; func: PikkuTriggerFunctionConfig; } & (unknown extends TInput ? { input?: TInput; } : { input: TInput; }); /** * Creates a trigger function configuration. * Use this to define trigger functions that set up subscriptions. * * @param triggerOrConfig - Function definition or configuration object * @returns The normalized configuration object * * @example * ```typescript * export const redisSubscribeTrigger = pikkuTriggerFunc< * { channel: string }, * { message: string } * >(async ({ redis }, { channel }, { trigger }) => { * const subscriber = redis.duplicate() * await subscriber.subscribe(channel, (msg) => { * trigger.invoke({ message: msg }) * }) * return () => subscriber.unsubscribe() * }) * * export const redisSubscribeTrigger = pikkuTriggerFunc({ * title: 'Redis Subscribe Trigger', * description: 'Listens to Redis pub/sub channel', * input: z.object({ channel: z.string() }), * output: z.object({ message: z.string() }), * func: async ({ redis }, { channel }, { trigger }) => { * const subscriber = redis.duplicate() * await subscriber.subscribe(channel, (msg) => { * trigger.invoke({ message: msg }) * }) * return () => subscriber.unsubscribe() * } * }) * ``` */ export declare function pikkuTriggerFunc(config: PikkuTriggerFunctionConfigWithSchema): PikkuTriggerFunctionConfig, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput : unknown, InputSchema, OutputSchema>; export declare function pikkuTriggerFunc(triggerOrConfig: PikkuTriggerFunction | PikkuTriggerFunctionConfig): PikkuTriggerFunctionConfig; /** * Registers a trigger with the Pikku framework. * Declares a trigger name and its target pikku function. * Runs everywhere — inspector extracts at build time. * * @param trigger - Trigger definition with name and function config */ export declare const wireTrigger: (trigger: TriggerWiring) => void; /** * Registers a trigger source with the Pikku framework. * Provides the subscription function and input data. * Only imported in the trigger worker process. * * @param source - Trigger source with name, func, and input */ export declare const wireTriggerSource: (source: TriggerSource) => void; export {};