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

genesis

v1.0.0

Published

A simple library for creating data models in Node.

Downloads

5

Readme

genesis

Build Status

A simple library for creating data models in Node.

npm install genesis

Basics

Genesis.create (options)

Creates a new Model class.

  • options -- A hash of options describing a new data model.

Options:

  • index -- The name of the attribute that should be used as the unique identifier of an instance. Defaults to null.
  • methods -- A hash of methods to add to instances. Defaults to {}.
  • parent -- The parent class that the new model should extend. Defaults to Model.
  • schema -- A Joi schema describing acceptable model attributes. Defaults to Joi.any().

Returns a constructor function.

Constructor.extend (options)

  • options -- A hash of options describing additional attributes for the new data model.

Options:

  • index -- The name of the attribute that should be used as the unique identifier of an instance. Defaults to the parent model's index.
  • methods -- A hash of additional methods to add to instances. This hash is merged with the methods from the parent model.
  • schema -- A Joi schema describing acceptable model attributes. This schema is merged with the parent model's schema.

For Advanced Uses

Model (schema, attributes)

Creates a new model instance. A model is an immutable object with a pre-defined set of attributes and methods.

  • schema -- A Joi schema describing the acceptable attributes.
  • options -- A hash of attributes to assign to the instance.

Returns a new model instance.

Mappers

Mappers implement persistence strategies for models and can be used to store and retrieve model instances. All mappers follow the some API and all models that are used with mappers must define an index.

The Mapper API

mapper.create (instance)

Persists a new model instance. An error is thrown if the instance already exists in the underlying data store.

  • instance -- A Model instance to persist.

Returns the instance.

mapper.destroy (instance)

Removes a model instance from the data store. An error is thrown if the instance has not been persisted in the data store.

  • instance -- A Model instance to persist.

Returns the instance.

mapper.find (Constructor, query)

Finds all persisted instances of Constructor that matches the query object.

  • Constructor -- A Model constructor function indicating the type of instance that should be retrieved.
  • query -- A hash of attributes used to match persisted instances.

Returns a list of matching instances.

mapper.findOne (Constructor, query)

Finds one matching instance of Constructor that matches the query object.

  • Constructor -- A Model constructor function indicating the type of instance that should be retrived.
  • query -- A hash of attributes used to match persisted instances.

Returns a single matching instance.

mapper.update (instance)

Persists a new version of a previously persisted model instance. An error is thrown if a previous version is not in the data store.

  • instance -- The new Model instance.

Returns the instance.

Mapper Implementations

Genesis comes with the following mapper implementations:

MemoryMapper ()

The MemoryMapper stores all instances in memory.

MongoMapper (dbUrl)

The MongoMapper stores all instances in a Mongo database. If no dbUrl is specified, the default mongodb://localhost/test is used.