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

vesicle

v1.0.4

Published

High performance and flexible RPC framework for Node.JS

Downloads

8

Readme

vesicle

NPM Version Node Version

High performance and flexible RPC framework for Node.JS

Installation

npm i vesicle -S

Usage

  • typescript
// server
import { Action, Factory, Module, Service } from 'vesicle';

@Service()
class Book {
  @Action()
  hi() {
    console.log('hello');
  }

  @Action()
  hi2() {
    throw new Error('asdad');
  }

  @Action()
  hello() {
    return 'hello';
  }
}

@Module([Book])
class AppModule {}

function bootstrap() {
  const app = Factory.create(AppModule);
  app.listen(6960);
}

bootstrap();

// client
import { Client } from 'vesicle';

const myclient = new Client({
  url: '172.19.2.10:6960,172.19.2.10:6971,192.168.1.61:6960'
});

myclient
  .call('book.hi')
  .then(ret => {
    console.log(ret);
  })
  .catch(err => {
    console.error(err);
  });
  • javascript
import { Server } from 'vesicle';
import { responseTime, LRU } from 'vesicle/middleware';

const server = new Server({ nodeID: 'node1' });

server.addAction({
  name: 'list',
  handler: () => {
    console.log(1);
  }
});

server.addAction({
  name: 'book.hello',
  handler: () => {
    return 'hello';
  }
});

server.addAction({
  name: 'book.hi',
  handler: async () => {
    await sleep(1000);
    return 'sleep hi';
  },
  use: responseTime
});

server.addAction({
  name: 'book.cache',
  handler: async () => {
    await sleep(5000);
    return 'cache book';
  },
  use: [responseTime, LRU]
});

server.addAction({
  name: 'book.hi2',
  handler: async () => {
    throw new Error('hi2');
  }
});

function sleep(delay = 1000) {
  return new Promise(resolve => setTimeout(resolve, delay));
}

server.listen(6960);

API

server

new Server({nodeID?: string; port?: number;})

create a server instance

.addAction( action: Action | Handler, service?: string, version?: string ): boolean

add a defined funtion

.listen(port: number)

start listen on specific port

client

new Client({ url: string; timeout?: number; retry?:number;connectTimeout?: number;})

url: entry url, combine with servers's url

timeout: max wait time for response

retry: retry times, when network error occurs, retry request

.call(action: string,parameter?: any,options: CallOptions = { retry: this.retry }): Promise<any>

invoke a remote funtion

Middleware

type Middleware = (context: Context, next: NextFunc) => any;

write style

export async function responseTime(context: Context, next: NextFunc) {
  let start = Date.now();
  await next();
  console.log(`${context.action.name} took:${Date.now() - start}ms`);
}
  • [x] responseTime
  • [x] LRU
  • [ ] auth
  • [ ] rate limiter
  • [ ] compress

Cluster

join in another node

import { request } from '../src/helper';

// join in a cluster
request(`172.19.2.10:6960/join`, { addr: '172.19.2.10:6970' })
  .then(ret => {
    console.log(ret);
  })
  .catch(err => {
    console.error(err);
  });

cluster infos

import { request } from '../src/helper';

// display cluster info
request(`172.19.2.10:6960/nodes`)
  // request(`172.19.2.10:6960/actions`)
  // request(`172.19.2.10:6960/connections`)
  .then(ret => {
    console.log(ret);
  })
  .catch(err => {
    console.error(err);
  });

Todo

  • [ ] xxx

License

MIT