@xtr-dev/zod-rpc
Version:
Simple, type-safe RPC library with Zod validation and automatic TypeScript inference
78 lines • 3.36 kB
JavaScript
"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");
exports.userService = (0, zod_rpc_1.defineService)('user', {
get: {
input: zod_1.z.object({
userId: zod_1.z.string().min(1).describe('Unique identifier for the user to retrieve'),
}),
output: zod_1.z.object({
id: zod_1.z.string().describe('Unique user identifier'),
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).default(1).describe('Page number for pagination (starts at 1)'),
limit: zod_1.z
.number()
.min(1)
.max(100)
.default(10)
.describe('Maximum number of users to return per page'),
}),
output: zod_1.z.object({
users: zod_1.z
.array(zod_1.z.object({
id: zod_1.z.string().describe('Unique user identifier'),
name: zod_1.z.string().describe('Full name of the user'),
email: zod_1.z.string().describe('Email address of the user'),
}))
.describe('Array of user objects'),
total: zod_1.z.number().describe('Total number of users in the system'),
hasMore: zod_1.z.boolean().describe('Whether there are more users available on subsequent pages'),
}),
},
});
exports.mathService = (0, zod_rpc_1.defineService)('math', {
add: {
input: zod_1.z.object({
a: zod_1.z.number().describe('First number to add'),
b: zod_1.z.number().describe('Second number to add'),
}),
output: zod_1.z.object({
result: zod_1.z.number().describe('Sum of the two input numbers'),
}),
},
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 to round the result to'),
}),
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