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

methodulus

v1.0.16

Published

<a href="https://travis-ci.org/nodulusteam/methodulus"> <img src="./examples/resources/methodulus.png" alt="Drawing" style="max-width: 200px!important;"/> </a>

Downloads

36

Readme

Methodulus

motivation

  • we want microservices!
  • we need a dynamic system architecture!
  • we want it all!

automatic server to server connectivity using a dynamic rpc transport layer

npm i -S methodulus

Hello methodulus

This example creats a rest (express based) server using a controller class Player

it is configured to run the class code locally via an http server.

import { Player } from './controllers/player';
import { ServerConfig, ClientConfig, ConfiguredServer, MethodType, ServerType } from 'methodulus';

@ServerConfig(ServerType.Express, { port: process.env.PORT || 8020 })
@ClientConfig(Player, MethodType.Local)
class SetupServer extends ConfiguredServer {

}

new SetupServer();

the Player class

import { Body, Method, MethodConfig, MethodType, Param, Query, Verbs, MethodError, MethodResult } from 'methodulus';
import { PlayerModel } from '../models/player';


@MethodConfig('Player')
export class Player {
    @Method(Verbs.Post, '/api/player')
    public async create() {
        let p = new PlayerModel('1', 'player 1');
        await DB.Player.insert(p);
        return new MethodResult(p)
    }

    @Method(Verbs.Get, '/api/player/:player_id')
    public async read( @Param('player_id') playerId: number) {
        return await DB.Player.find({ 'Id': playerId });
    }

    @Method(Verbs.Put, '/api/player')
    public async update() {

    }


    @Method(Verbs.Delete, '/api/player')
    public delete() {

    }



}

Classes & API

ConfiguredServer

this class is the base class for the server implementation. it uses the Server & Client decorators to apply the desired configuration.

@Server(ServerType, options)

syntetic suger for MethodulusConfig.run() function.

@Client(ClassType, MethodType, resolver?)

syntetic suger for MethodulusConfig.use() function.

MethodulusConfig

configuration must complete before the server starts. configure each controller class to its desired state

let config = new MethodulusConfig()

.run(ServerType, options)

the run method determines what kind of server to run on the listening part of the application. to listen to REST request you should run ServerType.Expess and to listen to redis channel use ServerType.Redis .

ServerType

  • Express
  • Redis
  • MQ
  • Socket

.use(classType, MethodType, resolver)

the use method registers the way a class should be activated. the first parameter is a class decorated with methodulus decoratos.

MethodType

avaliable options are Local | Http | MQ | Socket | Redis

  • Local run the code in the class, no proxy or transport required.

  • Http run the code using an http request to a microservice.

  • MQ use amqp rpc to execute the class code

  • Socket directly connect to a server using websocket connection.

  • Redis use redis rpc to execute the class code

Resolver

in order to access the correct service methodulus uses a resolver, which may be a literal containing the service uri or a promise returning the same.

resolvers are attached to a class, allowing the application to use different resolvers for different services.

Available servers

an instamce of methodulus can run multiple listeners in different channels. the current list is:

  • express
  • socketio
  • amqp
  • redis

here is a simple local configuration: The class Player will execute locally.

let servers = ['express']; 
let config = new MethodulusConfig(servers);
let resolver = 'http://127.0.0.1:8090';
config.run(ServerType.express, {port: process.env.PORT })
config.use(TestClass, MethodType.Local,resolver);

Server

creates an agnostic configured server.

const server = new Server(process.env.PORT);

Server methods are chainable and should e called in this order

const server = await new Server(process.env.PORT).configure(config).start();

Decorators

Class decorators

@MethodConfig

decorating a class with the decorator will turn it into a methodulus end point.

@MethodulusConfig(applicationname, [middlewares]?)

@Method

Each decorated method in the MethodConfig decorated class will become a function endpoint of the methodulus application.

@Method(Verb, route, [middlewares])

Parameter decorators

a decorated method should use the following parameter decorators to indicate the source of each argument.

@Query

@Param

@Body

@Request

@Response