New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mongoose-schema-model

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-schema-model

Validation and formatting, converting MongooseDB schema definitions to be used in any environment

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

mongoose-schema-model

browser support

Build Status

Small model definitions (MongooseDB style) for composable use in other environments.

  • Share the same model definitions from MongooseDB on the server with your client
  • Use to apply transformations getters/setters between client and REST API (casting form strings as numbers, etc.)
  • Shared validations in server/client

Install

Currently only in npm as commonjs.

npm install mongoose-schema-model

Usage

Using a Mongoose Schema definition, apply getter and setter transformations and validation.


// Declare a schema definition

var Model = require("mongoose-schema-model");

function numberCast (x) { return ~~x; }
function split (x) { return x.split(', '); }

var definitions = {
  year: { type: Number, min: 1900, max: 2014, set: numberCast },
  items: { type: [String], lowercase: true, get: split },

};

var model = Model(definitions);

// `get` applies the `get` transformation
model.get("items", ["hello", "world"]); // "hello, world"

// `set` applies all implicit and `set` transformations, as well as subsequently validating
// the model, post-transform.
var response = model.set("items", ["HELLO", "WORLD"]);
response.value; // `["hello", "world"]`, the implicit `lowercase` transform was applied to each element
response.error; // null

response = model.set("year", "2000"); 
response.value; // `2000`, transforms applied via `set`
response.error ; // null

response = model.set("year", "1550"); 
response.value; // `2000`, transforms applied, via `set`
response.error; // "Path `year` (1550) is less than the minimum allowed value (1900)."

Supported Types

  • Number
  • String
  • [Number]
  • [String]

Supported Properties

Transforms

Validations

License

MIT License

Keywords

mongoose

FAQs

Package last updated on 02 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts