npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grpc-ts-gen

v0.2.1-rc.1

Published

[![npm](https://img.shields.io/npm/v/grpc-ts-gen)](https://www.npmjs.com/package/grpc-ts-gen) [![npm downloads](https://img.shields.io/npm/dm/grpc-ts-gen)](https://www.npmjs.com/package/grpc-ts-gen) [![Coverage Status](https://coveralls.io/repos/github/

Downloads

6

Readme

grpc-ts-gen

npm npm downloads Coverage Status

grpc-ts-gen is a tool for generating a typed grpc server and client from protobuf descriptors.

This means that the only thing needed for implementing a GRPC service is implementing a simple typescript interface.

Given this protobuf definition

syntax = "proto3";

package example.HelloService;

message HelloRequest {
	string hello = 1;
}

message HelloResponse {
	string world = 1;
}

service HelloService {
	rpc Hello(HelloRequest) returns (HelloResponse);
}

This is the only code needed to implement a server

import { ProtoServer } from "./sample-out/ProtoServer";
import { IHelloService, HelloRequest, HelloResponse } from "./sample-out/Example/HelloService"
import { GrpcResponseError } from "grpc-ts-gen";
import * as grpc from "@grpc/grpc-js";

let server = new ProtoServer(new grpc.Server());

class HelloService implements IHelloService {
	async Hello(request: HelloRequest): Promise<HelloResponse> {
		if (request.hello != "hello") {
			throw new GrpcResponseError("Expected hello", grpc.status.INVALID_ARGUMENT)
		}
		return {world: "world"};
	}
}

server.AddHelloService(new HelloService());

Installation & Usage

grpc-ts-gen is tested for node 18.x.x but will probably work for earlier version. However, for now 18.x.x is the only officially supported version, this will be changed later when all features are implemented.

Install using:

npm install grpc-ts-gen

This is not just a dev dependency, since this library also contains a small helper library for the generated code.

Generate definitions using:

npx grpc-ts-gen --proto-base-path <root protobuf path> --out-path <output folder>

Options

grpc-ts-gen has many options to customize the generated code. A table of the options can be seen here

| Name | Description | Required | |------|-------------|----------| | proto-base-path | The base path for protobuf definition files | ✔️ | | out-path | The base path for the generated files | ✔️ | | server-name | The name of the file where the generated server is defined | ❌ | | request-body-as-object | Supply the request object as parameters as a handler instead of an object | ❌ |

These options can also be defined in a JSON file called grpc-ts-gen.config.json, here they are named with camelCase instead of kebab-case.

// grpc-ts-gen.config.json
{
	"protoBasePath": "../OpenIdle-Connect/protos",
	"outPath": "testout",
	"serverName": "OpenIdle",
	"requestBodyAsObject": true
}

The option source is prioritized in this way

  1. CLI option
  2. Config file option
  3. Default value

This means that any option supplied by the command line will overwrite the config file option.