import type { OutputKey } from "./OutputKey"; import type { OutputAccessor, InferOutputEntry } from "./OutputAccessor"; import type { RunAuthContext } from "./RunAuthContext"; import type { SmithersRuntimeConfig } from "./context"; import type { z } from "zod"; /** * Reverse-lookup: given Schema and a value type V, find the key K where Schema[K] extends V. * Used to narrow return types when passing Zod schema objects directly. */ type SchemaKeyForValue = { [K in keyof Schema & string]: Schema[K] extends V ? K : never; }[keyof Schema & string]; type FallbackTableName = [keyof Schema & string] extends [never] ? string : never; export interface SmithersCtx { runId: string; iteration: number; iterations?: Record; input: Schema extends { input: infer T } ? T extends z.ZodTypeAny ? z.infer : T : any; auth: RunAuthContext | null; __smithersRuntime?: SmithersRuntimeConfig | null; outputs: OutputAccessor; output(table: FallbackTableName, key: OutputKey): any; // Overload: pass Zod schema value directly → narrowed return type output( table: V, key: OutputKey, ): SchemaKeyForValue extends never ? InferOutputEntry : InferOutputEntry; // Overload: pass string key → narrowed via K output( table: K, key: OutputKey, ): InferOutputEntry; outputMaybe( table: FallbackTableName, key: OutputKey, ): any | undefined; // Overload: pass Zod schema value directly → narrowed return type outputMaybe( table: V, key: OutputKey, ): SchemaKeyForValue extends never ? InferOutputEntry | undefined : InferOutputEntry | undefined; // Overload: pass string key → narrowed via K outputMaybe( table: K, key: OutputKey, ): InferOutputEntry | undefined; // Overload: pass Zod schema value directly → narrowed return type latest( table: V, nodeId: string, ): SchemaKeyForValue extends never ? InferOutputEntry | undefined : InferOutputEntry | undefined; // Overload: pass string key → narrowed via K latest( table: K, nodeId: string, ): InferOutputEntry | undefined; latest( table: FallbackTableName, nodeId: string, ): any | undefined; latestArray(value: unknown, schema: z.ZodType): any[]; iterationCount(table: any, nodeId: string): number; }