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

prodio-orm

v0.0.6

Published

Object Relation Model and Validation module

Downloads

26

Readme

Build Status

Prodio-ORM

The ORM for Prodio is not your standard implementation, it allows for member upgrades and downgrades. To account for this you should check for a member on the root and then in the meta segment if it is not found there.

You can post all of your data on the root of your ojbect and the backend will automatically migrate data that isn't within the ORM root to the meta segment.

Anything posted to the meta segment will NOT be automatically moved to the root.

The ORM does NOT necessarily match up with the API's. This is on purpose since at times there may be necessity to augment the response object(s). A good example of this is the project/{id}/tree endpoint.

This library implements the complete ORM used by Prodio. Yes, any of the other off the shelf solutions could have been modified to work, but writing one that actually fit Prodio just made more sense.

Installation

npm install prodio-orm

API

ORM

ORM(optionalName, proto, noAutoMigrate)

  • optionalName - An optional name you can pass to the ORM creator, used for savers/loaders.
  • proto - The root validator or a plain JavaScript Object.
  • noAutoMigrate - Defaults false, if true members not registered as part of the prototype will not be migrated to the meta member. If set to false then anything not defined in the prototype will be migrated to the meta member.
var ORM = require('prodio-orm');

var Test = new ORM('test', {
    num: ORM.Number()
  });

ORM.Array

ORM.Array(next)

  • next - Optional child validators to be executed.
var Item = ORM.Object({
    name: ORM.String()
  });
var ItemsValidator = ORM(ORM.Array(Item));

ItemsValidator.validate([{name: 'foo'}], function(err, items){
  console.log(err||items);
});

ORM.Boolean

Matches boolean values: true, false, 'true', 'false', 0, 1, '0', '1', 'yes', 'no'

ORM.Boolean()

ORM.Date

Matches an actual Date() Object or a String that validates with Date.parse().

ORM.Date()

ORM.Default

If a value doesn't exist then set the value defaultValue.

ORM.Default(defaultValue, next)

  • defaultValue - The value to use if no value is present.
  • next - Optional validator to use if value exists.

ORM.ID

Validate an Identity value.

ORM.ID(regexp, options)

  • regexp - RegExp Object or String representing a Regular Expression
  • options - If regexp is a String, this is the options passed to new RegExp()

ORM.Nullable

Allow the value to be null, if the value does not exist, then set it to null.

ORM.Nullable(next)

  • next - Optional validator to use if value exists.

ORM.Number

Validate that the passed in value is a Number. If the value is a String representation of a Number then convert it to a Number and use it.

ORM.Number()

ORM.Object

Validate that the passed in value matches the expected Object ORM. Anything member that doesn't fit into the ORM will be stored in the Objects meta member.

ORM.Object(proto, noAutoMigrate)

  • proto - The prototype for the expected object
  • noAutoMigrate - Defaults false, if true members not registered as part of the prototype will not be migrated to the meta member. If set to false then anything not defined in the prototype will be migrated to the meta member.
var Obj = ORM.Object({name: ORM.String()});

Obj.validate({name: 'test', value: 123}, function(err, obj){
  console.log(err||obj);
});

Output would be:

{
  name: 'test',
  meta: {
    value: 123
  }
}

ORM.Optional

Allow the value to be optional. If the value is passed in and there is a next handler then pass the value to next to be validated. If no value is passed in (matches typeof(value) === 'undefined') then call the callback with no value. Checking arguments.length is the best way to validate if a value was present.

ORM.Optional(next)

  • next - Optional validator to use if value exists.

ORM.RegExp

Validate the value with a regular expression.

ORM.RegExp(regexp, options)

  • regexp - RegExp Object or String representing a Regular Expression
  • options - If regexp is a String, this is the options passed to new RegExp()

ORM.Semver

Validate that the value is a valid Semantic Version.

ORM.Semver()

ORM.String

Validates that the passed in value is a valid String. If it is a Number then convert it to a String.

ORM.String(minLength)

  • minLength - Minimum length the string must be.

ORM.Value

Forces a value into a member.

ORM.Value(value)

ORM.validate

Performs the actual validate of the passed in value.

var Item = ORM.Object({
    name: ORM.String()
  });
var ItemsValidator = ORM(ORM.Array(Item));

ItemsValidator.validate([{name: 'foo'}], function(err, items){
  console.log(err||items);
});