/** * Function validation core module * Provides a validator for function values along with an `implement()` * helper that wraps a concrete function with runtime validation of its * inputs and output. * * The runtime validator only enforces that the value is a function, since * argument and return-value contracts can only be checked when the function * is actually invoked. Use `.implement()` (or call the validator's * `implement` property directly) to create a wrapped function that asserts * the schema on every call. */ import { type StandardSchemaV1 } from "../../Validate/standardSchema"; import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type"; export type FunctionAnyValidator = (value: any) => ValidateCoreReturnType; export type FunctionExtractValidatedType = V extends (value: never) => { type: infer T; } ? ValidateType : never; export type InferInputs = Inputs extends readonly FunctionAnyValidator[] ? { [K in keyof Inputs]: FunctionExtractValidatedType; } : any[]; export type InferOutput = Output extends FunctionAnyValidator ? FunctionExtractValidatedType : any; /** * Function schema definition. `input` describes positional parameters and * `output` describes the return type. Both are optional; when omitted the * validator only enforces that the value is callable. */ export interface FunctionSchema { input?: readonly FunctionAnyValidator[]; output?: FunctionAnyValidator; } export type ExtractInput = S extends { input: infer I; } ? I : undefined; export type ExtractOutput = S extends { output: infer O; } ? O : undefined; /** * Inferred function signature from a `FunctionSchema`. Used by callers via * `SchemaToInterface` and as the return type of `implement()`. * @template Inputs - Tuple of validators describing positional parameters * @template Output - Validator describing the return value */ export type InferFunction = (...arguments_: InferInputs) => InferOutput; /** * Validator return type. Carries the inferred function signature through * the `type` field so `SchemaToInterface` can recover it. * @template Inputs - Tuple of validators describing positional parameters * @template Output - Validator describing the return value */ export interface FunctionReturnType { validate: boolean; message: string; type: InferFunction; } /** * Validator value enriched with an `implement()` method that returns a * runtime-checked wrapper of a concrete function matching the schema. * @template Inputs - Tuple of validators describing positional parameters * @template Output - Validator describing the return value */ export interface FunctionValidator { (value: InferFunction): FunctionReturnType; implement: (function__: InferFunction) => InferFunction; } /** * Creates a function validator. When invoked the validator only checks that * the value is callable; use `.implement()` on the returned validator to * obtain a runtime-checked wrapper that asserts the schema for each call. * @template S - Function schema type, captured for input/output inference * @param {S} [schema] - Function schema definition * @param {string} [message] - Custom error message for type validation * @returns {FunctionValidator} - Validator augmented with `implement()` */ export declare const func: (schema?: S, message?: string) => FunctionValidator, ExtractOutput> & StandardSchemaV1, ExtractOutput>, InferFunction, ExtractOutput>>;