{"_id":"@6edesign/zrpc","_rev":"5-c3f224fc94f334369fa65fc19cfbb465","name":"@6edesign/zrpc","dist-tags":{"latest":"0.0.5"},"versions":{"0.0.1":{"name":"@6edesign/zrpc","version":"0.0.1","_id":"@6edesign/zrpc@0.0.1","maintainers":[{"name":"6edesign","email":"jon@6eDesign.net"}],"dist":{"shasum":"066a987030da1ca2803f9da02a05cc6fc19806e7","tarball":"https://registry.npmjs.org/@6edesign/zrpc/-/zrpc-0.0.1.tgz","fileCount":24,"integrity":"sha512-fk4HsZxLwqzjFnQ0cwhMhXZNNqm0zFXb+uQomKrw3h6gFe5qZQC8cwh0+mgQQ0+Uki3eciTRf04xOlgoIhZo5Q==","signatures":[{"sig":"MEUCIQC/BQHUYhTb9G+Wu/h20/YUiMkPwn3WvRvkkFsGnf17jgIgCMsJLukkdPZLK+CRY0xXyGK9vs1rFqiOw5Bk0nujBhw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":77598},"main":"dist/index.js","_from":"file:6edesign-zrpc-0.0.1.tgz","types":"dist/index.d.ts","scripts":{"dev":"tsdown --watch src/index.ts","test":"vitest run --dir test","build":"tsdown src/index.ts","check-types":"tsc --noEmit"},"_npmUser":{"name":"6edesign","email":"jon@6eDesign.net"},"_resolved":"/tmp/0fef4ce10dcd04059d892f71a136884a/6edesign-zrpc-0.0.1.tgz","_integrity":"sha512-fk4HsZxLwqzjFnQ0cwhMhXZNNqm0zFXb+uQomKrw3h6gFe5qZQC8cwh0+mgQQ0+Uki3eciTRf04xOlgoIhZo5Q==","_npmVersion":"10.9.3","description":"A schema-driven microservice library for building robust, type-safe APIs and clients in TypeScript or JavaScript.","directories":{},"_nodeVersion":"22.18.0","dependencies":{"zod":"^3.22.4","bull":"^4.12.2","cors":"^2.8.5","meow":"^13.1.0","axios":"^1.6.5","express":"^4.18.2","winston":"^3.17.0","body-parser":"^1.20.2","compression":"^1.8.0","openapi3-ts":"^4.5.0","response-time":"^2.3.2","express-winston":"^4.2.0","@6edesign/tracing":"^0.2.6","@opentelemetry/api":"^1.7.0","@6edesign/messenger":"^0.2.6","@opentelemetry/sdk-node":"^0.48.0","@influxdata/influxdb-client":"^1.33.2","@asteasolutions/zod-to-openapi":"^6.3.1","@opentelemetry/exporter-trace-otlp-http":"^0.48.0","@opentelemetry/auto-instrumentations-node":"^0.41.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.13.0","vitest":"^1.6.0","supertest":"^7.0.0","typescript":"^5.4.5","@types/bull":"^4.10.0","@types/cors":"^2.8.17","@types/express":"^4.17.21","@types/supertest":"^6.0.2","@6edesign/tsconfig":"^0.0.6","@types/body-parser":"^1.19.5","@types/compression":"^1.7.5","@types/response-time":"^2.3.8"},"_npmOperationalInternal":{"tmp":"tmp/zrpc_0.0.1_1756684934780_0.3214058356102758","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@6edesign/zrpc","version":"0.0.2","_id":"@6edesign/zrpc@0.0.2","maintainers":[{"name":"6edesign","email":"jon@6eDesign.net"}],"dist":{"shasum":"537f40f5855461936b2fc6a990cf217648581e6a","tarball":"https://registry.npmjs.org/@6edesign/zrpc/-/zrpc-0.0.2.tgz","fileCount":24,"integrity":"sha512-EAZr81n/lNX71UdhTmElqX/X95R+xqw2wIwg+OpMGgFna+QVtRjQSWbXkL+DSx6tyXB4dVnIlGCla44YUqUh7A==","signatures":[{"sig":"MEUCIF6htIZjkTbJ7dBrjn5VMJ2PVuaveqDFJdwllZPdz/4UAiEAtTiCDS2sJ1Y/QNOftqSplKOlX1yFybuOVA9ySrWZhfo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":77222},"main":"dist/index.js","type":"module","_from":"file:6edesign-zrpc-0.0.2.tgz","types":"dist/index.d.ts","scripts":{"dev":"tsdown --watch src/index.ts","test":"vitest run --dir test","build":"tsdown src/index.ts","check-types":"tsc --noEmit"},"_npmUser":{"name":"6edesign","email":"jon@6eDesign.net"},"_resolved":"/tmp/1366c0181b8e363ed961d38a9f4889bd/6edesign-zrpc-0.0.2.tgz","_integrity":"sha512-EAZr81n/lNX71UdhTmElqX/X95R+xqw2wIwg+OpMGgFna+QVtRjQSWbXkL+DSx6tyXB4dVnIlGCla44YUqUh7A==","_npmVersion":"10.9.3","description":"A schema-driven microservice library for building robust, type-safe APIs and clients in TypeScript or JavaScript.","directories":{},"_nodeVersion":"22.18.0","dependencies":{"zod":"^3.22.4","bull":"^4.12.2","cors":"^2.8.5","meow":"^13.1.0","axios":"^1.6.5","express":"^4.18.2","winston":"^3.17.0","body-parser":"^1.20.2","compression":"^1.8.0","openapi3-ts":"^4.5.0","response-time":"^2.3.2","express-winston":"^4.2.0","@6edesign/tracing":"^0.2.6","@opentelemetry/api":"^1.7.0","@6edesign/messenger":"^0.2.6","@opentelemetry/sdk-node":"^0.48.0","@influxdata/influxdb-client":"^1.33.2","@asteasolutions/zod-to-openapi":"^6.3.1","@opentelemetry/exporter-trace-otlp-http":"^0.48.0","@opentelemetry/auto-instrumentations-node":"^0.41.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.13.0","vitest":"^1.6.0","supertest":"^7.0.0","typescript":"^5.4.5","@types/bull":"^4.10.0","@types/cors":"^2.8.17","@types/express":"^4.17.21","@types/supertest":"^6.0.2","@6edesign/tsconfig":"^0.0.6","@types/body-parser":"^1.19.5","@types/compression":"^1.7.5","@types/response-time":"^2.3.8"},"_npmOperationalInternal":{"tmp":"tmp/zrpc_0.0.2_1756699825951_0.20275389104671748","host":"s3://npm-registry-packages-npm-production"}},"0.0.3":{"name":"@6edesign/zrpc","version":"0.0.3","_id":"@6edesign/zrpc@0.0.3","maintainers":[{"name":"6edesign","email":"jon@6eDesign.net"}],"dist":{"shasum":"6a46f3096c96eee0c8e0ac7cdd694b8fa5f3c118","tarball":"https://registry.npmjs.org/@6edesign/zrpc/-/zrpc-0.0.3.tgz","fileCount":55,"integrity":"sha512-0X0xjyNLJnmXh8k9/C7JyV048KK/qrNaZG8zssLaFe3QouDfx5EJGvoEjvmYxuYIvNQuI2BM8Mkohs2UzpgU+A==","signatures":[{"sig":"MEUCIQD0waNJlMiLnMhEYOYeCAFRMY2ATH9TpTNQqhwqf/sMSwIgBHlF742HXMrNl10Uk9wkkUayW3FGQiesqpmU4DSxahw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":88919},"main":"./dist/index.js","_from":"file:6edesign-zrpc-0.0.3.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.js"},"./zod":{"import":"./dist/zod.mjs","require":"./dist/zod.js"},"./client":{"import":"./dist/client.mjs","require":"./dist/client.js"},"./router":{"import":"./dist/router.mjs","require":"./dist/router.js"},"./package.json":"./package.json","./messenger-client":{"import":"./dist/messenger-client.mjs","require":"./dist/messenger-client.js"}},"scripts":{"dev":"tsdown --watch","test":"vitest run --dir test","build":"tsdown","check-types":"tsc --noEmit"},"_npmUser":{"name":"6edesign","email":"jon@6eDesign.net"},"_resolved":"/tmp/641fc7dc356cd40f22d6cdfaeae78f12/6edesign-zrpc-0.0.3.tgz","_integrity":"sha512-0X0xjyNLJnmXh8k9/C7JyV048KK/qrNaZG8zssLaFe3QouDfx5EJGvoEjvmYxuYIvNQuI2BM8Mkohs2UzpgU+A==","_npmVersion":"10.9.3","description":"A schema-driven microservice library for building robust, type-safe APIs and clients in TypeScript or JavaScript.","directories":{},"_nodeVersion":"22.18.0","dependencies":{"zod":"^3.22.4","bull":"^4.12.2","cors":"^2.8.5","meow":"^13.1.0","axios":"^1.6.5","express":"^4.18.2","winston":"^3.17.0","body-parser":"^1.20.2","compression":"^1.8.0","openapi3-ts":"^4.5.0","response-time":"^2.3.2","express-winston":"^4.2.0","@6edesign/tracing":"^0.2.5","@opentelemetry/api":"^1.7.0","@6edesign/messenger":"^0.2.5","@opentelemetry/sdk-node":"^0.48.0","@influxdata/influxdb-client":"^1.33.2","@asteasolutions/zod-to-openapi":"^6.3.1","@opentelemetry/exporter-trace-otlp-http":"^0.48.0","@opentelemetry/auto-instrumentations-node":"^0.41.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.13.0","vitest":"^1.6.0","supertest":"^7.0.0","typescript":"^5.4.5","@types/bull":"^4.10.0","@types/cors":"^2.8.17","@types/express":"^4.17.21","@types/supertest":"^6.0.2","@6edesign/tsconfig":"^0.0.6","@types/body-parser":"^1.19.5","@types/compression":"^1.7.5","@types/response-time":"^2.3.8"},"_npmOperationalInternal":{"tmp":"tmp/zrpc_0.0.3_1756703508776_0.7170690025113962","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"@6edesign/zrpc","version":"0.0.4","_id":"@6edesign/zrpc@0.0.4","maintainers":[{"name":"6edesign","email":"jon@6eDesign.net"}],"dist":{"shasum":"e184ca1e305733edbfbcb0ef035f8aa698159db0","tarball":"https://registry.npmjs.org/@6edesign/zrpc/-/zrpc-0.0.4.tgz","fileCount":54,"integrity":"sha512-fh8gdd9DIsPNtALIkSTfFvOVNBcGRxy+9qFO1wMn8Kso/CBVjGzbkhr4JiVXcc88L2RqWNAWmm00pSeE6VEQsw==","signatures":[{"sig":"MEYCIQCziJOXknzf8xmQqjTouIDFTDkkgfOClZ6vl43U2ZzlLQIhAIENGP2/niBJMuRtx8VpfYjcCht12nbG/bivNopQ+Prr","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":90419},"main":"./dist/index.js","_from":"file:6edesign-zrpc-0.0.4.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.js"},"./zod":{"import":"./dist/zod.mjs","require":"./dist/zod.js"},"./client":{"import":"./dist/client.mjs","require":"./dist/client.js"},"./router":{"import":"./dist/router.mjs","require":"./dist/router.js"},"./package.json":"./package.json","./messenger-client":{"import":"./dist/messenger-client.mjs","require":"./dist/messenger-client.js"}},"scripts":{"dev":"tsdown --watch","test":"vitest run --dir test","build":"tsdown","check-types":"tsc --noEmit"},"_npmUser":{"name":"6edesign","email":"jon@6eDesign.net"},"_resolved":"/tmp/f57c90cbc4055ffc3f8fe3f7d59058f4/6edesign-zrpc-0.0.4.tgz","_integrity":"sha512-fh8gdd9DIsPNtALIkSTfFvOVNBcGRxy+9qFO1wMn8Kso/CBVjGzbkhr4JiVXcc88L2RqWNAWmm00pSeE6VEQsw==","_npmVersion":"10.9.3","description":"A schema-driven microservice library for building robust, type-safe APIs and clients in TypeScript or JavaScript.","directories":{},"_nodeVersion":"22.19.0","dependencies":{"zod":"^3.22.4","bull":"^4.12.2","cors":"^2.8.5","meow":"^13.1.0","axios":"^1.6.5","express":"^4.18.2","winston":"^3.17.0","body-parser":"^1.20.2","compression":"^1.8.0","openapi3-ts":"^4.5.0","response-time":"^2.3.2","express-winston":"^4.2.0","@6edesign/tracing":"^0.2.5","@opentelemetry/api":"^1.7.0","@6edesign/messenger":"^0.2.5","@opentelemetry/sdk-node":"^0.48.0","@influxdata/influxdb-client":"^1.33.2","@asteasolutions/zod-to-openapi":"^6.3.1","@opentelemetry/exporter-trace-otlp-http":"^0.48.0","@opentelemetry/auto-instrumentations-node":"^0.41.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.13.0","vitest":"^1.6.0","supertest":"^7.0.0","typescript":"^5.4.5","@types/bull":"^4.10.0","@types/cors":"^2.8.17","@types/express":"^4.17.21","@types/supertest":"^6.0.2","@6edesign/tsconfig":"^0.0.6","@types/body-parser":"^1.19.5","@types/compression":"^1.7.5","@types/response-time":"^2.3.8"},"_npmOperationalInternal":{"tmp":"tmp/zrpc_0.0.4_1757567345855_0.12478840405509928","host":"s3://npm-registry-packages-npm-production"}},"0.0.5":{"name":"@6edesign/zrpc","version":"0.0.5","description":"A schema-driven microservice library for building robust, type-safe APIs and clients in TypeScript or JavaScript.","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.js"},"./client":{"import":"./dist/client.mjs","require":"./dist/client.js"},"./messenger-client":{"import":"./dist/messenger-client.mjs","require":"./dist/messenger-client.js"},"./router":{"import":"./dist/router.mjs","require":"./dist/router.js"},"./zod":{"import":"./dist/zod.mjs","require":"./dist/zod.js"},"./package.json":"./package.json"},"publishConfig":{"access":"public"},"dependencies":{"@asteasolutions/zod-to-openapi":"^6.3.1","@influxdata/influxdb-client":"^1.33.2","@opentelemetry/api":"^1.7.0","@opentelemetry/auto-instrumentations-node":"^0.41.1","@opentelemetry/exporter-trace-otlp-http":"^0.48.0","@opentelemetry/sdk-node":"^0.48.0","@6edesign/messenger":"^0.2.5","@6edesign/tracing":"^0.2.5","axios":"^1.6.5","body-parser":"^1.20.2","bull":"^4.12.2","compression":"^1.8.0","cors":"^2.8.5","express":"^4.18.2","express-winston":"^4.2.0","meow":"^13.1.0","openapi3-ts":"^4.5.0","response-time":"^2.3.2","winston":"^3.17.0","zod":"^3.22.4"},"devDependencies":{"@types/body-parser":"^1.19.5","@types/bull":"^4.10.0","@types/compression":"^1.7.5","@types/cors":"^2.8.17","@types/express":"^4.17.21","@types/response-time":"^2.3.8","@types/supertest":"^6.0.2","supertest":"^7.0.0","tsdown":"^0.13.0","typescript":"^5.4.5","vitest":"^1.6.0","@6edesign/tsconfig":"^0.0.6"},"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"dev":"tsdown --watch","build":"tsdown","test":"vitest run --dir test","check-types":"tsc --noEmit"},"_id":"@6edesign/zrpc@0.0.5","_integrity":"sha512-NS4MOR896r2rv8o0Bio3Tmr4rWw7a3ix2hKLaWPxzxAeeEJR+dmAsJ29KgKq7dYnTFLdp57ecoG+SniFygqMvQ==","_resolved":"/tmp/65c7dc2bb87b7126373085dc24cdd56b/6edesign-zrpc-0.0.5.tgz","_from":"file:6edesign-zrpc-0.0.5.tgz","_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-NS4MOR896r2rv8o0Bio3Tmr4rWw7a3ix2hKLaWPxzxAeeEJR+dmAsJ29KgKq7dYnTFLdp57ecoG+SniFygqMvQ==","shasum":"b83a80530b7f46be694e8b8aa1b971a53281073f","tarball":"https://registry.npmjs.org/@6edesign/zrpc/-/zrpc-0.0.5.tgz","fileCount":54,"unpackedSize":91078,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCcAUWsvIPQYKFOyQyEIxypMQgrjrJx+S2+u/iNI+ehuQIgMepTC1OKhmlhd6tYqCNpxV8kPzumKejDH+U89/9cxb4="}]},"_npmUser":{"name":"6edesign","email":"jon@6eDesign.net"},"directories":{},"maintainers":[{"name":"6edesign","email":"jon@6eDesign.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/zrpc_0.0.5_1757655971717_0.15573938891002714"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-01T00:02:14.727Z","modified":"2025-09-12T05:46:12.092Z","0.0.1":"2025-09-01T00:02:14.977Z","0.0.2":"2025-09-01T04:10:26.149Z","0.0.3":"2025-09-01T05:11:48.954Z","0.0.4":"2025-09-11T05:09:06.059Z","0.0.5":"2025-09-12T05:46:11.910Z"},"description":"A schema-driven microservice library for building robust, type-safe APIs and clients in TypeScript or JavaScript.","maintainers":[{"name":"6edesign","email":"jon@6eDesign.net"}],"readme":"# @6edesign/zrpc\n\n<!-- Badges: Version, Build Status, npm, etc. -->\n\n## Overview\n\nA schema-driven library serving as a robust foundation for building type-safe microservice APIs and clients. It leverages Zod to define clear input and output schemas, enabling strong validation and automatic OpenAPI specification generation. The package supports HTTP communication via Express and integrates message-based interactions, providing rich intellisense for both TypeScript and JavaScript projects.\n\n## Key Features\n\n- **Schema-Driven API Definition:** Define API contracts using Zod for robust validation.\n- **Type-Safe Development:** Ensures strong typing for controllers and clients in TypeScript and JavaScript.\n- **Automatic OpenAPI Generation:** Generate OpenAPI (Swagger) specifications directly from your route definitions.\n- **Multiple Transport Layers:** Supports HTTP (Express) and message-based communication.\n- **Excellent Developer Experience:** Provides rich intellisense and clear error handling.\n\n## Installation\n\n```bash\npnpm add @6edesign/zrpc\n```\n\n```bash\nnpm install @6edesign/zrpc\n```\n\n```bash\nyarn add @6edesign/zrpc\n```\n\n## Quick Start\n\n### 1. Define Schemas and Routes\n\nStart by defining your data schemas using Zod and then create your API routes.\n\n```typescript\n// src/schemas.ts (or similar)\nimport { z } from './zod';\nimport { createRoute } from './router';\n\nexport const UserSchema = z.object({\n\tid: z.string(),\n\tname: z.string(),\n\temail: z.string().email()\n});\n\nexport const GetUserRoute = createRoute({\n\tpath: '/users/:id',\n\tmethod: 'get',\n\tinput: z.object({ id: z.string() }),\n\toutput: UserSchema\n});\n\nexport const CreateUserRoute = createRoute({\n\tpath: '/users',\n\tmethod: 'post',\n\tinput: z.object({\n\t\tname: z.string(),\n\t\temail: z.string().email()\n\t}),\n\toutput: UserSchema.extend({ createdAt: z.string() })\n});\n```\n\n### 2. Implement Your Service\n\nCreate an instance of `ZRPCService` and add your defined routes with their corresponding business logic (resolvers).\n\n```typescript\n// src/service-app.ts (or your main application file)\nimport { ZRPCService } from './service';\nimport { GetUserRoute, CreateUserRoute, UserSchema } from './schemas'; // Adjust path\n\nconst myService = new ZRPCService({\n\tname: 'UserService',\n\tport: 3000 // Or use 0 for a random available port\n});\n\n// Resolver for GetUserRoute\nmyService.addRoute(GetUserRoute, async (input) => {\n\t// In a real application, you would fetch data from a database\n\tif (input.id === '123') {\n\t\treturn { id: '123', name: 'John Doe', email: 'john.doe@example.com' };\n\t}\n\tthrow new Error('User not found');\n});\n\n// Resolver for CreateUserRoute\nmyService.addRoute(CreateUserRoute, async (input) => {\n\t// In a real application, save data to a database\n\tconst newUser = { ...input, id: 'new-id-' + Date.now(), createdAt: new Date().toISOString() };\n\tconsole.log('New user created:', newUser);\n\treturn newUser;\n});\n\n// Start the service\nmyService.start().then(() => {\n\tconsole.log(`User Service started on port ${myService.port}`);\n});\n\n// Optionally, generate OpenAPI spec\n// const openApiSpec = myService.generateOpenAPI();\n// console.log(JSON.stringify(openApiSpec, null, 2));\n```\n\n### 3. Define and Export Your SDK\n\nWithin your service package, define and export an object containing your API routes. This object serves as the type-safe SDK definition that other projects can consume.\n\n```typescript\n// packages/your-service/src/api/sdk.ts (or similar, within your service package)\nimport { clientFactory } from '@6edesign/zrpc';\nimport { GetUserRoute, CreateUserRoute } from '../schemas'; // Adjust path to your route definitions\n\n// Define a collection of routes that form your service's API\nconst userServiceApiRoutes = {\n\tgetUser: GetUserRoute,\n\tcreateUser: CreateUserRoute\n};\n\n// Export a function that, when called with SDKOptions, returns the type-safe client\nexport const createUserServiceSDK = clientFactory(userServiceApiRoutes);\n```\n\n### 4. Consume the SDK in Another Project\n\nIn a separate application or repository, import the SDK definition and use `clientFactory` to create a type-safe client instance.\n\n```typescript\n// packages/another-app/src/index.ts (or your frontend application)\nimport { createUserServiceSDK } from '@6edesign/your-service'; // Import the SDK creation function from your service package\n\n// Create an SDK instance pointing to your service\nconst userServiceClient = createUserServiceSDK({\n\tbaseUrl: 'http://localhost:3000' // Or the actual URL of your deployed service\n});\n\n// Example: Fetch a user\nuserServiceClient\n\t.getUser({ id: '123' })\n\t.then((user) => console.log('Fetched user:', user))\n\t.catch((error) => console.error('Error fetching user:', error.message));\n\n// Example: Create a user\nuserServiceClient\n\t.createUser({ name: 'Jane Doe', email: 'jane.doe@example.com' })\n\t.then((newUser) => console.log('Created user:', newUser))\n\t.catch((error) => console.error('Error creating user:', error.message));\n```\n\n## OpenAPI Generation\n\nOne of the core features of `@6edesign/zrpc` is its ability to automatically generate OpenAPI (Swagger) documentation directly from your Zod schemas and route definitions. This ensures your API documentation is always in sync with your code.\n\n### Basic Generation\n\nBy default, `ZRPCService` will generate a basic OpenAPI specification for all registered routes. You don't need any extra configuration to get started.\n\n```typescript\n// Example: Basic OpenAPI generation\nimport { z } from './src/zod';\nimport { createRoute } from './src/router';\nimport { ZRPCService } from './src/service';\n\nconst SimpleUserSchema = z.object({\n\tid: z.string(),\n\tname: z.string()\n});\n\nconst getSimpleUserRoute = createRoute({\n\tpath: '/simple-users/{id}',\n\tmethod: 'get',\n\tinput: z.object({ id: z.string() }),\n\toutput: SimpleUserSchema\n});\n\nconst service = new ZRPCService({ name: 'SimpleService', port: 0 });\nservice.addRoute(getSimpleUserRoute, async (input) => ({ id: input.id, name: 'Test User' }));\n\nconst openApiSpec = service.generateOpenAPI();\n// This `openApiSpec` will contain a basic definition for /simple-users/{id}\n```\n\nThis will generate a basic OpenAPI definition for your `/simple-users/{id}` endpoint, inferring parameters and responses from your `input` and `output` schemas.\n\n### Customizing Schemas with `.openapi()`\n\nYou can enrich the documentation for your Zod schemas by using the `.openapi()` method. This allows you to add `description`, `example` values, and register schemas as reusable components in the OpenAPI document's `components/schemas` section.\n\n```typescript\nimport { z } from './src/zod';\n\nconst ProductSchema = z\n\t.object({\n\t\tproductId: z.string().uuid().openapi({\n\t\t\tdescription: 'Unique identifier for the product',\n\t\t\texample: 'a1b2c3d4-e5f6-7890-1234-567890abcdef'\n\t\t}),\n\t\tname: z.string().min(3).openapi({\n\t\t\tdescription: 'Name of the product',\n\t\t\texample: 'Super Widget'\n\t\t}),\n\t\tprice: z.number().positive().openapi({\n\t\t\tdescription: 'Price of the product in USD',\n\t\t\texample: 99.99\n\t\t})\n\t})\n\t.openapi('Product', {\n\t\t// Register as a component named 'Product'\n\t\tdescription: 'Detailed information about a product'\n\t});\n\n// This schema will appear in #/components/schemas/Product\n// with the provided descriptions and examples.\n```\n\n### Customizing Routes with `openapi` Property (Escape Hatch)\n\nFor more granular control over the generated OpenAPI operation (e.g., `summary`, `tags`, `operationId`), you can provide an `openapi` property directly within your `createRoute` options. This acts as an escape hatch to directly influence the OpenAPI [Operation Object](https://swagger.io/docs/specification/describing-operations/).\n\n**Important:** `@6edesign/zrpc` automatically infers parameters and request bodies from your `input` schemas. You should generally _not_ need to manually define `parameters` or `requestBody` within this `openapi` property unless you have very specific, non-standard requirements.\n\n```typescript\nimport { createRoute } from './src/router';\nimport { z } from './src/zod';\nimport { ProductSchema } from './path/to/your/schemas'; // Assuming ProductSchema is defined elsewhere\n\nconst getProductDetailsRoute = createRoute({\n\tpath: '/products/{productId}',\n\tmethod: 'get',\n\tinput: z.object({ productId: z.string().uuid() }),\n\toutput: ProductSchema,\n\topenapi: {\n\t\tsummary: 'Retrieve product details',\n\t\tdescription: 'Fetches comprehensive details for a specific product by its ID.',\n\t\ttags: ['Products', 'Public API'],\n\t\toperationId: 'getProductDetailsById',\n\t\tparameters: [\n\t\t\t{\n\t\t\t\tname: 'productId',\n\t\t\t\tin: 'path',\n\t\t\t\trequired: true,\n\t\t\t\tdescription: 'The unique identifier of the product',\n\t\t\t\tschema: { type: 'string', format: 'uuid' }\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'includeReviews',\n\t\t\t\tin: 'query',\n\t\t\t\trequired: false,\n\t\t\t\tdescription: 'Include customer reviews in the response',\n\t\t\t\tschema: { type: 'boolean' }\n\t\t\t}\n\t\t],\n\t\tresponses: {\n\t\t\t200: { description: 'Product details retrieved successfully' },\n\t\t\t404: { description: 'Product not found' }\n\t\t}\n\t}\n});\n```\n\n## API Reference\n\nTODO: Link to comprehensive API documentation (e.g., TypeDoc generated).\n\n## Advanced Usage\n\n- **Using Request-level Context:**\n  You can provide an asynchronous `context` function to the `ZRPCService` constructor. This function is executed for every incoming request, allowing you to inject request-specific data, such as a user session, into your route handlers. The return value of this function becomes the `context` object available in your resolvers.\n\n  ```typescript\n  import { ZRPCService } from '@6edesign/zrpc';\n  import { lucia, User, Session } from './lucia'; // Your Lucia auth setup\n\n  // Define the shape of your context\n  interface MyContext {\n  \tsession: { user: User | null; session: Session | null };\n  }\n\n  const service = new ZRPCService<MyContext>({\n  \tname: 'AuthenticatedService',\n  \tport: 3001,\n  \tasync context(req) {\n  \t\tconst cookieHeader = req.headers.cookie ?? '';\n  \t\tconst sessionId = lucia.readSessionCookie(cookieHeader);\n  \t\tif (!sessionId) {\n  \t\t\treturn { session: { user: null, session: null } };\n  \t\t}\n  \t\tconst { session, user } = await lucia.validateSession(sessionId);\n  \t\treturn { session: { user, session } };\n  \t}\n  });\n\n  // The `context` object in the resolver will be fully typed\n  service.addRoute(someProtectedRoute, async (input, context) => {\n  \tif (!context.session.user) {\n  \t\tthrow new Error('UNAUTHORIZED');\n  \t}\n  \t// ... your logic here\n  });\n  ```\n\n- **Integrating with a Message Bus:**\n  `ZRPCService` can integrate with a message bus by passing an instance of `@6edesign/messenger.BaseDistributedEventBus` to its constructor. The service will then listen for messages on a queue named `${serviceName}ServiceQueue` and route them to the appropriate `addRoute` resolver based on the message `key`.\n\n- **Customizing Logger:**\n  You can provide a custom logger conforming to the `Logger` interface to the `ZRPCService` constructor. This allows you to integrate with your preferred logging solution (e.g., Winston, Pino).\n\n- **Configuring CORS and Compression:**\n  Control CORS (Cross-Origin Resource Sharing) and response compression by setting `useCors` and `useCompression` boolean options in the `ZRPCService` constructor. Both are `true` by default.\n\n## Development\n\n- **Building:** `pnpm turbo build --filter=@6edesign/zrpc`\n- **Testing:** `pnpm turbo test --filter=@6edesign/zrpc`\n\n## Contributing\n\n(Standard section with guidelines for contributing to the project, e.g., code of conduct, how to submit issues/PRs.)\n\n## License\n\n(Standard section detailing the project's license.)\n","readmeFilename":"README.md"}