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

minimodel

v0.2.2

Published

Minimal, database agnostic Models for Node.js (and the Browser)

Downloads

20

Readme

NPM version Build Status Coverage Status Dependency Status

browser support

Minimodel

Minimal, database agnostic Models for Node.js and the Browser.

The idea is to implement a Domain Model System that is persitence agnostic, to be used only for validation, type casting, transormations, and business logic. By using minimodel, persintence (if relevant) has to be delegated to an external component (e.g. DAO/Services).

Advantages

  • The same model can be retrieved from different data sources
  • Easily reuse the same models in the Browser
  • Custom persitence allows more fine grained and powerful queries (instead of using an imposed ORM style querying system)

Features

  • Define schemas with a syntax similar to Mongoose's
  • Type checking/casting
  • Defaults
  • Validation
  • Virtuals
  • Custom getters/setters

Usage

var minimodel = require('minimodel');

var Post = minimodel.define({
  id: {
    //the field is a String
    type: String,
    //the field is required
    required: true
  },
  createdDate: {
    type: Date,
    //set the default (can be a value or a function)
    default: function() {
      //the execution context is the field itself
      this.setRaw(new Date());
    }
  },
  visits: {
    type: Number,
    default: 0,
    //do not include during object export using toJson()
    includeInJson: false
    //other options include
    //includeInObject: false
    //includeInDb: false
  },
  //a nested object
  author: {
    //shortcut to define a field
    name: String,
    surname: String,
    fullname: {
      //Virtuals are by default not exported (e.g. using toObject())
      //Virtuals do not have any default getter/setter, neet to define them explicitly
      type: minimodel.Types.Virtual,
      //a custom getter
      get: function() {
        return this.model.author.name + " " + this.model.author.surname;
      },
      //a custom setter
      set: function(val) {
        var parts = val.split(' ');
        this.model.setRaw({
          author: {
            name: parts[0],
            surname: parts[1]
          }
        });
      }
    }
  }
});

//create a post
var post = new Post({
  id: Date.now(),
  author: {
    fullname: "John Doe"
  }
});

//set a field after creation
post.set('author.name', 'Joe');
//or
post.author.name = 'Johnny'

//get a field
console.log(post.get('author.fullname'));
//or
console.log(post.author.name);

Stability

1 - Experimental

Please try it out and provide feedback.

What's new

0.2

  • Breaking changes:
    • validate() is now an async function. A callback could be given as argument otherwise a promise will be returned.

Bitdeli Badge