{"id":19168551,"url":"https://github.com/xanthous-tech/typescript-grpc","last_synced_at":"2025-05-07T14:42:18.190Z","repository":{"id":43974329,"uuid":"248529576","full_name":"xanthous-tech/typescript-grpc","owner":"xanthous-tech","description":"a minimalistic annotation-based typescript library to help build grpc servers and clients.","archived":false,"fork":false,"pushed_at":"2022-06-02T21:36:46.000Z","size":537,"stargazers_count":14,"open_issues_count":10,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-31T11:02:39.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/xanthous-tech.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}},"created_at":"2020-03-19T14:51:31.000Z","updated_at":"2023-09-08T18:04:44.000Z","dependencies_parsed_at":"2022-09-14T00:52:38.043Z","dependency_job_id":null,"html_url":"https://github.com/xanthous-tech/typescript-grpc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xanthous-tech%2Ftypescript-grpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xanthous-tech%2Ftypescript-grpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xanthous-tech%2Ftypescript-grpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xanthous-tech%2Ftypescript-grpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xanthous-tech","download_url":"https://codeload.github.com/xanthous-tech/typescript-grpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249830834,"owners_count":21331355,"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":[],"created_at":"2024-11-09T09:43:05.158Z","updated_at":"2025-04-19T23:31:20.485Z","avatar_url":"https://github.com/xanthous-tech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typescript-grpc\n\na minimalistic annotation-based typescript library to help build grpc servers and clients.\n\n# Usage\n\n```\n$ yarn add typescript-grpc protobufjs grpc @grpc/proto-loader --save\n```\n\nSee [src/example.ts](src/example.ts)\n\n```typescript\nimport debug from 'debug';\nimport { Type, Field, Message } from 'protobufjs';\nimport { load } from '@grpc/proto-loader';\nimport { Server, ServiceDefinition, ServerCredentials } from 'grpc';\n\nimport { Service, Method, generateProto, wrapServiceMethods } from 'typescript-grpc';\n\nconst log = debug('typescript-grpc:example');\n\n@Type.d()\nclass Movie extends Message\u003cMovie\u003e {\n  @Field.d(1, 'string')\n  name: string;\n\n  @Field.d(2, 'int32')\n  year: number;\n\n  @Field.d(3, 'float')\n  rating: number;\n\n  @Field.d(4, 'string', 'repeated')\n  cast: string[];\n}\n\n@Type.d()\nclass MoviesResult extends Message\u003cMoviesResult\u003e {\n  @Field.d(1, Movie, 'repeated')\n  result: Movie[];\n}\n\n@Type.d()\nclass EmptyRequest extends Message\u003cEmptyRequest\u003e {}\n\n@Type.d()\nclass SearchByCastInput extends Message\u003cSearchByCastInput\u003e {\n  @Field.d(1, 'string')\n  castName: string;\n}\n\n@Service()\nclass ExampleService {\n  @Method({\n    requestType: 'EmptyRequest',\n    requestStream: false,\n    responseType: 'MoviesResult',\n    responseStream: false,\n  })\n  async getMovies(req: EmptyRequest): Promise\u003cMoviesResult\u003e {\n    log('get movies called');\n    return new MoviesResult({ result: [] });\n  }\n\n  @Method({\n    requestType: 'SearchByCastInput',\n    requestStream: false,\n    responseType: 'Movie',\n    responseStream: true,\n  })\n  searchMoviesByCast(req: SearchByCastInput): Observable\u003cMovie\u003e {\n    const movies = [\n      {\n        cast: ['Tom Cruise', 'Simon Pegg', 'Jeremy Renner'],\n        name: 'Mission: Impossible Rogue Nation',\n        rating: 0.97,\n        year: 2015,\n      },\n      {\n        cast: ['Tom Cruise', 'Simon Pegg', 'Henry Cavill'],\n        name: 'Mission: Impossible - Fallout',\n        rating: 0.93,\n        year: 2018,\n      },\n      {\n        cast: ['Leonardo DiCaprio', 'Jonah Hill', 'Margot Robbie'],\n        name: 'The Wolf of Wall Street',\n        rating: 0.78,\n        year: 2013,\n      },\n    ];\n\n    return from(movies.filter(movie =\u003e movie.cast.indexOf(req.castName) \u003e -1).map(m =\u003e new Movie(m)));\n}\n\nasync function main(): Promise\u003cvoid\u003e {\n  const service = new ExampleService();\n  log(service);\n\n  const protoPath = await generateProto('example');\n\n  const packageDefinition = await load(protoPath);\n\n  const server = new Server({\n    'grpc.max_send_message_length': -1,\n    'grpc.max_receive_message_length': -1,\n  });\n\n  server.addService(packageDefinition[service.constructor.name] as ServiceDefinition\u003cany\u003e, wrapServiceMethods(service));\n  server.bind('0.0.0.0:50051', ServerCredentials.createInsecure());\n  server.start();\n\n  log(`server started`);\n}\n\nmain();\n\n```\n\n# Features\n\n- Modern service method handlers via Promise and rxjs streams\n- Auto proto generation using annotations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxanthous-tech%2Ftypescript-grpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxanthous-tech%2Ftypescript-grpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxanthous-tech%2Ftypescript-grpc/lists"}