Giter VIP home page Giter VIP logo

fastify-cote's Introduction

fastify-cote

Fastify plugin for work with Cote easier by adding decorator & helpers for reply-mechanism.

Installation

Using npm:

$ npm i --save fastify-cote

Registering Plugins

const fastify = require('fastify')();
const fastify_cote = require('fastify-cote');
const CoteRequester = require('cote').Requester;
const CoteResponder = require('cote').Responder;

fastify.register(fastify_cote, {
    requester: {
        decorator: 'getRequest',
        instances: {
            first: new CoteResponder({ name: 'request' }),
            server: new CoteResponder({ name: 'request' })
        }
    },
    responder: {
        instance: 'runService' || new CoteResponder({ name: 'respond' }),
        decorator: 'run',
        actions: {
            updateUser: {
                event: 'user.update',
                listener: async function (payload) {
                    // code for update user
                    // access fastify instance using `this`
                }
            }
        }
    }
});

Explaination

module.exports = {

    requester: {
        // Can only be 'string', you would access using `fastify.getRequester(name);` 
        decorator: 'getRequester',
        instances: {
            // Must be key, `cote.requester` instances
            first: new CoteResponder({ name: 'request' }),
            server: new CoteResponder({ name: 'request' })
        },

        /*
            When trying access requester with these denifition using
            > const response = await fastify.getRequester('first').send({
            >    type: 'event',
            >    payload: {
            >        ...data
            >    }
            > });
        */
    },
    responder: {
        // Can be `string` or `cote.responder` instances
        instance: 'respond' || new CoteResponder({ name: 'respond' }),
        
        // Can only be 'string', you would access using `fastify.run(action, payload);` 
        decorator: 'runService',

        actions: {

            // A custom name for let you access faster or easier when using `decorator`
            updateUser : {

                // Target server-side event name when requesting
                event: 'update.user',
                
                // Run action when someone `requesting` this or accessing using `fastify.run();`
                listener: async function (payload) {
                    // access fastify instance using `this`
                }
            }
        }
        /*
            When trying access responder with these denifition using
            > const response = await fastify.runService('updateUser', { name: 'oska' });

            Responder will receive the whole object as payload
            * when accessing using requester, 'payload' only passed into listener.
        */
    }
};

Changelog

  • 0.0.1 Release
  • 0.0.2 Update requester method to async or non-async
  • 0.0.3 Fix missing services issues
  • 0.0.4 Fix emmiter issues
  • 0.0.5 Planning new & better structure after tested
  • 0.1.0 Better and new structure
  • 0.1.1 Fix minor issues
  • 0.1.5 Added multiple requester
  • 0.1.6 Fix minor issues
  • 0.1.8 Invalid passing listener
  • 0.1.9 Missing payload when run service

Maintainers

fastify-cote's People

Contributors

dependabot[bot] avatar oskang09 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

r0lodex plcgi1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.