Comparing version 1.0.7 to 1.0.8
100
dist/mio.js
@@ -491,3 +491,6 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.mio=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
Collection.prototype.toJSON = function () { | ||
return this.resources; | ||
var array = this.resources; | ||
array.size = this.resources.size; | ||
array.from = this.resources.from; | ||
return array; | ||
}; | ||
@@ -612,2 +615,6 @@ | ||
} | ||
if (this.query.withRelated) { | ||
this.withRelated(this.query.withRelated); | ||
} | ||
} | ||
@@ -640,3 +647,3 @@ | ||
* @param {Mixed=} value | ||
* @returns {module:mio.Query} | ||
* @returns {module:mio.Query|Object} | ||
*/ | ||
@@ -663,3 +670,3 @@ Query.prototype.where = function(where, value) { | ||
* @param {Object} sort | ||
* @returns {module:mio.Query} | ||
* @returns {module:mio.Query|Object} | ||
*/ | ||
@@ -669,6 +676,6 @@ Query.prototype.sort = function(sort) { | ||
if (arguments.length === 0) return query.sort; | ||
query.sort = query.sort || {}; | ||
if (arguments.length === 0) return query.sort; | ||
if (typeof sort === 'object') { | ||
@@ -768,3 +775,3 @@ for (var key in sort) { | ||
* User.get(1).withRelated({ | ||
* posts: { limit: 5 } | ||
* posts: { size: 5 } | ||
* }).exec(function (err, user) { | ||
@@ -785,3 +792,3 @@ * console.log(user.posts.length); // => 5 | ||
if (!query.withRelated) { | ||
if (typeof query.withRelated !== 'object') { | ||
query.withRelated = {}; | ||
@@ -1036,4 +1043,10 @@ } | ||
var attributes = util.pluck(prototype, ['attributes']).attributes; | ||
var plucked = util.pluck(statics, [ | ||
var pluckedPrototype = util.pluck(prototype, [ | ||
'attributes', | ||
'collection' | ||
]); | ||
var attributes = pluckedPrototype.attributes; | ||
var pluckedStatics = util.pluck(statics, [ | ||
'on', | ||
@@ -1043,3 +1056,5 @@ 'before', | ||
'browser', | ||
'use' | ||
'options', | ||
'use', | ||
'collection' | ||
]); | ||
@@ -1065,4 +1080,12 @@ | ||
if (pluckedStatics.options) { | ||
for (var key in pluckedStatics.options) { | ||
if (pluckedStatics.options.hasOwnProperty(key)) { | ||
child.options[key] = pluckedStatics.options[key]; | ||
} | ||
} | ||
} | ||
// define instance attributes using `Resource#attr()` | ||
if (attributes) { | ||
if (pluckedPrototype.attributes) { | ||
for (var attr in attributes) { | ||
@@ -1077,5 +1100,8 @@ if (attributes.hasOwnProperty(attr)) { | ||
if (!statics.collection || typeof statics.collection === 'object') { | ||
child.Collection = Collection.extend({ | ||
Resource: child | ||
}, statics.collection); | ||
pluckedPrototype.collection = pluckedPrototype.collection || {}; | ||
pluckedPrototype.collection.Resource = child; | ||
child.Collection = (this.Collection || Collection).extend( | ||
pluckedPrototype.collection, | ||
pluckedStatics.collection | ||
); | ||
} | ||
@@ -1085,3 +1111,3 @@ | ||
['browser', 'server', 'use'].forEach(function (key) { | ||
plucked[key] && plucked[key].forEach(function (plugin) { | ||
pluckedStatics[key] && pluckedStatics[key].forEach(function (plugin) { | ||
child[key](plugin); | ||
@@ -1092,9 +1118,9 @@ }); | ||
// register hooks | ||
for (var events in plucked.before) { | ||
child.before(event, plucked.before[event]); | ||
for (var events in pluckedStatics.before) { | ||
child.before(event, pluckedStatics.before[event]); | ||
} | ||
// register event listeners | ||
for (var event in plucked.on) { | ||
child.on(event, plucked.on[event]); | ||
for (var event in pluckedStatics.on) { | ||
child.on(event, pluckedStatics.on[event]); | ||
} | ||
@@ -1318,2 +1344,3 @@ | ||
* @param {Error} err | ||
* @param {module:mio.Resource=} resource | ||
*/ | ||
@@ -1333,9 +1360,9 @@ return this.trigger('get', new Query({ state: query }), callback); | ||
*/ | ||
Resource.put = function (query, rep, callback) { | ||
Resource.put = function (query, representation, callback) { | ||
if (arguments.length === 1) { | ||
rep = query; | ||
representation = query; | ||
return new Query({ | ||
handler: function (query, callback) { | ||
this.put(query, rep, callback); | ||
this.put(query, representation, callback); | ||
}, | ||
@@ -1352,3 +1379,3 @@ context: this | ||
* @param {module:mio.Query} query | ||
* @param {Object|module:mio.Resource} representation | ||
* @param {Object|module:mio.Resource} representationresentation | ||
* @param {module:mio.Resource.trigger.next} next | ||
@@ -1365,3 +1392,3 @@ * @param {module:mio.Resource} resource included if triggered by instance. | ||
* @param {module:mio.Query} query | ||
* @param {Object|module:mio.Resource} representation | ||
* @param {Object|module:mio.Resource} representationresentation | ||
* @param {module:mio.Resource} resource included if triggered by instance. | ||
@@ -1377,4 +1404,7 @@ * @this {module:mio.Resource} | ||
* @param {Error} err | ||
* @param {module:mio.Resource} resource | ||
*/ | ||
return this.trigger('put', new Query({ state: query }), rep, callback); | ||
return this.trigger('put', new Query({ | ||
state: query | ||
}), representation, callback); | ||
}; | ||
@@ -1443,4 +1473,7 @@ | ||
* @param {Error} err | ||
* @param {module:mio.Resource} resource | ||
*/ | ||
return this.trigger('patch', new Query({ state: query }), changes, callback); | ||
return this.trigger('patch', new Query({ | ||
state: query | ||
}), changes, callback); | ||
}; | ||
@@ -1490,2 +1523,3 @@ | ||
* @param {Error} err | ||
* @param {module:mio.Resource} resource | ||
*/ | ||
@@ -1547,3 +1581,5 @@ return this.trigger('post', representation, callback); | ||
*/ | ||
return this.trigger('delete', new Query({ state: query }), callback); | ||
return this.trigger('delete', new Query({ | ||
state: query | ||
}), callback); | ||
}; | ||
@@ -1984,11 +2020,5 @@ | ||
Resource.prototype.post = function (callback) { | ||
return this.trigger('post', this.changed(), function (err, representation) { | ||
if (err) return callback.call(this, err); | ||
var representation = this; | ||
if (representation) { | ||
this.reset(representation); | ||
} | ||
callback.apply(this, arguments); | ||
}); | ||
return this.trigger('post', this.changed(), callback); | ||
}; | ||
@@ -1995,0 +2025,0 @@ |
@@ -482,3 +482,6 @@ var Query = require('./query'); | ||
Collection.prototype.toJSON = function () { | ||
return this.resources; | ||
var array = this.resources; | ||
array.size = this.resources.size; | ||
array.from = this.resources.from; | ||
return array; | ||
}; | ||
@@ -485,0 +488,0 @@ |
@@ -77,2 +77,6 @@ module.exports = Query; | ||
} | ||
if (this.query.withRelated) { | ||
this.withRelated(this.query.withRelated); | ||
} | ||
} | ||
@@ -105,3 +109,3 @@ | ||
* @param {Mixed=} value | ||
* @returns {module:mio.Query} | ||
* @returns {module:mio.Query|Object} | ||
*/ | ||
@@ -128,3 +132,3 @@ Query.prototype.where = function(where, value) { | ||
* @param {Object} sort | ||
* @returns {module:mio.Query} | ||
* @returns {module:mio.Query|Object} | ||
*/ | ||
@@ -134,6 +138,6 @@ Query.prototype.sort = function(sort) { | ||
if (arguments.length === 0) return query.sort; | ||
query.sort = query.sort || {}; | ||
if (arguments.length === 0) return query.sort; | ||
if (typeof sort === 'object') { | ||
@@ -233,3 +237,3 @@ for (var key in sort) { | ||
* User.get(1).withRelated({ | ||
* posts: { limit: 5 } | ||
* posts: { size: 5 } | ||
* }).exec(function (err, user) { | ||
@@ -250,3 +254,3 @@ * console.log(user.posts.length); // => 5 | ||
if (!query.withRelated) { | ||
if (typeof query.withRelated !== 'object') { | ||
query.withRelated = {}; | ||
@@ -253,0 +257,0 @@ } |
@@ -193,4 +193,10 @@ var Collection = require('./collection'); | ||
var attributes = util.pluck(prototype, ['attributes']).attributes; | ||
var plucked = util.pluck(statics, [ | ||
var pluckedPrototype = util.pluck(prototype, [ | ||
'attributes', | ||
'collection' | ||
]); | ||
var attributes = pluckedPrototype.attributes; | ||
var pluckedStatics = util.pluck(statics, [ | ||
'on', | ||
@@ -201,3 +207,4 @@ 'before', | ||
'options', | ||
'use' | ||
'use', | ||
'collection' | ||
]); | ||
@@ -223,6 +230,6 @@ | ||
if (plucked.options) { | ||
for (var key in plucked.options) { | ||
if (plucked.options.hasOwnProperty(key)) { | ||
child.options[key] = plucked.options[key]; | ||
if (pluckedStatics.options) { | ||
for (var key in pluckedStatics.options) { | ||
if (pluckedStatics.options.hasOwnProperty(key)) { | ||
child.options[key] = pluckedStatics.options[key]; | ||
} | ||
@@ -233,3 +240,3 @@ } | ||
// define instance attributes using `Resource#attr()` | ||
if (attributes) { | ||
if (pluckedPrototype.attributes) { | ||
for (var attr in attributes) { | ||
@@ -244,5 +251,8 @@ if (attributes.hasOwnProperty(attr)) { | ||
if (!statics.collection || typeof statics.collection === 'object') { | ||
child.Collection = Collection.extend({ | ||
Resource: child | ||
}, statics.collection); | ||
pluckedPrototype.collection = pluckedPrototype.collection || {}; | ||
pluckedPrototype.collection.Resource = child; | ||
child.Collection = (this.Collection || Collection).extend( | ||
pluckedPrototype.collection, | ||
pluckedStatics.collection | ||
); | ||
} | ||
@@ -252,3 +262,3 @@ | ||
['browser', 'server', 'use'].forEach(function (key) { | ||
plucked[key] && plucked[key].forEach(function (plugin) { | ||
pluckedStatics[key] && pluckedStatics[key].forEach(function (plugin) { | ||
child[key](plugin); | ||
@@ -259,9 +269,9 @@ }); | ||
// register hooks | ||
for (var events in plucked.before) { | ||
child.before(event, plucked.before[event]); | ||
for (var events in pluckedStatics.before) { | ||
child.before(event, pluckedStatics.before[event]); | ||
} | ||
// register event listeners | ||
for (var event in plucked.on) { | ||
child.on(event, plucked.on[event]); | ||
for (var event in pluckedStatics.on) { | ||
child.on(event, pluckedStatics.on[event]); | ||
} | ||
@@ -485,2 +495,3 @@ | ||
* @param {Error} err | ||
* @param {module:mio.Resource=} resource | ||
*/ | ||
@@ -500,9 +511,9 @@ return this.trigger('get', new Query({ state: query }), callback); | ||
*/ | ||
Resource.put = function (query, rep, callback) { | ||
Resource.put = function (query, representation, callback) { | ||
if (arguments.length === 1) { | ||
rep = query; | ||
representation = query; | ||
return new Query({ | ||
handler: function (query, callback) { | ||
this.put(query, rep, callback); | ||
this.put(query, representation, callback); | ||
}, | ||
@@ -519,3 +530,3 @@ context: this | ||
* @param {module:mio.Query} query | ||
* @param {Object|module:mio.Resource} representation | ||
* @param {Object|module:mio.Resource} representationresentation | ||
* @param {module:mio.Resource.trigger.next} next | ||
@@ -532,3 +543,3 @@ * @param {module:mio.Resource} resource included if triggered by instance. | ||
* @param {module:mio.Query} query | ||
* @param {Object|module:mio.Resource} representation | ||
* @param {Object|module:mio.Resource} representationresentation | ||
* @param {module:mio.Resource} resource included if triggered by instance. | ||
@@ -544,4 +555,7 @@ * @this {module:mio.Resource} | ||
* @param {Error} err | ||
* @param {module:mio.Resource} resource | ||
*/ | ||
return this.trigger('put', new Query({ state: query }), rep, callback); | ||
return this.trigger('put', new Query({ | ||
state: query | ||
}), representation, callback); | ||
}; | ||
@@ -610,4 +624,7 @@ | ||
* @param {Error} err | ||
* @param {module:mio.Resource} resource | ||
*/ | ||
return this.trigger('patch', new Query({ state: query }), changes, callback); | ||
return this.trigger('patch', new Query({ | ||
state: query | ||
}), changes, callback); | ||
}; | ||
@@ -657,2 +674,3 @@ | ||
* @param {Error} err | ||
* @param {module:mio.Resource} resource | ||
*/ | ||
@@ -714,3 +732,5 @@ return this.trigger('post', representation, callback); | ||
*/ | ||
return this.trigger('delete', new Query({ state: query }), callback); | ||
return this.trigger('delete', new Query({ | ||
state: query | ||
}), callback); | ||
}; | ||
@@ -1151,11 +1171,5 @@ | ||
Resource.prototype.post = function (callback) { | ||
return this.trigger('post', this.changed(), function (err, representation) { | ||
if (err) return callback.call(this, err); | ||
var representation = this; | ||
if (representation) { | ||
this.reset(representation); | ||
} | ||
callback.apply(this, arguments); | ||
}); | ||
return this.trigger('post', this.changed(), callback); | ||
}; | ||
@@ -1162,0 +1176,0 @@ |
{ | ||
"name": "mio", | ||
"description": "A common model layer between client and server for building REST APIs and web applications.", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"homepage": "https://github.com/mio/mio", | ||
@@ -6,0 +6,0 @@ "repository": { |
Sorry, the diff of this file is too big to display
392062
13089