@odel/module-sdk
Version:
SDK for building Odel modules - MCP protocol over HTTP for Cloudflare Workers
47 lines • 1.47 kB
TypeScript
/**
* Schema utilities for Odel modules
*/
import { z } from 'zod';
/**
* Standard success/error response wrapper
*
* Creates a union type that supports either:
* - { success: true, ...customFields } for successful responses
* - { success: false, error: string } for error responses
*
* @example
* ```typescript
* const outputSchema = SuccessResponseSchema(
* z.object({
* result: z.number()
* })
* );
*
* // Valid responses:
* { success: true, result: 42 }
* { success: false, error: "Something went wrong" }
* ```
*
* Note: Use `as const` on the success literal for proper type discrimination:
* ```typescript
* return { success: true as const, result: 42 };
* return { success: false as const, error: "Error message" };
* ```
*/
export declare const SuccessResponseSchema: <T extends z.ZodRawShape>(dataSchema: z.ZodObject<T>) => z.ZodUnion<[z.ZodObject<{
success: z.ZodLiteral<true>;
} & T, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
success: z.ZodLiteral<true>;
} & T>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
success: z.ZodLiteral<true>;
} & T> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>, z.ZodObject<{
success: z.ZodLiteral<false>;
error: z.ZodString;
}, "strip", z.ZodTypeAny, {
error: string;
success: false;
}, {
error: string;
success: false;
}>]>;
//# sourceMappingURL=schemas.d.ts.map