Permalink
Browse files

Removed unwanted spaces and tabs

  • Loading branch information...
IonicaBizau committed Apr 2, 2014
1 parent b787302 commit c2cfca4b06634c5931ff4d1502927836358a4f56
Showing with 212 additions and 212 deletions.
  1. +6 −6 README.md
  2. +2 −2 example/array.js
  3. +1 −1 example/boolean.js
  4. +1 −1 example/buffer.js
  5. +2 −2 example/date.js
  6. +1 −1 example/example.js
  7. +1 −1 example/number.js
  8. +1 −1 example/object.js
  9. +1 −1 example/objectid.js
  10. +3 −3 example/string.js
  11. +6 −6 index.js
  12. +26 −26 lib/adapter.js
  13. +28 −28 lib/apis/mongodb.js
  14. +10 −10 lib/convert.js
  15. +2 −2 lib/default.js
  16. +25 −25 lib/manipulator.js
  17. +16 −16 lib/model.js
  18. +25 −25 lib/options.js
  19. +44 −44 lib/schema.js
  20. +10 −10 lib/validator.js
  21. +1 −1 package.json
View
@@ -10,23 +10,23 @@ var modm = require('modm');
// define a schema
schema = new modm.Schema({field: String});
-
+
// create db connection
model = modm('myDb', {
host: '127.0.0.1',
port: 27017,
server: {pooSize: 5},
db: {w: 1}
});
-
+
// get a collection
myCollection = model('myCollection', schema);
// db operations
myCollection.insert({data: 1}, function (err, item) {
- //...
+ //...
});
-
+
// connect first, otherwise find will return undefined
// instead of a cursor.
model.connect(function (err, db) {
@@ -35,7 +35,7 @@ model.connect(function (err, db) {
//...
});
});
-
+
// ..or access the cursor in the callback
myCollection.find({/*query*/}, function (err, cursor) {
cursor.toArray(function () {
@@ -130,7 +130,7 @@ Results of atomic operations are not validated.
</tr>
</tbody>
</table>
-
+
## License
"THE BEER-WARE LICENSE" (Revision 42):
View
@@ -1,14 +1,14 @@
var modm = require('../index');
var Schema = new modm.Schema({array: {
-
+
type: Array,
required: true,
default: ['a', 'b'],
//validate: function () {},
//manipulate: function () {},
//live: true,
-
+
// INFO only the input gets validated, not the result of an atomic operation
maxLength: 5,
minLength: 1
View
@@ -1,7 +1,7 @@
var modm = require('../index');
var Schema = new modm.Schema({boolean: {
-
+
type: Boolean,
required: true,
default: false
View
@@ -1,7 +1,7 @@
var modm = require('../index');
var Schema = new modm.Schema({buffer: {
-
+
type: Buffer,
required: true,
default: new Buffer('buffer data'),
View
@@ -1,14 +1,14 @@
var modm = require('../index');
var Schema = new modm.Schema({date: {
-
+
type: Date,
required: true,
default: new Date()
//validate: function () {},
//manipulate: function () {},
//live: true
-
+
}});
var test1 = {date: new Date()};
View
@@ -22,7 +22,7 @@ model.connect(function () {
console.log('------------------------------------------------');
console.log('string');
console.log(err || result);
- });
+ });
});
// number
View
@@ -1,7 +1,7 @@
var modm = require('../index');
var Schema = new modm.Schema({number: {
-
+
type: Number,
required: true,
max: 5,
View
@@ -1,7 +1,7 @@
var modm = require('../index');
var Schema = new modm.Schema({object: {
-
+
type: Object,
required: true,
default: {a: 'b'}
View
@@ -3,7 +3,7 @@ var modm = require('../index');
var ObjectID = require('../node_modules/pongo/node_modules/mongodb').ObjectID;
var Schema = new modm.Schema({objectid: {
-
+
type: ObjectID,
required: true,
default: new ObjectID()
View
@@ -1,7 +1,7 @@
var modm = require('../index');
var Schema = new modm.Schema({string: {
-
+
type: String,
required: true,
pre: ' tru',
@@ -24,9 +24,9 @@ var Schema = new modm.Schema({string: {
var test1 = {string: ''};
module.exports = function (model, callback) {
-
+
var document = model('string', Schema);
-
+
document.insert(test1, callback);
console.log('STRING FIND: ' + typeof document.find());
}
View
@@ -3,29 +3,29 @@ var Schema = require('./lib/schema');
var Model = require('./lib/model');
function modm (dbName, options) {
-
+
var db = function (collection, schema) {
return Model(db, collection, schema);
};
-
+
db.options = options;
db.driver = new Pongo(options);
db.connection = null;
db.connect = function (callback) {
-
+
// db is connected
if (this.connection) {
return callback(null, this.connection);
}
-
+
var self = this;
this.driver.connect(dbName, function (err, db) {
-
+
self.connection = err ? null : db;
callback(err, db);
});
};
-
+
return db;
}
View
@@ -13,7 +13,7 @@ function validateValue (value, path, type, paths) {
}
function handleValidation (document, prefix, paths) {
-
+
var result;
var self = this;
@@ -35,7 +35,7 @@ function handleValidation (document, prefix, paths) {
}
for (var field in document) {
-
+
// get field without operators
var _field = field[0] === '$' ? '' : field.replace(/\.\$|\[[0-9]+\]/, '');
@@ -50,70 +50,70 @@ function handleValidation (document, prefix, paths) {
}
if (document[field] && document[field].constructor.name === 'Array' && type !== 'array') {
-
+
for (var i in document[field]) {
-
+
result = validateValue.call(this, document[field][i], path, type, paths);
-
+
if (result[0]) {
return result;
}
-
+
document[field][i] = result[1];
}
} else {
-
+
result = validateValue.call(this, document[field], path, type, paths);
-
+
if (result[0]) {
return result;
}
-
+
document[field] = result[1];
}
}
-
+
return [null, document, paths];
}
function adapter (method, args, docIndex) {
-
+
if (!this._schema || !this._schema.paths) {
return;
}
var self = this;
var args = Array.prototype.slice.call(args);
-
+
// connect to db
if (!self.db.connection) {
-
+
var caller = adapter.caller;
return self.db.connect(function (err, db) {
-
+
caller.apply(self, args);
});
}
-
+
/////////////////////////////////////////////////////////////////////
-
+
// get callback ref
var callback = args[args.length-1];
-
+
// create collection instance
if (typeof this.collection === 'string') {
self.collection = self.db.connection.collection(self.collection);
}
-
+
if (!self.collection[method]) {
return;
}
-
+
// validate the document
if (args[docIndex]) {
-
+
var result = handleValidation.call(self, args[docIndex], '', {});
-
+
if (result[0]) {
var error = new Error(result[0]);
// TODO appropriate status codes
@@ -127,22 +127,22 @@ function adapter (method, args, docIndex) {
if (typeof result[2][field] === 'undefined' && self._schema.paths[field]) {
var value = defaultValue(self._schema.paths[field].type, self._schema.default[field]);
-
+
// handle default value errors
if (value.constructor.name === 'Error') {
return callback(value);
}
// add default value to document
if (method !== 'insert') {
- result[1].$set[field] = value;
+ result[1].$set[field] = value;
} else {
result[1][field] = value;
}
}
}
}
-
+
// check if required fields exists when insert or upsert
// TODO it could be, that not all required fields are in the document on an upsert.
if (self._schema.required && method === 'insert' || (method === 'update' && (args[2] && args[2].upsert || (Object.keys(args[docIndex])[0] || "")[0] !== '$'))) {
@@ -152,10 +152,10 @@ function adapter (method, args, docIndex) {
}
}
}
-
+
args[docIndex] = result[1];
}
-
+
return self.collection[method].apply(self.collection, args);
}
Oops, something went wrong.

0 comments on commit c2cfca4

Please sign in to comment.