/** * @module defineConfig * * Factory that wraps a Zod schema into a CogniPipe-compliant config parser. * Node authors use this at class scope to define their config shape once and * reference it from execute(), describe(), or any other method that needs typed config. * * Never call schema.parse() or schema.safeParse() directly in node code — * use this factory to ensure validation failures produce CogniPipeError(NODE_CONFIG_INVALID) * rather than raw ZodError instances. */ import type { ZodType } from 'zod'; /** * A reusable, typed config parser returned by {@link defineConfig}. * Call `.parse()` inside `execute()` to validate and type the raw config. */ export interface ConfigDefinition { /** * Validates `raw` against the schema and returns typed output. * Applies Zod defaults (e.g. `z.number().default(5000)`) automatically. * * @param raw - The raw config object from the workflow step (NodeConfig = Record). * @returns The validated, fully-typed result. * @throws {CogniPipeError} NODE_CONFIG_INVALID if validation fails. * Error message identifies the first failing field and received value, * using the same path format as WorkflowValidator. */ parse(raw: unknown): T; /** * The underlying Zod schema. Expose for advanced use cases (e.g. generating * JSON Schema documentation or composing with other schemas). Read-only. */ readonly schema: ZodType; } /** * Creates a CogniPipe-compliant config parser from a Zod schema. * Declare the result as a constant at class scope so it is reusable * across all methods that need typed config. * * @param schema - A Zod schema describing the node's config shape. * @returns A {@link ConfigDefinition} with a `.parse()` method and `.schema` accessor. * * @example * ```typescript * import { defineConfig } from '@cognipipe/sdk'; * import { z } from 'zod'; * * // Declare at class scope — defined once, reused everywhere * const HttpConfig = defineConfig( * z.object({ * url: z.string().url('URL must be a valid http/https address'), * method: z.enum(['GET', 'POST', 'PUT', 'DELETE']).default('GET'), * timeout: z.number().int().min(0).max(30_000).default(5_000), * }), * ); * * @CogniNode({ type: '@cognipipe/node-http', version: '1.0.0' }) * export class HttpNode extends BaseNode { * async execute(config: NodeConfig, ctx: IExecutionContext): Promise { * const { url, method, timeout } = HttpConfig.parse(config); * // url, method, timeout are fully typed with defaults applied * return { result: 'done' }; * } * } * ``` */ export declare function defineConfig(schema: ZodType): ConfigDefinition; //# sourceMappingURL=defineConfig.d.ts.map