UNPKG

@xtr-dev/zod-rpc

Version:

Simple, type-safe RPC library with Zod validation and automatic TypeScript inference

70 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mathService = exports.userService = void 0; const zod_1 = require("zod"); const zod_rpc_1 = require("@xtr-dev/zod-rpc"); // User service for managing users exports.userService = (0, zod_rpc_1.defineService)('user', { get: { input: zod_1.z.object({ userId: zod_1.z.string().describe('Unique identifier for the user to retrieve'), }), output: zod_1.z.object({ id: zod_1.z.string().describe('User ID'), name: zod_1.z.string().describe('Full name of the user'), email: zod_1.z.string().email().describe('Email address of the user'), age: zod_1.z.number().min(0).max(120).describe('Age of the user in years'), }), }, create: { input: zod_1.z.object({ name: zod_1.z.string().min(1).describe('Full name of the new user'), email: zod_1.z.string().email().describe('Email address for the new user'), age: zod_1.z.number().min(0).max(120).describe('Age of the user in years'), }), output: zod_1.z.object({ id: zod_1.z.string().describe('Unique identifier assigned to the new user'), success: zod_1.z.boolean().describe('Whether the user was created successfully'), }), }, list: { input: zod_1.z.object({ page: zod_1.z.number().min(1).describe('Page number (1-based)'), limit: zod_1.z.number().min(1).max(100).describe('Number of users per page'), }), output: zod_1.z.object({ users: zod_1.z .array(zod_1.z.object({ id: zod_1.z.string(), name: zod_1.z.string(), email: zod_1.z.string().email(), })) .describe('List of users for this page'), total: zod_1.z.number().describe('Total number of users'), hasMore: zod_1.z.boolean().describe('Whether there are more pages available'), }), }, }); // Math service for calculations exports.mathService = (0, zod_rpc_1.defineService)('math', { add: { input: zod_1.z.object({ a: zod_1.z.number().describe('First number'), b: zod_1.z.number().describe('Second number'), }), output: zod_1.z.object({ result: zod_1.z.number().describe('Sum of a and b'), }), }, calculate: { input: zod_1.z.object({ expression: zod_1.z.string().describe('Mathematical expression to evaluate (e.g., "2 + 3 * 4")'), precision: zod_1.z.number().min(0).max(10).default(2).describe('Number of decimal places'), }), output: zod_1.z.object({ result: zod_1.z.number().describe('Calculated result of the mathematical expression'), expression: zod_1.z.string().describe('Original expression that was evaluated'), }), }, }); //# sourceMappingURL=shared.js.map