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

stork-odm

v0.1.18

Published

Stork provides a layer of document management over the CouchDB.

Downloads

9

Readme

#stork Build Status Dependency Status

Stork provides a layer of document management over the CouchDB with multitenant support and the use of CouchDB view indexing to support parent/child relationships.

Inspired by resourceful.

TOC

What's it look like?

var odm = require('stork');

var dburl = 'http://localhost:5984/stork_test'
  , User
  , BlogPost
  , Comment
  ;

User = odm.deliver('user', function() {
  this.sort('lastName', 'firstName');
  this.string('firstName');
  this.string('lastName', { required: true });
  this.string('email', { required: true, format: 'email' });
});

Comment = odm.deliver('comment', function() {
  this.string('title', { required: true });
  this.string('content');
  this.timestamps();

  this.ref('author', User, { required: true });
});

BlogPost = odm.deliver('discussion', function() {
  this.string('title', { required: true });
  this.string('content');
  this.bool('isSticky');
  this.timestamps();
  this.view('byUpdatedOn', ['updatedOn']);

  this.ref('author', User, { required: true });

  this.composes('comments', Comment);

  // DOES NOT EXIST, YET: this.method
  this.method('addComment', function (title, content, author) {
    var comment = Comment.new({
          title: title
        , content: content
        , author: author
        })
      ;
    this.comments.push(comment);
  });

  // DOES NOT EXIST, YET
  this.method('removeComment', function (comment) {
    var childIds = this.children.map(function(child) {
          return child._id
        })
      , childIndex = childIds.indexOf(comment._id)
      ;
    if (childIndex < 0) {
      return;
    }
    this.comments.splice(childIndex, 1);
  });
});

BlogPost.from(dburl).withComments(function(err, posts) {
  posts.forEach(function (post) {
    console.log(post);
    post.comments.forEach(function (comment) {
      console.log('\t', comment);
    });
  });
});

How to use it

This section contains a task-based set of instructions on how to use stork for your CouchDB ODM needs. It models a simple reservation system.

Install stork for your project

Follow the instructions, below, in Installing.

require stork

Yeah, that seems pretty self evident.

var odm = require('stork');

Declare an entity

Let's declare an entity that stork knows about. When we declare entities, we provide a name and, if we want, a function that will describe a schema for us. We can define arrays, booleans, children, date/times, numbers, objects with their own schema, references to other documents, strings, timestamps, and views.

stork uses the schema of the object to provide validation for you. You can save invalid documents to CouchDB, if you'd like. stork does not judge. stork just delivers.

var event = odm.stork('event', function() {
  this.string('name', { required: true, maxLength: 100 });
  this.string('description', { required: true });
  this.object('venue', { required: true }, function() {
    this.string('url', { format: 'url' });
    this.string('name');
    this.string('address', { required: true });
    this.string('city');
    this.string('state');
    this.string('zip', { format: /\d{5}/ });
  });

  this.number('maximumGuests', { required: true });
  this.boolean('cancelled');

  this.array('rsvps');

  this.timestamps();
});

How to contribute

  1. Make sure you have grunt-cli installed.
  2. Clone. You know how. This is GitHub, for goodness' sake.
  3. Install stuff. npm install
  4. Run the autotester. SKIP_STORK_DB_TESTS=1 ./node_modules/autotest/autotest.js --npm
  5. Or, if you want to run with db tests. ```./node_modules/autotest/autotest.js --npm``
  6. Find an issue
  7. Write a test.
  8. Write nice code.
  9. Run grunt and make sure you have no errors either in tests or in jslint.
  10. Commit.
  11. Make a PULL REQUEST if you're not already a contributor.

Installing

Because we're still developing, this ain't on npm, yet. So, right now, you can run the following commands to include it in your project.

git clone https://github.com/realistschuckle/stork.git
cd stork
npm link

Read more about the npm-link command.