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

fastify-cote

v0.1.9

Published

Fastify Cote decorator & helper for reply mechanism plugins

Downloads

26

Readme

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