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

argosy-service

v2.0.2

Published

Easily create micro-services.

Downloads

5

Readme

argosy-service

NPM version Build Status Coverage Status Davis Dependency Status

Deprecated

Use argosy instead. This module is no longer maintained as a separate entity.

Easily create micro-services.

Part of the Argosy family.

example

var service = require('argosy-service')(),
    match   = require('argosy-pattern/match'),
    client  = require('argosy-client')

// connect the client to the service
client.pipe(service).pipe(client)

// create the service
service.message({ greet: match.string }).process(function (msg, cb) {
    cb(null, 'Hello ' + msg.greet)
})

// use the service
client.invoke({ greet: 'Jason' }, function (err, result) {
    console.log(result)
})

or with promises...

// create the service
service.message({ greet: match.string }).process(function (msg) {
    return Promise.resolve('Hello ' + msg.greet)
})

// use the service
client.invoke({ greet: 'Jason' }).then(console.log)

api

var argosyService = require('argosy-service')

service = argosyService()

Create a new service object. The service object is a stream intended to be connected (piped) to Argosy clients through any number of intermediary streams.

queue = service.message(pattern)

Create a concurrent-queue that will be pushed messages that match the pattern object provided (see argosy-pattern for details on defining patterns). These messages should be processed and responded to using the process function of the queue. Responses will be sent to the connected/requesting client.

It is advised not to match the key argosy as this is reserved for internal use.

built-in message handlers

{argosy: 'info'}

All services created will respond to messages that match {argosy: 'info'}. The response payload will be:

{
    role: 'service',
    implemented: [
        'encoded argosy pattern 1',
        'encoded argosy pattern 2',
        '...'
    ]
}

The implemented array will contain encoded argosy-pattern's for which the service will respond.

service stream messages

service request

Incoming requests are structured like so:

{
    type: 'request',
    headers: { client: { id: 'uuid', seq: 0 } },
    body: {}
}

Where:

  • headers can be anything you want to send, the service will send them back exactly as they were. This is useful for correlating responses with requests. The argosy-client sends a client UUID and a request sequence number in the headers to correlate responses.
  • body contains the message that the service will match against

service response

Outbound responses are structured like so:

{
    type: 'response',
    headers: { client: { id: 'uuid', seq: 0 } },
    body: {},
    error: { message: '', stack: '' }
}

Where:

  • headers matches whatever headers object was supplied by the client to allow the client to correlate responses with requests on it's end
  • body contains the response from the service message implementation
  • error will be undefined unless an error occured in which case it will contain an object with the error message and stack

new service message implementation

When a new message pattern for the service is defined, a notify-implemented message object will be emitted from the service stream. This allows connected listers to be made aware of new message implementations. The structure of this message is:

{
    type: 'notify-implemented',
    body: 'encoded argosy pattern'
}

testing

npm test [--dot | --spec] [--grep=pattern]

Specifying --dot or --spec will change the output from the default TAP style. Specifying --grep will only run the test files that match the given pattern.

coverage

npm run coverage [--html]

This will output a textual coverage report. Including --html will also open an HTML coverage report in the default browser.