document.js

1.4.11 • Public • Published

document.js

Circle CI
npm version
Code Climate

Getting started

Install it

$ npm install document.js

Require it

var store = decidingFactor ? 'mongo' : 'memory';
 
Document = require('document.js/lib/index')({store: store});

Use it

Channel = Document.progeny('Channel', {
}, {
  classMethods: {
    fields: {
      String: { slug: 's', name: 'n', token: 't' },
      Date: { firstMessageAt: 'fma' },
      Integer: { keepAlive: 'ka', buffered: 'b', capped: 'c' },
      Object: { info: 'i' }
    },
    belongsTo: ['user'],
    // hasMany: ['messages'], TODO
    allow: ['name', 'token', 'userId', 'firstMessageAt', 'buffered', 'capped'],
    validate: {
      presence: ['name', 'userId'],
      format: { slug: /^#\w{4,16}/ },
      custom: [
        function() { return Object.keys(this.get('info')).length > 0 }
      ]
    },
    beforeCreate: [
      function() {
        this.set('token', '{{random token generator}}');
      }
    ]
  }
});

For the full API see the document definition docs.

Package Sidebar

Install

npm i document.js

Weekly Downloads

1

Version

1.4.11

License

MIT

Last publish

Collaborators

  • bnorton