@xtr-dev/zod-rpc
Version:
Simple, type-safe RPC library with Zod validation and automatic TypeScript inference
11 lines • 979 B
TypeScript
import { z, ZodSchema } from 'zod';
export interface MethodContract<T extends ZodSchema, U extends ZodSchema> {
id: string;
input: T;
output: U;
}
export declare function createTypedInvoker<T extends ZodSchema, U extends ZodSchema>(contract: MethodContract<T, U>, invoke: (targetId: string, methodId: string, input: unknown, inputSchema?: ZodSchema, outputSchema?: ZodSchema, timeout?: number) => Promise<unknown>): (targetId: string, input: z.infer<T>, timeout?: number) => Promise<z.infer<U>>;
export declare function createBoundServiceClient<T extends Record<string, MethodContract<any, any>>>(serviceContracts: T, targetId: string, invoke: (targetId: string, methodId: string, input: unknown, inputSchema?: ZodSchema, outputSchema?: ZodSchema, timeout?: number) => Promise<unknown>): {
[K in keyof T]: T[K] extends MethodContract<infer I, infer O> ? (input: z.infer<I>, timeout?: number) => Promise<z.infer<O>> : never;
};
//# sourceMappingURL=method.d.ts.map