{"id":13487663,"url":"https://github.com/eggjs/egg-grpc","last_synced_at":"2025-10-19T21:13:47.996Z","repository":{"id":21364766,"uuid":"92567518","full_name":"eggjs/egg-grpc","owner":"eggjs","description":"grpc plugin for egg","archived":false,"fork":false,"pushed_at":"2021-10-26T09:28:54.000Z","size":32,"stargazers_count":81,"open_issues_count":2,"forks_count":20,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-10-14T12:25:18.440Z","etag":null,"topics":["egg","egg-plugin","eggplugin","grpc"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"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/eggjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-27T03:24:04.000Z","updated_at":"2025-07-17T07:53:53.000Z","dependencies_parsed_at":"2022-09-16T00:20:19.171Z","dependency_job_id":null,"html_url":"https://github.com/eggjs/egg-grpc","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/egg-grpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-grpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-grpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-grpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-grpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-grpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-grpc/sbom","scorecard":{"id":368732,"data":{"date":"2025-08-11","repo":{"name":"github.com/eggjs/egg-grpc","commit":"d142b52c5d3fae86b428fe5648b1fb3d18a42006"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Code-Review","score":2,"reason":"Found 4/16 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 11 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T12:29:15.914Z","repository_id":21364766,"created_at":"2025-08-18T12:29:15.914Z","updated_at":"2025-08-18T12:29:15.914Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279913502,"owners_count":26243070,"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","status":"online","status_checked_at":"2025-10-19T02:00:07.647Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["egg","egg-plugin","eggplugin","grpc"],"created_at":"2024-07-31T18:01:01.791Z","updated_at":"2025-10-19T21:13:47.974Z","avatar_url":"https://github.com/eggjs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Plugins","目录","仓库"],"sub_categories":["插件"],"readme":"# egg-grpc\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-grpc.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-grpc\n[travis-image]: https://img.shields.io/travis/eggjs/egg-grpc.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-grpc\n[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-grpc.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/eggjs/egg-grpc?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-grpc.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-grpc\n[snyk-image]: https://snyk.io/test/npm/egg-grpc/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-grpc\n[download-image]: https://img.shields.io/npm/dm/egg-grpc.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-grpc\n\n[grpc](http://www.grpc.io) plugin for egg\n\n## Install\n\n```bash\n$ npm i egg-grpc --save\n```\n\n```js\n// {app_root}/config/plugin.js\nexports.grpc = {\n  enable: true,\n  package: 'egg-grpc',\n};\n```\n\n## Configuration\n\n```js\n// {app_root}/config/config.default.js\nexports.grpc = {\n  endpoint: 'localhost:50051',\n  // dir: 'app/proto', // proto files dir, relative path\n  // property: 'grpc', // default attach to `ctx.grpc.**`\n  // loadOpts: { convertFieldsToCamelCase: true, }, // message field case: `string user_name` -\u003e `userName`\n};\n```\n\nsee [config/config.default.js](config/config.default.js) for more detail.\n\n## Usage\n\nfixtures:\n\n```bash\napp/proto\n├── egg\n│   └── test\n│       ├── game.proto\n│       └── message.proto\n├── uc\n│   └── test.proto\n└── share.proto\n```\n\n```protobuf\n// app/proto/share.proto\nsyntax = \"proto3\";\n\npackage egg.share;\n\nmessage Status {\n  string code = 1;\n  string err_msg = 2;\n}\n\nservice ShowCase {\n  rpc Echo(Status) returns (Status) {}\n}\n```\n\nquickstart:\n\n```js\n// mount by `package` define, not proto file path\nconst client = ctx.grpc.egg.share.showCase;\nconst result = yield client.echo({ code: 200 });\nconsole.log(result);\n```\n\n### Folder Structure\n\n- default to load proto files from `app/proto`.\n- file path is only use for file manager, it DON'T affect the proto class path at `ctx` and `app`.\n- such as `app/proto/share.proto`, it defined as `package egg;`, so will visit as\n  - `yield ctx.grpc.egg.share.showCase.echo(data, meta, options)`\n  - `new app.grpcProto.egg.share.Status({ code: 200 })`\n  - `new app.grpcProto.egg.share.ShowCase(address)`\n  - `new ctx.grpcProto.egg.share.ShowCase(address)`\n\n### Name Conversion\n\n- [Protobuff Style Guide](https://developers.google.com/protocol-buffers/docs/style)\n- [GRPC Concepts](http://www.grpc.io/docs/guides/concepts.html)\n\n| term        | case at proto      | case when load                     |\n| ----------- | ------------------ | ---------------------------------- |\n| **package** | lowercase with `.` | camleCase if contains `_`          |\n| **service** | PascalCase         | camleCase when initialize at `ctx` |\n| **rpc**     | PascalCase         | camleCase                          |\n| **message** | PascalCase         | PascalCase at `app`                |\n| **field**   | snake_case         | camleCase                          |\n| **enums**   | CONSTANT_CASE      | CONSTANT_CASE                      |\n\n## API\n\n### Custom Options\n\n- {Number} `timeout` - for convenient usage of `deadline`, equals to `{ deadline: Date.now() + timeout }`\n\n### Service \u0026\u0026 Message\n\nYou can get service instance and invoke rpc by `ctx.mypackage.myService.myRpc({ id: 1 })`.\n\nUsually, you don't need to instantiate a message instace, grpc will do it for you, however you can create it by `new app.grpcProto.mypackage.SomeMessage({ id: 1 })`.\n\n### Unary RPC\n\n```js\n/**\n * Unary RPC, such as `rpc Echo(Request) returns (Response) {}`\n * @param {Object} data - data sent to sever\n * @param {Object|grpc.Metadata} [metadata] - metadata, support plain object\n * @param {Object} [options] - { timeout }\n * @return {Promise} response promise chain\n * @see http://www.grpc.io/docs/guides/concepts.html#unary-rpc\n */\n// const client = ctx.grpc.\u003cpackage\u003e.\u003cservice\u003e;\nyield client.echo(data, metadata, options);\nyield client.echo(data, options);\n```\n\n### Client Streaming RPC\n\n```js\n/**\n * Client Streaming RPC, such as `rpc EchoClientStream(stream Request) returns (Response) {}`\n * @param {Object|grpc.Metadata} [metadata] - metadata, support plain object\n * @param {Object} [options] - { timeout }\n * @param {Function} [callback] - callback for response, `(err, response) =\u003e {}`\n * @return {Stream} write stream\n * @see http://www.grpc.io/docs/guides/concepts.html#client-streaming-rpc\n */\nconst stream = client.echoClientStream(meta, options, callback);\n// const stream = client.echoClientStream(callback);\n// const stream = client.echoClientStream(meta, callback);\n// trigger order: metadata -\u003e callback -\u003e status\nstream.once('metadata', meta =\u003e {});\nstream.once('status', status =\u003e {});\nstream.on('error', status =\u003e {});\n// send data to server or end\nstream.write(data1);\nstream.write(data2);\nstream.end(data4);\n```\n\n### Server Streaming RPC\n\n```js\n/**\n * Server Streaming RPC, such as `rpc EchoServerStream(Request) returns (stream Response) {}`\n * @param {Object} data - data sent to sever\n * @param {Object|grpc.Metadata} [metadata] - metadata, support plain object\n * @param {Object} [options] - { timeout }\n * @return {Stream} read stream\n * @see http://www.grpc.io/docs/guides/concepts.html#server-streaming-rpc\n */\nconst stream = client.echoServerStream(data, meta, options);\n// trigger order: metadata -\u003e data -\u003e status -\u003e end\nstream.on('data', response =\u003e {});\nstream.on('end', response =\u003e {});\nstream.once('metadata', meta =\u003e {});\nstream.once('status', status =\u003e {});\nstream.on('error', status =\u003e {});\n```\n\n### Bidirectional Streaming RPC\n\n```js\n/**\n * Bidirectional Streaming RPC, such as `rpc echoStreamStream(stream Request) returns (stream Response) {}`\n * @param {Object|grpc.Metadata} [metadata] - metadata, support plain object\n * @param {Object} [options] - { timeout }\n * @return {Stream} duplex stream\n * @see http://www.grpc.io/docs/guides/concepts.html#bidirectional-streaming-rpc\n */\nconst stream = client.echoStreamStream(meta, options);\n// trigger order: metadata -\u003e data -\u003e status -\u003e end\nstream.on('data', response =\u003e {});\nstream.on('end', () =\u003e {});\nstream.once('metadata', meta =\u003e {});\nstream.once('status', status =\u003e {});\nstream.on('error', status =\u003e {});\n// send data to server or end\nstream.write(data1);\nstream.write(data2);\nstream.end(data3);\n```\n\n## Example\n\nsee [grpc.tests.js](test/grpc.tests.js).\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-grpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-grpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-grpc/lists"}