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

deco-brick-rpc

v0.2.9

Published

a decorator style rpc micro-service

Downloads

35

Readme

deco-brick-rpc

A simple、quick-start rpc micro-service framework

Concept

Only grpc is avaliable now.

There are GrpcServerIBrickServiceGrpcClientEtcdDiscoveryClientConatiner for useage.

GrpcServer

server config

{
  host: HOST
  port: PORT,
  protoPath: PROTOPATH,
  discovery: // optional, a EtcdDiscovery class object
}

server usage

protobuf file example as below:

syntax = "proto3";
package test;
service Test {
	rpc check (req) returns (res) {}
}
message req {
	string data = 1;
}
message res {
	string status = 1;
}

Create a server

typescript code:

import { GrpcServer, IBrickService } from "deco-brick-rpc";

class TestService implements IBrickService {
  public name: string =  "Test";
  public async check(params: any): Promise<object> {
    return { status: "success" };
  }
}

const test = new GrpcServer({
  port: 50051,
  protoPath: __dirname + "/test.proto",
});
test.setServices([ TestService ]);
test.start();

javascript code:

const brick = require('deco-brick-rpc')
class TestService {
  constructor() {
    this.name = 'Test'
  }
  async check(params) {
    return { status: "success" };
  }
}
const app = new brick.GrpcServer({
    port: 50051,
    protoPath: __dirname + "/test.proto",
})
app.setServices([ TestService ])
app.start()

IBrickService

The service interface is for standardization, only used in typescript.

interface IBrickService {
  name: string;
}

GrpcClient

Client share the same protobuf file as server.

client config

{
  protoPath: PROTOPATH,
  host: HOST, // optional when using discovery
  port: PORT, // optional when using discovery
  discovery: // optional, a EtcdDiscovery class object
}

client usage

Here is a client demo typescript code:

import { GrpcClient } from "deco-brick-rpc";
const log = console.log;

const rpc = new GrpcClient({
  port: 50051,
  protoPath: __dirname + "/test.proto",
});

log("package name: ", rpc.packageName);

rpc.client.Test.check().sendMessage({data: "you"}).then((data: any) => {
  log(data);
}).catch((e: any) => {
  log(e.message);
});

javascript code:

const brick = require('deco-brick-rpc')
const log = console.log;

const rpc = new brick.GrpcClient({
  port: 50051,
  protoPath: __dirname + "/test.proto",
});

log("package name: ", rpc.packageName);

rpc.client.Test.check().sendMessage({data: "you"}).then((data: any) => {
  log(data);
}).catch((e: any) => {
  log(e.message);
});

EtcdDiscovery

You can use etcd as a discovery centre for multiple application.

discovery config

{
  namespace: NAMESPACE,
  url: ETCD_URL // e.g. "localhost:2379"
}

server usage

typescript code:

import { EtcdDiscovery, GrpcServer, IBrickService } from "deco-brick-rpc";

class TestService implements IBrickService {
  public name: string =  "Test";
  public async check(params: any): Promise<object> {
    return { status: "server 1 success" };
  }
}

const test = new GrpcServer({
  discovery: new EtcdDiscovery({
    namespace: "deco",
    url: "localhost:2379",
  }),
  port: 50051,
  protoPath: __dirname + "/../test.proto",
});
test.setServices([ TestService ]);
test.start();

client usage

typescript code:

import { EtcdDiscovery, GrpcClient } from "deco-brick-rpc";
const log = console.log;

const rpc = new GrpcClient({
  discovery: new EtcdDiscovery({
    namespace: "deco",
    url: "localhost:2379",
  }),
  protoPath: __dirname + "/../test.proto",
});

rpc.client.Test.check().sendMessage({data: "you"}).then((data: any) => {
  log(data);
}).catch((e: any) => {
  log(e.message);
});

ClientConatiner

rpc client will depend on several rpc server usally, use ClientConatiner for that.

auto-select rpc type by the suffix of protofile, support grpc only for now.

typescript code

import { ClientConatiner, EtcdDiscovery } from "deco-brick-rpc";
const log = console.log;

const discovery = new EtcdDiscovery({
  namespace: "deco",
  url: "localhost:2379",
});
const rpc = new ClientConatiner({
  discovery,
  protoDirPath: __dirname + "/../protos",
});
// 'test' is the package name in protofile
rpc.clients.test.Test.check().sendMessage({data: "you"}).then((data: any) => {
  log(data);
}).catch((e: any) => {
  log(e.message);
});

examples

TODO

  • etcd watch
  • thrift support