/** * StandardSchema — Universal Schema Abstraction Layer * * Decouples the MCP Fusion validation engine from Zod specifically, * enabling support for any validator that implements the Standard Schema * specification (`@standard-schema/spec`). * * This allows users to choose lighter alternatives: * - **Zod** (~14kb min): Full-featured, most popular * - **Valibot** (~1kb min via tree-shaking): Ultra-lightweight * - **ArkType** (~5kb min): Fastest runtime validation * - **TypeBox** (~4kb min): JSON Schema native * * ## Standard Schema Spec * * Any object with `~standard` property conforming to: * ```typescript * interface StandardSchema { * '~standard': { * version: 1; * vendor: string; * validate: (value: unknown) => { value: T } | { issues: Issue[] }; * } * } * ``` * * @see https://github.com/standard-schema/standard-schema * * @example * ```typescript * import { toStandardValidator } from '@vinkius-core/mcp-fusion'; * import * as v from 'valibot'; * * // Valibot schemas work natively via Standard Schema * const schema = v.object({ name: v.string(), age: v.number() }); * const validator = toStandardValidator(schema); * * const result = validator.validate({ name: 'Alice', age: 30 }); * // { success: true, data: { name: 'Alice', age: 30 } } * ``` * * @module */ /** * Issue reported by a Standard Schema validator. */ export interface StandardSchemaIssue { readonly message: string; readonly path?: readonly (string | number | symbol)[]; } /** * Standard Schema v1 spec — the universal validator contract. * * Any schema library implementing this interface can be used with * MCP Fusion's validation pipeline. */ export interface StandardSchemaV1 { readonly '~standard': { readonly version: 1; readonly vendor: string; readonly validate: (value: TInput) => { readonly value: TOutput; } | { readonly issues: readonly StandardSchemaIssue[]; }; }; } /** * Infer the output type from a Standard Schema. */ export type InferStandardOutput = T extends StandardSchemaV1 ? O : never; /** * Fusion's internal validation result. */ export type ValidationResult = { readonly success: true; readonly data: T; } | { readonly success: false; readonly issues: readonly StandardSchemaIssue[]; }; /** * Universal validator interface used internally by MCP Fusion. * * Wraps any schema library (Zod, Valibot, ArkType, etc.) into * a consistent validation contract. */ export interface FusionValidator { /** Run validation and return a result (never throws) */ validate(value: unknown): ValidationResult; /** Vendor identifier (e.g. 'zod', 'valibot', 'arktype') */ readonly vendor: string; /** Original schema reference (for introspection) */ readonly schema: unknown; } /** * Create a FusionValidator from a Standard Schema v1 compatible schema. * * This is the primary entry point for non-Zod validators. Any schema * library implementing the Standard Schema spec can be used directly. * * @param schema - A Standard Schema v1 compatible schema * @returns A {@link FusionValidator} wrapping the schema * * @example * ```typescript * import * as v from 'valibot'; // ~1kb tree-shaken * * const schema = v.object({ name: v.string() }); * const validator = toStandardValidator(schema); * * const ok = validator.validate({ name: 'Alice' }); * // { success: true, data: { name: 'Alice' } } * * const err = validator.validate({ name: 42 }); * // { success: false, issues: [{ message: 'Expected string', path: ['name'] }] } * ``` */ export declare function toStandardValidator(schema: StandardSchemaV1): FusionValidator; /** * Create a FusionValidator from a raw Zod schema. * * This adapter uses Zod's `.safeParse()` method and maps the result * to the standard FusionValidator interface. * * @param schema - A Zod schema (z.object, z.string, etc.) * @returns A {@link FusionValidator} wrapping the Zod schema * * @example * ```typescript * import { z } from 'zod'; * * const schema = z.object({ name: z.string() }); * const validator = fromZodSchema(schema); * * const ok = validator.validate({ name: 'Alice' }); * // { success: true, data: { name: 'Alice' } } * ``` */ export declare function fromZodSchema(schema: ZodSchemaLike): FusionValidator; /** * Check if a value implements the Standard Schema v1 spec. * * @param value - Any value to check * @returns `true` if the value has a valid `~standard` property */ export declare function isStandardSchema(value: unknown): value is StandardSchemaV1; /** * Auto-detect and create a FusionValidator from any supported schema. * * Detection order: * 1. Standard Schema v1 (Valibot, ArkType, etc.) * 2. Zod-like (has `.safeParse()`) * 3. Throws if unrecognized * * @param schema - Any supported schema * @returns A {@link FusionValidator} * @throws If the schema type is not recognized */ export declare function autoValidator(schema: unknown): FusionValidator; /** Duck-typed Zod schema interface */ interface ZodSchemaLike { safeParse(value: unknown): { success: true; data: unknown; } | { success: false; error: { issues: Array<{ message: string; path?: (string | number)[]; }>; }; }; parse?(value: unknown): T; } export {}; //# sourceMappingURL=StandardSchema.d.ts.map