{"id":21064182,"url":"https://github.com/moveaxlab/grpc-gen","last_synced_at":"2026-04-21T10:03:29.622Z","repository":{"id":222483336,"uuid":"757407170","full_name":"moveaxlab/grpc-gen","owner":"moveaxlab","description":"Opinionated utilities to generate TypeScript code from prorobuf files.","archived":false,"fork":false,"pushed_at":"2024-07-26T08:20:38.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-21T06:40:00.675Z","etag":null,"topics":["grpc","protobuf","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moveaxlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-14T12:39:08.000Z","updated_at":"2024-07-26T08:20:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8fb92f4-9108-4e41-bcba-311feb36a184","html_url":"https://github.com/moveaxlab/grpc-gen","commit_stats":null,"previous_names":["moveaxlab/grpc-gen"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgrpc-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgrpc-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgrpc-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moveaxlab%2Fgrpc-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moveaxlab","download_url":"https://codeload.github.com/moveaxlab/grpc-gen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243507045,"owners_count":20301797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grpc","protobuf","typescript"],"created_at":"2024-11-19T17:48:42.709Z","updated_at":"2026-04-21T10:03:29.547Z","avatar_url":"https://github.com/moveaxlab.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gRPC gen\n\n![NPM License](https://img.shields.io/npm/l/%40moveaxlab%2Fgrpc-gen)\n![NPM Version](https://img.shields.io/npm/v/%40moveaxlab%2Fgrpc-gen)\n\nThis package contains some opinionated utility functions to generate TypeScript types\nfrom protobuf files, to interact with gRPC services and protobuf in general.\n\nThe goal of this package is to avoid the code bloat caused by generating JS code:\nwe prefer to rely on packages like `@grpc/proto-loader` to generate code\nat runtime from raw `.proto` files.\nFor this reason we want to generate only TypeScript types,\nand let other packages generate the code needed to parse protobuf messages.\n\n## Installation\n\n```bash\nyarn add --dev @moveaxlab/grpc-gen\n```\n\n## Usage\n\nThis tool comes with opinionated defaults on how protobuf files must be structured\nand how code will be generated.\n\nThe expected directory structure is the following:\n\n```\nprotobuf/\n  common/\n    file1.proto\n    file2.proto\n  service1/\n    file1.proto\n    file2.proto\n  service2/\n    file1.proto\n    file2.proto\n```\n\nTo generate code:\n\n```bash\nyarn grpc-gen -i \u003cprotobuf directory\u003e -o \u003coutput directory\u003e [services ...]\n```\n\nOmitting the `services` positional argument will generate code for all services\ncontained in the `protobuf directory` option.\n\nThe output directory will contain an index file with types for all packages,\nand a `Parser.ts` file that allows you to manually decode and encode\nprotobuf messages in a type safe way.\n\nTo use the parser:\n\n```typescript\nimport { Parser } from \"./__generated__/Parser\";\n\n// obtain a parser for a generated package\nconst packageParser = Parser.forPackage(\"mypackage\");\n\n// use the parser to encode and decode protobuf data\nconst encodedBuffer = packageParser.encode(\"myType\", {\n  /* data */\n});\nconst decodedValue = packageParser.decode(\"myType\", encodedBuffer);\n```\n\nThe parser relies on `@grpc/proto-loader` to load protobuf definitions at runtime,\nand must be configured before usage to know where protobuf models are:\n\n```typescript\nimport { join, dirname } from \"path\";\nimport { setModelsFolder, addIncludeDir } from \"./__generated__/Parser\";\n\nsetModelsFolder(\n  process.env.NODE_ENV === \"production\" ? \"/app/protobuf\" : \"../../protobuf\",\n);\n\naddIncludeDIr(\n  process.env.NODE_ENV == \"production\"\n    ? \"/app/node_modules/grpc-tools/bin\"\n    : join(dirname(require.resolve(\"grpc-tools\")), \"bin\"),\n);\n```\n\nGenerated types are compatible with [`@moveaxlab/nestjs-grpc-client`](https://github.com/moveaxlab/nestjs-grpc-client).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoveaxlab%2Fgrpc-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoveaxlab%2Fgrpc-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoveaxlab%2Fgrpc-gen/lists"}