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

v0.0.18

Published

An easy way to run a mock gRPC server.

Downloads

44

Readme

grpc-server-mock

An easy way to run a mock gRPC server.

Installation

npm install -g grpc-server-mock

Usage

Usage: grpc-server-mock <command> [options]

Commands:
  grpc-server-mock start:autowire       Autowires grpc server mock using the mock folder
  grpc-server-mock start:config         Creates gRPC server mock using given config
  grpc-server-mock generate:config      Targets autowire folder and generates JSON config from it

Start from auto-wire folder

Starts the server from the given autowire config. An example can be found in the examples folder.

grpc-server-mock start:autowire

Options:

--host     Server host.                                                       [default: "127.0.0.1"]
--port     Server port.                                                           [default: "50051"]
--folder   Path to folder with files for autowireing.                                 [default: "."]
--silent   If set, noop logger will be used                               [boolean] [default: false]
--delay    Delay in milliseconds before returning response.                           [default: "0"]
--ordered  If set, responses will be ordered instead of random.           [boolean] [default: false]
--matched  If set, received inputs will be matched to provided outputs.     [boolean][default:false]

Expected format:

|-- <autowire root folder>
|   |-- <arbitrary folder name that contains proto file and responses>
|   |   |-- <service_from_your_proto>
|   |   |   |-- <your_service_method_name1.json>
|   |   |   |-- <your_service_method_name2.json>
|   |   |-- <_otherservice_from_your_proto>
|   |   |   |-- <your_other_service_method_name1.json>
|   |   |   |-- <your_other_service_method_name2.json>
|   |   |   |-- <your_other_service_method_name3.json>
|   |   `-- <your.proto>
|   |-- <another arbitrary folder name that contains proto file and responses>
|   |   |-- <service_from_your_other_proto>
|   |   |   |-- <your_service_method_name1.json>
|   |   |   |-- <your_service_method_name2.json>
|   |   |-- <_otherservice_from_your_other_proto>
|   |   |   |-- <your_other_service_method_name1.json>
|   |   |   |-- <your_other_service_method_name2.json>
|   |   |   |-- <your_other_service_method_name3.json>
|   |   `-- <your_other.proto>
`

If your service is defined via multiple proto files, please provide the root.json file with the following format:

{
  "root":"<root_proto_name(proto where the service is defined)>.proto"
}

Service method json format for default mode:

[
  {
    "your_message_field_1": "<value>",
    "your_message_field_2": "<value>",
  },
  {
    "your_message_field_1": "<value>",
    "your_message_field_2": "<value>",
  }
]

Service method json format for --matched mode:

[
  {
    "input": {
      "your_message_field_1": "<value>"
    },
    "output": {
      "your_message_response_field_1": "<value>",
      "your_message_response_field_2": "<value>"
    },
  },
  {
    "input": {
      "your_message_field_2": "<value>",
      "your_message_field_3": "<value>"
    },
    "output": {
      "your_message_response_field_2": "<value>"
    },

    /**
    * Optional field.
    * If set, actual request value
    * will be regex matched against the provided input.
    */
    "regexMatch": true
  }
]

If you wish to ignore certain folders that dont contain method response files, you can do so by adding the ignoreServiceFolders array field in the aforementioned root.json.

The following example will not take the folder common into consideration, when crafting responses, but it will still load .proto files from it.

{
  "ignoreServiceFolders": ["common"]
}

Custom Loader Options

If you wish to pass custom loader options, provide a loaderOptions.json next to you .proto file. See the list of options in the @grpc/proto-loader package.

Start from config

Starts the server from the target config.

grpc-server-mock start:config

Options:

--folder   Path to file with config.                    [default: "./grpc-server-mock.json"]
--silent   If set, noop logger will be used                       [boolean] [default: false]

GenerateConfigCommand

Generates Config file from target autowire folder.

grpc-server-mock generate:config

Options:

--host     Server host.                                                       [default: "127.0.0.1"]
--port     Server port.                                                           [default: "50051"]
--folder   Path to folder with files for autowireing.                                 [default: "."]
--output   Desired path to output file.                         [default: "./grpc-server-mock.json"]
--delay    Delay in milliseconds before returning response.                           [default: "0"]
--ordered  If set, responses will be ordered instead of random.           [boolean] [default: false]
--matched  If set, received inputs will be matched to provided outputs.     [boolean][default:false]