import { z } from 'zod'; import type { Json } from './json'; export const ZTriggerJobOptionsSchema = z.object({ id: z.string().optional(), name: z.string(), payload: z.unknown().refine((x) => x !== undefined, { message: 'payload is required' }), timestamp: z.number().optional(), }); // The Omit is a temporary workaround for a "bug" in the zod library // @see: https://github.com/colinhacks/zod/issues/2966 export type TriggerJobOptions = Omit, 'payload'> & { payload: unknown; }; // eslint-disable-next-line @typescript-eslint/no-explicit-any export type JobDefinition = { id: string; name: string; version: string; enabled?: boolean; trigger: { name: string; schema?: z.ZodSchema; }; handler: (options: { payload: T; io: JobRunIO }) => Promise; }; export interface JobRunIO { // stableRun(cacheKey: string, callback: (io: JobRunIO) => T | Promise): Promise; runTask(cacheKey: string, callback: () => Promise): Promise; triggerJob(cacheKey: string, options: TriggerJobOptions): Promise; wait(cacheKey: string, ms: number): Promise; logger: { info(...args: unknown[]): void; error(...args: unknown[]): void; debug(...args: unknown[]): void; warn(...args: unknown[]): void; log(...args: unknown[]): void; }; }