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-mock

v0.7.0

Published

a simple grpc mock server

Downloads

8,021

Readme

grpc-mock

npm version

A simple mock gRPC server on Node.js.

const {createMockServer} = require("grpc-mock");
const mockServer = createMockServer({
  protoPath: "/path/to/greeter.proto",
  packageName: "greeter",
  serviceName: "Greeter",
  rules: [
    { method: "hello", input: { message: "test" }, output: { message: "Hello" } },
    { method: "goodbye", input: ".*", output: { message: "Goodbye" } },
    
    {
      method: "howAreYou",
      streamType: "client",
      stream: [
        { input: { message: "Hi" } },
        { input: { message: "How are you?" } },
      ],
      output: { message: "I'm fine, thank you" }
    },
    
    {
      method: "niceToMeetYou",
      streamType: "server",
      stream: [
        { output: { message: "Hi, I'm Sana" } },
        { output: { message: "Nice to meet you too" } },
      ],
      input: { message: "Hi. I'm John. Nice to meet you" }
    },
    
    {
      method: "chat",
      streamType: "mutual",
      stream: [
        { input: { message: "Hi" }, output: { message: "Hi there" } },
        { input: { message: "How are you?" }, output: { message: "I'm fine, thank you." } },
      ]
    },
    
    { method: "returnsError", input: { }, error: { code: 3, message: "Message text is required"} },
    
    {
      method: "returnsErrorWithMetadata",
      streamType: "server",
      input: { },
      error: { code: 3, message: "Message text is required", metadata: { key: "value"}}
    }
  ]
});
mockServer.listen("0.0.0.0:50051");
syntax="proto3";

package greeter;

service Greeter {
  rpc Hello (RequestGreet) returns (ResponseGreet) {}
  rpc Goodbye (RequestGreet) returns (ResponseGreet) {}
  rpc HowAreYou (stream RequestGreet) returns (ResponseGreet) {}
  rpc NiceToMeetYou (RequestGreet) returns (stream ResponseGreet) {}
  rpc Chat (stream RequestGreet) returns (stream ResponseGreet) {}
}

message RequestGreet {
  string message = 1;
}

message ResponseGreet {
  string message = 1;
}

api

createMockServer({protoPath,packageName,serviceName,options,rules}): grpc-kit.GrpcServer

|arg name|type|required/optional|description| |:-------|:---|:----------------|:----------| |protoPath|String|Required|path to .proto file| |packageName|String|Required|name of package| |serviceName|String|Required|name of service| |options|@grpc/proto-loader.Options|Optional|options for @grpc/proto-loader to load .proto file. In detail, please check here out. Default is null| |rules|Array<Rule>|Required|Array of Rules|

Rule

|prop name|type|required/optional|description| |:-------|:---|:----------------|:----------| |method|String|Required|path to .proto file| |streamType|Enum<"client"|"server"|"mutual">|Optional|Type of stream. Set client if only using client side stream, set server if only using server side stream, and set mutual if using both of client and server side stream. Set null/undefined if not using stream. Default is null| |input|Object|String|Required when streamType is null or server|Specifying an expected input. Raw object or pattern string(RegExp) is available| |output|String|Required when streamType is null or client|Specifying an output to an expected input| |stream|Array<Chunk>|Required when streamType is client, server and mutual|Array of Chunks| |error|Object|Optional|If provided, server will respond with this error object|

Chunk

|prop name|type|required/optional|description| |:-------|:---|:----------------|:----------| |input|Object|String|Required when streamType is client. Optional when streamType is mutual|Specifying an expected input. Raw object or pattern string(RegExp) is available.| |output|Object|Required when streamType is server. Optional when streamType is mutual|Specifying an output to an expected input|