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

hansa

v1.0.2

Published

Create leagues of Argosy micro-service endpoints

Downloads

5

Readme

hansa

NPM version Build Status Coverage Status

Create leagues of Argosy micro-services; connected via pipes.

example

var argosy = require('argosy'),
    hansa  = require('hansa')

var service1 = argosy(),
    service2 = argosy(),
    client   = argosy(),
    league   = hansa()

service1.accept({ greet: argosy.pattern.match.string }).process(function (msg, cb) {
    cb(null, 'Greetings ' + msg.greet)
})

service2.accept({ max: argosy.pattern.match.array }).process(function (msg, cb) {
    cb(null, Math.max.apply(null, msg.max))
})

league.connect([service1, service2, client], function () {
    client.invoke({ greet: 'Gege' }, function (err, message) {
        console.log(message)

        client.invoke({ max: [3, 9, 7] }, function (err, max) {
            console.log('The biggest number is: ' + max)
        })
    })
})

api

var league = hansa()

league.connect(argosyEndpoint)

Connect an Argosy endpoint to the league. This is a convenience function that does for you:

var port = league.port()
argosyEndpoint.pipe(port).pipe(argosyEndpoint)

In addition it maintains relationship between endpoint and port to make disconnection easier. Attempting to connect the same endpoint twice will have no effect.

league.disconnect(argosyEndpoint)

Disconnect an Argosy endpoint from the league. This is a convenience function that does for you:

argosyEndpoint.unpipe(port)

... where the league knows the port, so that you do not need to maintain a reference to it.

var leagueStream = league.createStream()

Add an unpaired Argosy stream to the league, to be connected to another Argosy endpoint or hansa league. This behaves just like any other Argosy stream, except it appears to provide all services that are provided by any Argosy endpoint piped to a league port. It's possible to connect two league objects this way, by piping them together.

Example of manually connecting an Argosy stream to a league (without using league.connect):

var league = require('hansa')(),
    argosy = require('argosy')()

argosy.pipe(league.createStream()).pipe(argosy)

Only one Argosy stream should be connected to a given Hansa league stream. Upon connecting, the league will request to be notified of services offered by (now or in the future) the Argosy stream, and any Argosy stream connected to the league will see those services, as well as the services of all other connected streams

league.connectionOpened(cb)

An eventuate representing a new Argosy stream being connected to the league. Handler functions, cb, associated with the eventuate receive the local (league-side) Argosy stream.

league.connectionClosed(cb)

An eventuate representing an Argosy stream being disconnected from the league. Handler functions, cb, associated with the eventuate receive the local (league-side) Argosy stream.

league.connectionFailed(cb)

An eventuate representing a failure while attempting to connect a new Argosy stream to the league. Handler functions, cb, associated with the eventuate receive the local (league-side) Argosy strean.

league.patternAdded(cb)

An eventuate representing a new service pattern being defined by one of the Argosy streams belonging to the league. Handler functions, cb, associated with the eventuate receive the Argosy pattern object.

league.patternRemoved(cb)

An eventuate representing the removal of a previously accepted service pattern. Handler functions, cb, associated with the eventuate receive the Argosy pattern object.

league.error(cb)

An eventuate representing an error condition within the league. Handler functions associated with this eventuate receive the Error object as the payload. This eventuate requires consumption, i.e. if no handler is associated with this eventuate when an Error is produced, the Error will be thrown.

league.id

The unique ID (UUID) of the league.

league.connections

An array containing all streams created via league.createStream().

league.patterns

An array of all service patterns (represented by Argosy pattern objects) offered by the league.

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.