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 🙏

© 2026 – Pkg Stats / Ryan Hefner

z-seneca-extended

v1.3.8

Published

Extend seneca library with additional features

Downloads

0

Readme

Extends senecajs microservice library: offhandedly, with respect

seneca-extended

npm coveralls deps travis

What is it and what is for

When i started building application using senecajs framework, i didn't find the easy ways to solve some of problems:

  • ability to use promises
  • throw errors on server and catch them by client (with custom payload)
  • initialize plugins on asynchronius way before load them into framework
  • log messages in own format instead of verbose seneca output
  • some other stuff

This wrapper try to solve most of this troubles, offering common interface without changing the basic functionality in my own way.

WARN: this module don't works in nodejs <6.x (no time for babel, feel free to pull reques with babel support if you need earlier versions support)

Install

$ npm install seneca-extended

Test

$ npm run test

Quck Example

const ld = require('lodash')
const seneca = require('../src')()
// `seneca` is fully usable seneca instance with build-in additional features

/** default senecajs plugin **/
const basicPlugin = function (config) {

  this.add({ role: 'example', method: 'ping' }, (message, done) => {
    // in case of exception here - error will not pass to remote client
    done(null, { ping: 'pong'} )
  })

  this.add('role:example,method:error', (message, done) => {
    this.emitError(new Error('this error will be passed to client'), done)
  })
}

/** extended plugin **/
const route = {
  ping: 'role:example,method:ping',
  error: 'role:example,method:error'
}
const extendedPlugin = {
  name: 'example', // exported routes will be available in: seneca.routes.example.*
  routes: ld.pick(route, ['ping']) // will export only route 'ping' for example
  init: function (senecaInstance, config) {
    // this method will be called on plugin load, async code can be used here
    return Promise.delay(300)
  },
  seneca: function (config) {
    // basoc seneca route add
    this.add('role:example,method:sometest', (message, done) => done(null, { ping: 'sometes'} ))
    this.addAsync(route.ping, message => {
      // we are in promise now, so can just return result - all error will be handled
      return { ping: 'pong' }
    })
    this.addAsync(route.error, message => {
      const error = new Error('this error will be passed to client')
      error.payload = { additional: 'payload' } // we can evend add payload
      throw error
    })
  },
  someOther: function () {
    // we can export other method for futher usage
    // ex.: route schemas/specifications, helper methods etc
  }
}


const sampleOptions = { some: 'config' }

// now seneca able to load not only synchronous code...
seneca.useAsync(basicPlugin, sampleOptions) // same as synchronous seneca.use
seneca.actAsync('role:example,method:error').catch(err => {
  console.log('catched from error:', err.message)
})

// ... but also preload plugins methods as promises
seneca.useAsync(extendedPlugin, sampleOptions).then(() => {
  console.log('async plugins loaded and usable now')
  // 'role:example,method:ping'
  seneca.actAsync(seneca.example.ping, { some: 'payload' }).then(res => {
    console.log('got from ping:', res)
  })
})

// Output:
// async plugins loaded and usable now
// catched from error: this error will be passed to client
// got from ping: { ping: 'pong' }

Advanced example: custom microservice with deployment into kubernetes, configuration files and common launcher - micro-test (maybe outdated)

API

Core documentation available at oficial API page. Following methods are added by seneca-extended and not usable without this module:

.addAsync(route, promisifiedCallback)

Extened version of seneca.add with promisified callback.

.useAsync(plugin, [config]) -> Promise

Extened version of seneca.use with ability to load promisified plugins.

.emitError(Error, callback)
this.add('...', (message, done) => {
  try {
    // some code
    done()
  } catch (err) {
    // now remote clients will catch this error
    this.emitError(err, done)
  }
})
.actCustom(...)

Extended version of seneca.act with error catching (useful if you dont need response)

.actAsync

Promisified version of seneca.actCustom.

seneca.actAsync('some:route').then(console.log).catch(console.log)
.logger.warn, .logger.debug, .logger.info, .logger.error

Lightweight logger without default seneca verbosity (should be, just lightweight now :) .