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

poseidon

v0.3.2

Published

Simplify Node Callback APIs with an optimized promise layer that doesnt compromise on performance.

Downloads

19

Readme

Poseidon

Poseidon is a tiny module which can generate a promise layer over an existing callback API for easier programming.

The performance of the generated api is on par with simple callbacks.

Simple Callbacks x 762 ops/seca ±1.51% (85 runs sampled)
Poseidon x 757 ops/sec ±1.39% (87 runs sampled)
Fastest is Simple Callbacks,Poseidon

How to generate an API

Poseidon uses a simple configuration file to generate an api. It creates a proxy class that holds a reference to the original object on this.instance. The proxy class also has all the methods of the original object in its prototype. Each of the proxy functions wrap the original function using Bluebird promises. Once the api is generated you can output the generated javascript to a file.

Sample configuration file from poseidon-mongo:

"Collection": {
    // Files to require and their location. The paths provided should be relative to the folder that the generated files are written to.
    // Bluebird promises are required by default in every generated file. It can be accessed through 'Promise'.
    "require": {
      "Mongo": "mongodb",
      "Cursor": "./cursor"
    },
    // You can write a custom constructor to wrap the original object that is passed to it. The original object should be stored on 'this.instance' always
    "constructor": {
      "params": ["collection"],
      "body": """
      if (!(collection instanceof Mongo.Collection)) {
        throw new Error('Object must be an instance of Mongo Collection');
      }
      this.instance = collection;
      return;
      """
    },
    // The instance is a simple object
    "type": "object",
    "functions": {
      "insert": {},
      "remove": {},
      "save": {},
      "update": {},
      "distinct": {},
      "count": {},
      "drop": {},
      "find": {
        // Don't wrap the find with a promise returning function
        "wrap": false,
        // Convert the return value to a Cursor class
        "return": ["Cursor"]
      },
      "findAndModify": {},
      "findAndRemove": {},
      "findOne": {},
      "createIndex": {},
      "ensureIndex": {},
      "indexInformation": {},
      "dropIndex": {},
      "dropAllIndexes": {},
      "reIndex": {},
      "mapReduce": {},
      "group": {},
      "options": {},
      "isCapped": {},
      "indexExists": {},
      "geoNear": {},
      "geoHaystackSearch": {},
      "indexes": {},
      "aggregate": {},
      "stats": {},
      "rename": {
        "return": ["Collection"]
      }
    }
  },
  "Cursor": {
    "require": {
      "Mongo": "mongodb"
    },
    "constructor": {
      "params": ["cursor"],
      "body": """
      if (cursor.constructor.name !== 'Cursor') {
        throw Error('Object must be an instance of Mongo Cursor');
      }
      this.instance = cursor;
      return;
      """
    },
    "type": "object",
    "functions": {
      "toArray": {},
      "each": {},
      "count": {},
      "nextObject": {},
      "explain": {},
      "close": {},
      "stream": {
        "wrap": false
      },
      "isClosed": {
        "wrap": false
      },
      "rewind": {
        "wrap": false,
        // The function will return a reference to the wrapping class allowing you to chain methods. Note: Chained methods should have wrap set to 'false'
        "chain": true
      },
      "sort": {
        "wrap": false,
        "chain": true
      },
      "setReadPreference": {
        "wrap": false,
        "chain": true
      },
      "skip": {
        "wrap": false,
        "chain": true
      },
      "limit": {
        "wrap": false,
        "chain": true
      },
      "batchSize": {
        "wrap": false,
        "chain": true
      }
    }
  },
  "Database": {
    "require": {
      "Driver": "./driver",
      "Collection": "./collection",
      "Cursor": "./cursor"
    },
    "constructor": {
      "params": ["connectionName"],
      "body": """
      this.connectionName = connectionName;
      this.instance = Driver.openConnection(connectionName);
      return;
      """
    },
    // The instance is a promised object
    "type": "promise",
    "functions": {
      "db": {},
      "collectionNames": {},
      "eval": {},
      "dereference": {},
      "logout": {},
      "authenticate": {},
      "addUser": {},
      "removeUser": {},
      "command": {},
      "dropCollection": {},
      "lastError": {},
      "previousErrors": {},
      "resetErrorHistory": {},
      "createIndex": {},
      "ensureIndex": {},
      "cursorInfo": {},
      "dropIndex": {},
      "reIndex": {},
      "indexInformation": {},
      "dropDatabase": {},
      "stats": {},
      "close": {},
      "collection": {
        "return": ["Collection"]
      },
      "collections": {
        "return": [
          // The value is an array of Collection items.
          {
            "name": "Collection"
            "array": true
          }
        ]
      },
      "createCollection": {
        "return": ["Collection"]
      },
      "renameCollection": {
        "return": ["Collection"]
      },
      "collectionsInfo": {
        "return": ["Cursor"]
      },
    }
  }
}

Modules using Poseidon

If you want to get your module listed here, just let me know at [email protected].

License

The MIT License

Copyright(c) 2013-2014, Playlyfe Technologies, [email protected], http://dev.playlyfe.com/