Comparing version 0.3.1 to 0.4.0
{ | ||
"name": "js-data", | ||
"description": "Data store.", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"homepage": "http://www.js-data.io/", | ||
@@ -34,5 +34,5 @@ "repository": { | ||
"observe-js": "0.3.4", | ||
"js-data-http": "~0.2.x", | ||
"js-data-localstorage": "~0.1.x" | ||
"js-data-http": "~0.4.x", | ||
"js-data-localstorage": "~0.4.x" | ||
} | ||
} |
@@ -0,1 +1,7 @@ | ||
##### 0.4.0 - 25 September 2014 | ||
###### Breaking API changes | ||
- Refactored from `baseUrl` to `basePath`, as `baseUrl` doesn't make sense for all adapters, but `basePath` does | ||
- Made `notify` configurable globally and per-resource | ||
##### 0.3.0 - 22 September 2014 | ||
@@ -2,0 +8,0 @@ |
/** | ||
* @author Jason Dobry <jason.dobry@gmail.com> | ||
* @file js-data.min.js | ||
* @version 0.3.1 - Homepage <http://www.js-data.io/> | ||
* @version 0.4.0 - Homepage <http://www.js-data.io/> | ||
* @copyright (c) 2014 Jason Dobry | ||
@@ -10,3 +10,3 @@ * @license MIT <https://github.com/js-data/js-data/blob/master/LICENSE> | ||
*/ | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.JSData=a()}}(function(){var define,module,exports;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(require,module,exports){!function(global){"use strict";function detectObjectObserve(){function a(a){b=a}if("function"!=typeof Object.observe||"function"!=typeof Array.observe)return!1;var b=[],c={},d=[];return Object.observe(c,a),Array.observe(d,a),c.id=1,c.id=2,delete c.id,d.push(1,2),d.length=0,Object.deliverChangeRecords(a),5!==b.length?!1:"add"!=b[0].type||"update"!=b[1].type||"delete"!=b[2].type||"splice"!=b[3].type||"splice"!=b[4].type?!1:(Object.unobserve(c,a),Array.unobserve(d,a),!0)}function detectEval(){if("undefined"!=typeof chrome&&chrome.app&&chrome.app.runtime)return!1;try{var a=new Function("","return true;");return a()}catch(b){return!1}}function dirtyCheck(a){for(var b=0;MAX_DIRTY_CHECK_CYCLES>b&&a.check_();)b++;return global.testingExposeCycleCount&&(global.dirtyCheckCycleCount=b),b>0}function objectIsEmpty(a){for(var b in a)return!1;return!0}function diffIsEmpty(a){return objectIsEmpty(a.added)&&objectIsEmpty(a.removed)&&objectIsEmpty(a.changed)}function diffObjectFromOldObject(a,b){var c={},d={},e={};for(var f in b){var g=a[f];(void 0===g||g!==b[f])&&(f in a?g!==b[f]&&(e[f]=g):d[f]=void 0)}for(var f in a)f in b||(c[f]=a[f]);return Array.isArray(a)&&a.length!==b.length&&(e.length=a.length),{added:c,removed:d,changed:e}}function runEOMTasks(){if(!eomTasks.length)return!1;for(var a=0;a<eomTasks.length;a++)eomTasks[a]();return eomTasks.length=0,!0}function newObservedObject(){function a(a){b&&b.state_===OPENED&&!d&&b.check_(a)}var b,c,d=!1,e=!0;return{open:function(c){if(b)throw Error("ObservedObject in use");e||Object.deliverChangeRecords(a),b=c,e=!1},observe:function(b,d){c=b,d?Array.observe(c,a):Object.observe(c,a)},deliver:function(b){d=b,Object.deliverChangeRecords(a),d=!1},close:function(){b=void 0,Object.unobserve(c,a),observedObjectCache.push(this)}}}function getObservedObject(a,b,c){var d=observedObjectCache.pop()||newObservedObject();return d.open(a),d.observe(b,c),d}function Observer(){this.state_=UNOPENED,this.callback_=void 0,this.target_=void 0,this.directObserver_=void 0,this.value_=void 0,this.id_=nextObserverId++}function addToAll(a){Observer._allObserversCount++,collectObservers&&allObservers.push(a)}function removeFromAll(){Observer._allObserversCount--}function ObjectObserver(a){Observer.call(this),this.value_=a,this.oldObject_=void 0}function diffObjectFromChangeRecords(a,b,c){for(var d={},e={},f=0;f<b.length;f++){var g=b[f];expectedRecordTypes[g.type]?(g.name in c||(c[g.name]=g.oldValue),"update"!=g.type&&("add"!=g.type?g.name in d?(delete d[g.name],delete c[g.name]):e[g.name]=!0:g.name in e?delete e[g.name]:d[g.name]=!0)):(console.error("Unknown changeRecord type: "+g.type),console.error(g))}for(var h in d)d[h]=a[h];for(var h in e)e[h]=void 0;var i={};for(var h in c)if(!(h in d||h in e)){var j=a[h];c[h]!==j&&(i[h]=j)}return{added:d,removed:e,changed:i}}var hasObserve=detectObjectObserve(),hasEval=detectEval(),createObject="__proto__"in{}?function(a){return a}:function(a){var b=a.__proto__;if(!b)return a;var c=Object.create(b);return Object.getOwnPropertyNames(a).forEach(function(b){Object.defineProperty(c,b,Object.getOwnPropertyDescriptor(a,b))}),c},MAX_DIRTY_CHECK_CYCLES=1e3,eomTasks=[],runEOM=hasObserve?function(){var a={pingPong:!0},b=!1;return Object.observe(a,function(){runEOMTasks(),b=!1}),function(c){eomTasks.push(c),b||(b=!0,a.pingPong=!a.pingPong)}}():function(){return function(a){eomTasks.push(a)}}(),observedObjectCache=[],UNOPENED=0,OPENED=1,CLOSED=2,nextObserverId=1;Observer.prototype={open:function(a,b){if(this.state_!=UNOPENED)throw Error("Observer has already been opened.");return addToAll(this),this.callback_=a,this.target_=b,this.connect_(),this.state_=OPENED,this.value_},close:function(){this.state_==OPENED&&(removeFromAll(this),this.disconnect_(),this.value_=void 0,this.callback_=void 0,this.target_=void 0,this.state_=CLOSED)},deliver:function(){this.state_==OPENED&&dirtyCheck(this)},report_:function(a){try{this.callback_.apply(this.target_,a)}catch(b){Observer._errorThrownDuringCallback=!0,console.error("Exception caught during observer callback: "+(b.stack||b))}},discardChanges:function(){return this.check_(void 0,!0),this.value_}};var collectObservers=!hasObserve,allObservers;Observer._allObserversCount=0,collectObservers&&(allObservers=[]);var runningMicrotaskCheckpoint=!1,hasDebugForceFullDelivery=hasObserve&&hasEval&&function(){try{return eval("%RunMicrotasks()"),!0}catch(ex){return!1}}();global.Platform=global.Platform||{},global.Platform.performMicrotaskCheckpoint=function(){if(!runningMicrotaskCheckpoint){if(hasDebugForceFullDelivery)return void eval("%RunMicrotasks()");if(collectObservers){runningMicrotaskCheckpoint=!0;var cycles=0,anyChanged,toCheck;do{cycles++,toCheck=allObservers,allObservers=[],anyChanged=!1;for(var i=0;i<toCheck.length;i++){var observer=toCheck[i];observer.state_==OPENED&&(observer.check_()&&(anyChanged=!0),allObservers.push(observer))}runEOMTasks()&&(anyChanged=!0)}while(MAX_DIRTY_CHECK_CYCLES>cycles&&anyChanged);global.testingExposeCycleCount&&(global.dirtyCheckCycleCount=cycles),runningMicrotaskCheckpoint=!1}}},collectObservers&&(global.Platform.clearObservers=function(){allObservers=[]}),ObjectObserver.prototype=createObject({__proto__:Observer.prototype,arrayObserve:!1,connect_:function(){hasObserve?this.directObserver_=getObservedObject(this,this.value_,this.arrayObserve):this.oldObject_=this.copyObject(this.value_)},copyObject:function(a){var b=Array.isArray(a)?[]:{};for(var c in a)b[c]=a[c];return Array.isArray(a)&&(b.length=a.length),b},check_:function(a){var b,c;if(hasObserve){if(!a)return!1;c={},b=diffObjectFromChangeRecords(this.value_,a,c)}else c=this.oldObject_,b=diffObjectFromOldObject(this.value_,this.oldObject_);return diffIsEmpty(b)?!1:(hasObserve||(this.oldObject_=this.copyObject(this.value_)),this.report_([b.added||{},b.removed||{},b.changed||{},function(a){return c[a]}]),!0)},disconnect_:function(){hasObserve?(this.directObserver_.close(),this.directObserver_=void 0):this.oldObject_=void 0},deliver:function(){this.state_==OPENED&&(hasObserve?this.directObserver_.deliver(!1):dirtyCheck(this))},discardChanges:function(){return this.directObserver_?this.directObserver_.deliver(!0):this.oldObject_=this.copyObject(this.value_),this.value_}});var observerSentinel={},expectedRecordTypes={add:!0,update:!0,"delete":!0};global.Observer=Observer,global.Observer.runEOM_=runEOM,global.Observer.observerSentinel_=observerSentinel,global.Observer.hasObjectObserve=hasObserve,global.ObjectObserver=ObjectObserver}((exports.Number={isNaN:window.isNaN})?exports:exports)},{}],2:[function(a,b,c){"use strict";var d=a("./promise/promise").Promise,e=a("./promise/polyfill").polyfill;c.Promise=d,c.polyfill=e},{"./promise/polyfill":6,"./promise/promise":7}],3:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to all.");return new b(function(b,c){function d(a){return function(b){e(a,b)}}function e(a,c){h[a]=c,0===--i&&b(h)}var g,h=[],i=a.length;0===i&&b([]);for(var j=0;j<a.length;j++)g=a[j],g&&f(g.then)?g.then(d(j),c):e(j,g)})}var e=a("./utils").isArray,f=a("./utils").isFunction;c.all=d},{"./utils":11}],4:[function(a,b,c){(function(a,b){"use strict";function d(){return function(){a.nextTick(g)}}function e(){var a=0,b=new k(g),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function f(){return function(){l.setTimeout(g,1)}}function g(){for(var a=0;a<m.length;a++){var b=m[a],c=b[0],d=b[1];c(d)}m=[]}function h(a,b){var c=m.push([a,b]);1===c&&i()}var i,j="undefined"!=typeof window?window:{},k=j.MutationObserver||j.WebKitMutationObserver,l="undefined"!=typeof b?b:void 0===this?window:this,m=[];i="undefined"!=typeof a&&"[object process]"==={}.toString.call(a)?d():k?e():f(),c.asap=h}).call(this,a("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:12}],5:[function(a,b,c){"use strict";function d(a,b){return 2!==arguments.length?e[a]:void(e[a]=b)}var e={instrument:!1};c.config=e,c.configure=d},{}],6:[function(a,b,c){(function(b){"use strict";function d(){var a;a="undefined"!=typeof b?b:"undefined"!=typeof window&&window.document?window:self;var c="Promise"in a&&"resolve"in a.Promise&&"reject"in a.Promise&&"all"in a.Promise&&"race"in a.Promise&&function(){var b;return new a.Promise(function(a){b=a}),f(b)}();c||(a.Promise=e)}var e=a("./promise").Promise,f=a("./utils").isFunction;c.polyfill=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./promise":7,"./utils":11}],7:[function(a,b,c){"use strict";function d(a){if(!q(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof d))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._subscribers=[],e(a,this)}function e(a,b){function c(a){j(b,a)}function d(a){l(b,a)}try{a(c,d)}catch(e){d(e)}}function f(a,b,c,d){var e,f,g,h,k=q(c);if(k)try{e=c(d),g=!0}catch(m){h=!0,f=m}else e=d,g=!0;i(b,e)||(k&&g?j(b,e):h?l(b,f):a===y?j(b,e):a===z&&l(b,e))}function g(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+y]=c,e[f+z]=d}function h(a,b){for(var c,d,e=a._subscribers,g=a._detail,h=0;h<e.length;h+=3)c=e[h],d=e[h+b],f(b,c,d,g);a._subscribers=null}function i(a,b){var c,d=null;try{if(a===b)throw new TypeError("A promises callback cannot return that same promise.");if(p(b)&&(d=b.then,q(d)))return d.call(b,function(d){return c?!0:(c=!0,void(b!==d?j(a,d):k(a,d)))},function(b){return c?!0:(c=!0,void l(a,b))}),!0}catch(e){return c?!0:(l(a,e),!0)}return!1}function j(a,b){a===b?k(a,b):i(a,b)||k(a,b)}function k(a,b){a._state===w&&(a._state=x,a._detail=b,o.async(m,a))}function l(a,b){a._state===w&&(a._state=x,a._detail=b,o.async(n,a))}function m(a){h(a,a._state=y)}function n(a){h(a,a._state=z)}var o=a("./config").config,p=(a("./config").configure,a("./utils").objectOrFunction),q=a("./utils").isFunction,r=(a("./utils").now,a("./all").all),s=a("./race").race,t=a("./resolve").resolve,u=a("./reject").reject,v=a("./asap").asap;o.async=v;var w=void 0,x=0,y=1,z=2;d.prototype={constructor:d,_state:void 0,_detail:void 0,_subscribers:void 0,then:function(a,b){var c=this,d=new this.constructor(function(){});if(this._state){var e=arguments;o.async(function(){f(c._state,d,e[c._state-1],c._detail)})}else g(this,d,a,b);return d},"catch":function(a){return this.then(null,a)}},d.all=r,d.race=s,d.resolve=t,d.reject=u,c.Promise=d},{"./all":3,"./asap":4,"./config":5,"./race":8,"./reject":9,"./resolve":10,"./utils":11}],8:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to race.");return new b(function(b,c){for(var d,e=0;e<a.length;e++)d=a[e],d&&"function"==typeof d.then?d.then(b,c):b(d)})}var e=a("./utils").isArray;c.race=d},{"./utils":11}],9:[function(a,b,c){"use strict";function d(a){var b=this;return new b(function(b,c){c(a)})}c.reject=d},{}],10:[function(a,b,c){"use strict";function d(a){if(a&&"object"==typeof a&&a.constructor===this)return a;var b=this;return new b(function(b){b(a)})}c.resolve=d},{}],11:[function(a,b,c){"use strict";function d(a){return e(a)||"object"==typeof a&&null!==a}function e(a){return"function"==typeof a}function f(a){return"[object Array]"===Object.prototype.toString.call(a)}var g=Date.now||function(){return(new Date).getTime()};c.objectOrFunction=d,c.isFunction=e,c.isArray=f,c.now=g},{}],12:[function(a,b){function c(){}var d=b.exports={};d.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){var b=a.source;if((b===window||null===b)&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var d=c.shift();d()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),d.title="browser",d.browser=!0,d.env={},d.argv=[],d.on=c,d.addListener=c,d.once=c,d.off=c,d.removeListener=c,d.removeAllListeners=c,d.emit=c,d.binding=function(){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(){throw new Error("process.chdir is not supported")}},{}],13:[function(a,b){function c(a,b){return-1!==d(a,b)}var d=a("./indexOf");b.exports=c},{"./indexOf":16}],14:[function(a,b){function c(a,b,c){b=d(b,c);var e=[];if(null==a)return e;for(var f,g=-1,h=a.length;++g<h;)f=a[g],b(f,g,a)&&e.push(f);return e}var d=a("../function/makeIterator_");b.exports=c},{"../function/makeIterator_":23}],15:[function(a,b){function c(a,b,c){if(null!=a)for(var d=-1,e=a.length;++d<e&&b.call(c,a[d],d,a)!==!1;);}b.exports=c},{}],16:[function(a,b){function c(a,b,c){if(c=c||0,null==a)return-1;for(var d=a.length,e=0>c?d+c:c;d>e;){if(a[e]===b)return e;e++}return-1}b.exports=c},{}],17:[function(a,b){function c(a){return null!=a&&""!==a}function d(a,b){return b=b||"",e(a,c).join(b)}var e=a("./filter");b.exports=d},{"./filter":14}],18:[function(a,b){function c(a,b){var c=d(a,b);-1!==c&&a.splice(c,1)}var d=a("./indexOf");b.exports=c},{"./indexOf":16}],19:[function(a,b){function c(a,b,c){var d=a.length;b=null==b?0:0>b?Math.max(d+b,0):Math.min(b,d),c=null==c?d:0>c?Math.max(d+c,0):Math.min(c,d);for(var e=[];c>b;)e.push(a[b++]);return e}b.exports=c},{}],20:[function(a,b){function c(a,b){if(null==a)return[];if(a.length<2)return a;null==b&&(b=d);var f,g,h;return f=~~(a.length/2),g=c(a.slice(0,f),b),h=c(a.slice(f,a.length),b),e(g,h,b)}function d(a,b){return b>a?-1:a>b?1:0}function e(a,b,c){for(var d=[];a.length&&b.length;)d.push(c(a[0],b[0])<=0?a.shift():b.shift());return a.length&&d.push.apply(d,a),b.length&&d.push.apply(d,b),d}b.exports=c},{}],21:[function(a,b){function c(a,b){var c={};if(null==a)return c;var e,f=-1,g=a.length;if(d(b))for(;++f<g;)e=a[f],c[b(e)]=e;else for(;++f<g;)e=a[f],c[e[b]]=e;return c}var d=a("../lang/isFunction");b.exports=c},{"../lang/isFunction":30}],22:[function(a,b){function c(a){return a}b.exports=c},{}],23:[function(a,b){function c(a,b){if(null==a)return d;switch(typeof a){case"function":return"undefined"!=typeof b?function(c,d,e){return a.call(b,c,d,e)}:a;case"object":return function(b){return f(b,a)};case"string":case"number":return e(a)}}var d=a("./identity"),e=a("./prop"),f=a("../object/deepMatches");b.exports=c},{"../object/deepMatches":38,"./identity":22,"./prop":24}],24:[function(a,b){function c(a){return function(b){return b[a]}}b.exports=c},{}],25:[function(a,b){function c(a){switch(h(a)){case"Object":return d(a);case"Array":return g(a);case"RegExp":return e(a);case"Date":return f(a);default:return a}}function d(a){return i(a)?j({},a):a}function e(a){var b="";return b+=a.multiline?"m":"",b+=a.global?"g":"",b+=a.ignorecase?"i":"",new RegExp(a.source,b)}function f(a){return new Date(+a)}function g(a){return a.slice()}var h=a("./kindOf"),i=a("./isPlainObject"),j=a("../object/mixIn");b.exports=c},{"../object/mixIn":44,"./isPlainObject":34,"./kindOf":36}],26:[function(a,b){function c(a,b){switch(h(a)){case"Object":return d(a,b);case"Array":return e(a,b);default:return f(a)}}function d(a,b){if(i(a)){var d={};return g(a,function(a,d){this[d]=c(a,b)},d),d}return b?b(a):a}function e(a,b){for(var d=[],e=-1,f=a.length;++e<f;)d[e]=c(a[e],b);return d}var f=a("./clone"),g=a("../object/forOwn"),h=a("./kindOf"),i=a("./isPlainObject");b.exports=c},{"../object/forOwn":41,"./clone":25,"./isPlainObject":34,"./kindOf":36}],27:[function(a,b){var c=a("./isKind"),d=Array.isArray||function(a){return c(a,"Array")};b.exports=d},{"./isKind":31}],28:[function(a,b){function c(a){return d(a,"Boolean")}var d=a("./isKind");b.exports=c},{"./isKind":31}],29:[function(a,b){function c(a){if(null==a)return!0;if("string"==typeof a||e(a))return!a.length;if("object"==typeof a){var b=!0;return d(a,function(){return b=!1,!1}),b}return!0}var d=a("../object/forOwn"),e=a("./isArray");b.exports=c},{"../object/forOwn":41,"./isArray":27}],30:[function(a,b){function c(a){return d(a,"Function")}var d=a("./isKind");b.exports=c},{"./isKind":31}],31:[function(a,b){function c(a,b){return d(a)===b}var d=a("./kindOf");b.exports=c},{"./kindOf":36}],32:[function(a,b){function c(a){return d(a,"Number")}var d=a("./isKind");b.exports=c},{"./isKind":31}],33:[function(a,b){function c(a){return d(a,"Object")}var d=a("./isKind");b.exports=c},{"./isKind":31}],34:[function(a,b){function c(a){return!!a&&"object"==typeof a&&a.constructor===Object}b.exports=c},{}],35:[function(a,b){function c(a){return d(a,"String")}var d=a("./isKind");b.exports=c},{"./isKind":31}],36:[function(a,b){function c(a){return null===a?"Null":a===d?"Undefined":e.exec(f.call(a))[1]}var d,e=/^\[object (.*)\]$/,f=Object.prototype.toString;b.exports=c},{}],37:[function(a,b){function c(a){return null==a?"":a.toString()}b.exports=c},{}],38:[function(a,b){function c(a,b){for(var c=-1,d=a.length;++c<d;)if(f(a[c],b))return!0;return!1}function d(a,b){for(var d=-1,e=b.length;++d<e;)if(!c(a,b[d]))return!1;return!0}function e(a,b){var c=!0;return g(b,function(b,d){return f(a[d],b)?void 0:c=!1}),c}function f(a,b){return a&&"object"==typeof a?h(a)&&h(b)?d(a,b):e(a,b):a===b}var g=a("./forOwn"),h=a("../lang/isArray");b.exports=f},{"../lang/isArray":27,"./forOwn":41}],39:[function(a,b){function c(a){for(var b,c=0,f=arguments.length;++c<f;)b=arguments[c],b&&e(b,d,a);return a}function d(a,b){var d=this[b];f(a)&&f(d)?c(d,a):this[b]=a}var e=a("./forOwn"),f=a("../lang/isPlainObject");b.exports=c},{"../lang/isPlainObject":34,"./forOwn":41}],40:[function(a,b){function c(){g=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=!0;for(var a in{toString:null})f=!1}function d(a,b,d){var i,j=0;null==f&&c();for(i in a)if(e(b,a,i,d)===!1)break;if(f)for(var k=a.constructor,l=!!k&&a===k.prototype;(i=g[j++])&&("constructor"===i&&(l||!h(a,i))||a[i]===Object.prototype[i]||e(b,a,i,d)!==!1););}function e(a,b,c,d){return a.call(d,b[c],c,b)}var f,g,h=a("./hasOwn");b.exports=d},{"./hasOwn":42}],41:[function(a,b){function c(a,b,c){e(a,function(e,f){return d(a,f)?b.call(c,a[f],f,a):void 0})}var d=a("./hasOwn"),e=a("./forIn");b.exports=c},{"./forIn":40,"./hasOwn":42}],42:[function(a,b){function c(a,b){return Object.prototype.hasOwnProperty.call(a,b)}b.exports=c},{}],43:[function(a,b){function c(){var a,b,g,h,i=1;for(h=e(arguments[0]);g=arguments[i++];)for(a in g)d(g,a)&&(b=g[a],h[a]=f(b)&&f(h[a])?c(h[a],b):e(b));return h}var d=a("./hasOwn"),e=a("../lang/deepClone"),f=a("../lang/isObject");b.exports=c},{"../lang/deepClone":26,"../lang/isObject":33,"./hasOwn":42}],44:[function(a,b){function c(a){for(var b,c=0,f=arguments.length;++c<f;)b=arguments[c],null!=b&&e(b,d,a);return a}function d(a,b){this[b]=a}var e=a("./forOwn");b.exports=c},{"./forOwn":41}],45:[function(a,b){function c(a,b){return b?(d(b.split("."),function(b){a[b]||(a[b]={}),a=a[b]}),a):a}var d=a("../array/forEach");b.exports=c},{"../array/forEach":15}],46:[function(a,b){function c(a){for(var b,c="string"!=typeof arguments[1]?arguments[1]:d(arguments,1),e={},f=0;b=c[f++];)e[b]=a[b];return e}var d=a("../array/slice");b.exports=c},{"../array/slice":19}],47:[function(a,b){function c(a,b,c){var e=/^(.+)\.(.+)$/.exec(b);e?d(a,e[1])[e[2]]=c:a[b]=c}var d=a("./namespace");b.exports=c},{"./namespace":45}],48:[function(a,b){function c(a){return a=d(a),a=e(a),a=f(a).replace(/[\-_]/g," ").replace(/\s[a-z]/g,g).replace(/\s+/g,"").replace(/^[A-Z]/g,h)}var d=a("../lang/toString"),e=a("./replaceAccents"),f=a("./removeNonWord"),g=a("./upperCase"),h=a("./lowerCase");b.exports=c},{"../lang/toString":37,"./lowerCase":49,"./removeNonWord":52,"./replaceAccents":53,"./upperCase":54}],49:[function(a,b){function c(a){return a=d(a),a.toLowerCase()}var d=a("../lang/toString");b.exports=c},{"../lang/toString":37}],50:[function(a,b){function c(){var a=d(e(arguments),"/");return a.replace(/([^:\/]|^)\/{2,}/g,"$1/")}var d=a("../array/join"),e=a("../array/slice");b.exports=c},{"../array/join":17,"../array/slice":19}],51:[function(a,b){function c(a){return a=d(a),e(a).replace(/^[a-z]/,f)}var d=a("../lang/toString"),e=a("./camelCase"),f=a("./upperCase");b.exports=c},{"../lang/toString":37,"./camelCase":48,"./upperCase":54}],52:[function(a,b){function c(a){return a=d(a),a.replace(e,"")}var d=a("../lang/toString"),e=/[^\x20\x2D0-9A-Z\x5Fa-z\xC0-\xD6\xD8-\xF6\xF8-\xFF]/g;b.exports=c},{"../lang/toString":37}],53:[function(a,b){function c(a){return a=d(a),a.search(/[\xC0-\xFF]/g)>-1&&(a=a.replace(/[\xC0-\xC5]/g,"A").replace(/[\xC6]/g,"AE").replace(/[\xC7]/g,"C").replace(/[\xC8-\xCB]/g,"E").replace(/[\xCC-\xCF]/g,"I").replace(/[\xD0]/g,"D").replace(/[\xD1]/g,"N").replace(/[\xD2-\xD6\xD8]/g,"O").replace(/[\xD9-\xDC]/g,"U").replace(/[\xDD]/g,"Y").replace(/[\xDE]/g,"P").replace(/[\xE0-\xE5]/g,"a").replace(/[\xE6]/g,"ae").replace(/[\xE7]/g,"c").replace(/[\xE8-\xEB]/g,"e").replace(/[\xEC-\xEF]/g,"i").replace(/[\xF1]/g,"n").replace(/[\xF2-\xF6\xF8]/g,"o").replace(/[\xF9-\xFC]/g,"u").replace(/[\xFE]/g,"p").replace(/[\xFD\xFF]/g,"y")),a}var d=a("../lang/toString");b.exports=c},{"../lang/toString":37}],54:[function(a,b){function c(a){return a=d(a),a.toUpperCase()}var d=a("../lang/toString");b.exports=c},{"../lang/toString":37}],55:[function(a,b){function c(a,b,c){var g=this,h=g.definitions[a],i=new d.Promise(function(d,f){c=c||{},h?("cacheResponse"in c||(c.cacheResponse=!0),"upsert"in c||(c.upsert=!0),d(b)):f(new e.NER(a))});return c.upsert&&b[h.idAttribute]?g.update(a,b[h.idAttribute],b,c):i.then(function(b){var d=c.beforeValidate?f(c.beforeValidate):h.beforeValidate;return d.call(b,a,b)}).then(function(b){var d=c.validate?f(c.validate):h.validate;return d.call(b,a,b)}).then(function(b){var d=c.afterValidate?f(c.afterValidate):h.afterValidate;return d.call(b,a,b)}).then(function(b){var d=c.beforeCreate?f(c.beforeCreate):h.beforeCreate;return d.call(b,a,b)}).then(function(a){return g.notify(h,"beforeCreate",d.merge({},a)),g.getAdapter(h,c).create(h,a,c)}).then(function(b){var d=c.afterCreate?f(c.afterCreate):h.afterCreate;return d.call(b,a,b)}).then(function(b){if(g.notify(h,"afterCreate",d.merge({},b)),c.cacheResponse){var e=g.store[a],f=g.inject(h.name,b,c),i=f[h.idAttribute];return e.completedQueries[i]=(new Date).getTime(),e.previousAttributes[i]=d.deepMixIn({},f),e.saved[i]=d.updateTimestamp(e.saved[i]),g.get(h.name,i)}return g.createInstance(a,b,c)})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],56:[function(a,b){function c(a,b,c){var g,h=this,i=h.definitions[a];return new d.Promise(function(f,j){c=c||{},b=d.resolveId(i,b),i?d.isString(b)||d.isNumber(b)?h.get(a,b)?(g=h.get(a,b),"notify"in c||(c.notify=!0),f(g)):j(new e.R('id "'+b+'" not found in cache!')):j(new e.IA('"id" must be a string or a number!')):j(new e.NER(a))}).then(function(b){if(c.notify){var d=c.beforeDestroy?f(c.beforeDestroy):i.beforeDestroy;return d.call(b,a,b)}return b}).then(function(e){return c.notify&&h.notify(i,"beforeDestroy",d.merge({},e)),c.eagerEject&&h.eject(a,b),h.getAdapter(i,c).destroy(i,b,c)}).then(function(){if(c.notify){var b=c.afterDestroy?f(c.afterDestroy):i.afterDestroy;return b.call(g,a,g)}return g}).then(function(e){return c.notify&&h.notify(i,"afterDestroy",d.merge({},e)),h.eject(a,b),b}).catch(function(b){throw c.eagerEject&&g&&h.inject(a,g,{notify:!1}),b})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],57:[function(a,b){function c(a,b,c){var f,g,h=this,i=h.definitions[a];return new d.Promise(function(b,d){i?(c=c||{},b()):d(new e.NER(a))}).then(function(){var d=c.beforeDestroy?promisify(c.beforeDestroy):i.beforeDestroy;return g=h.defaults.defaultFilter.call(h,a,b),d(a,g)}).then(function(){return c.notify&&h.notify(i,"beforeDestroy",g),c.eagerEject&&(f=h.ejectAll(a,b)),h.getAdapter(i,c).destroyAll(i,b,c)}).then(function(){var b=c.afterDestroy?promisify(c.afterDestroy):i.afterDestroy;return b(a,g)}).then(function(){return c.notify&&h.notify(i,"afterDestroy",g),f||h.ejectAll(a,b)}).catch(function(b){throw c.eagerEject&&f&&h.inject(a,f,{notify:!1}),b})}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],58:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a],h=f.store[a];return new d.Promise(function(i,j){c=c||{},g?d.isString(b)||d.isNumber(b)?d.isObject(c)?("cacheResponse"in c||(c.cacheResponse=!0),(c.bypassCache||!c.cacheResponse)&&delete h.completedQueries[b],b in h.completedQueries?i(f.get(a,b)):i()):j(new e.IA('"options" must be an object!')):j(new e.IA('"id" must be a string or a number!')):j(new e.NER(a))}).then(function(d){return b in h.completedQueries?d:(b in h.pendingQueries||(h.pendingQueries[b]=f.getAdapter(g,c).find(g,b,c).then(function(d){return c.cacheResponse?(delete h.pendingQueries[b],h.completedQueries[b]=(new Date).getTime(),f.inject(a,d,c)):f.createInstance(a,d,c)})),h.pendingQueries[b])}).catch(function(a){throw delete h.pendingQueries[b],a})}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],59:[function(a,b){function c(a,b,c,d){var f=this,g=f.store[b],h=f.definitions[b].idAttribute,i=(new Date).getTime();a=a||[],delete g.pendingQueries[c],g.completedQueries[c]=i,g.collectionModified=e.updateTimestamp(g.collectionModified);var j=f.inject(b,a,d);return e.isArray(j)?e.forEach(j,function(a){a&&a[h]&&(g.completedQueries[a[h]]=i)}):(console.warn(errorPrefix(b)+"response is expected to be an array!"),g.completedQueries[j[h]]=i),j}function d(a,b,d){var g,h=this,i=h.definitions[a],j=h.store[a];return new e.Promise(function(c,i){d=d||{},b=b||{},h.definitions[a]?e.isObject(b)?e.isObject(d)?("cacheResponse"in d||(d.cacheResponse=!0),g=e.toJson(b),(d.bypassCache||!d.cacheResponse)&&delete j.completedQueries[g],g in j.completedQueries?c(h.filter(a,b,d)):c()):i(new f.IA('"options" must be an object!')):i(new f.IA('"params" must be an object!')):i(new f.NER(a))}).then(function(f){return g in j.completedQueries?f:(g in j.pendingQueries||(j.pendingQueries[g]=h.getAdapter(i,d).findAll(i,b,d).then(function(b){return delete j.pendingQueries[g],d.cacheResponse?c.call(h,b,a,g,d):(e.forEach(b,function(c,e){b[e]=h.createInstance(a,c,d)}),b)})),j.pendingQueries[g])}).catch(function(a){throw delete j.pendingQueries[g],a})}var e=a("../../utils"),f=a("../../errors");b.exports=d},{"../../errors":76,"../../utils":78}],60:[function(a,b){function c(a,b,c){var f=this;return new d.Promise(function(g,h){c=c||{},b=d.resolveId(f.definitions[a],b),f.definitions[a]?d.isString(b)||d.isNumber(b)?d.isObject(c)?(c.bypassCache=!0,g(f.get(a,b))):h(new e.IA('"options" must be an object!')):h(new e.IA('"id" must be a string or a number!')):h(new f.errors.NER(a))}).then(function(d){return d?f.find(a,b,c):d})}var d=a("../../utils"),e=a("../../errors");b.exports={create:a("./create"),destroy:a("./destroy"),destroyAll:a("./destroyAll"),find:a("./find"),findAll:a("./findAll"),loadRelations:a("./loadRelations"),refresh:c,save:a("./save"),update:a("./update"),updateAll:a("./updateAll")}},{"../../errors":76,"../../utils":78,"./create":55,"./destroy":56,"./destroyAll":57,"./find":58,"./findAll":59,"./loadRelations":61,"./save":62,"./update":63,"./updateAll":64}],61:[function(a,b){function c(a,b,c,f){var g=this,h=g.definitions[a],i=[];return new d.Promise(function(j,k){if(f=f||{},(d.isString(b)||d.isNumber(b))&&(b=g.get(a,b)),d.isString(c)&&(c=[c]),h)if(d.isObject(b))if(d.isArray(c))if(d.isObject(f)){"findBelongsTo"in f||(f.findBelongsTo=!0),"findHasMany"in f||(f.findHasMany=!0);var l=[];d.forEach(h.relationList,function(a){var e=a.relation;if(d.contains(c,e)){var j,k={};k[a.foreignKey]=b[h.idAttribute],"hasMany"===a.type&&k[a.foreignKey]?j=g.findAll(e,k,f):"hasOne"===a.type?a.localKey&&b[a.localKey]?j=g.find(e,b[a.localKey],f):a.foreignKey&&k[a.foreignKey]&&(j=g.findAll(e,k,f).then(function(a){return a.length?a[0]:null})):b[a.localKey]&&(j=g.find(e,b[a.localKey],f)),j&&(l.push(j),i.push(a.localField))}}),j(l)}else k(new e.IA('"options" must be an object!'));else k(new e.IA('"relations" must be a string or an array!'));else k(new e.IA('"instance(id)" must be a string, number or object!'));else k(new e.NER(a))}).then(function(a){return d.Promise.all(a)}).then(function(a){return d.forEach(i,function(c,d){b[c]=a[d]}),b})}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],62:[function(a,b){function c(a,b,c){var g,h=this,i=h.definitions[a];return new d.Promise(function(f,j){c=c||{},b=d.resolveId(i,b),i?d.isString(b)||d.isNumber(b)?d.isObject(c)?h.get(a,b)?(g=h.get(a,b),"cacheResponse"in c||(c.cacheResponse=!0),f(g)):j(new e.R('id "'+b+'" not found in cache!')):j(new e.IA('"options" must be an object!')):j(new e.IA('"id" must be a string or a number!')):j(new e.NER(a))}).then(function(b){var d=c.beforeValidate?f(c.beforeValidate):i.beforeValidate;return d.call(b,a,b)}).then(function(b){var d=c.validate?f(c.validate):i.validate;return d.call(b,a,b)}).then(function(b){var d=c.afterValidate?f(c.afterValidate):i.afterValidate;return d.call(b,a,b)}).then(function(b){var d=c.beforeUpdate?f(c.beforeUpdate):i.beforeUpdate;return d.call(b,a,b)}).then(function(e){if(h.notify(i,"beforeUpdate",d.merge({},e)),c.changesOnly){var f=h.store[a];f.observers[b].deliver();var g=[],j=h.changes(a,b);for(var k in j.added)g.push(k);for(k in j.changed)g.push(k);if(j=d.pick(e,g),d.isEmpty(j))return e;e=j}return h.getAdapter(i,c).update(i,b,e,c)}).then(function(b){var d=c.afterUpdate?f(c.afterUpdate):i.afterUpdate;return d.call(b,a,b)}).then(function(e){if(h.notify(i,"afterUpdate",d.merge({},e)),c.cacheResponse){var f=h.store[a],g=h.inject(i.name,e,c);return f.previousAttributes[b]=d.deepMixIn({},g),f.saved[b]=d.updateTimestamp(f.saved[b]),f.observers[b].discardChanges(),h.get(a,b)}return e})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],63:[function(a,b){function c(a,b,c,g){var h=this,i=h.definitions[a];return new d.Promise(function(f,h){g=g||{},b=d.resolveId(i,b),i?d.isString(b)||d.isNumber(b)?d.isObject(g)?("cacheResponse"in g||(g.cacheResponse=!0),f(c)):h(new e.IA('"options" must be an object!')):h(new e.IA('"id" must be a string or a number!')):h(new e.NER(a))}).then(function(b){var c=g.beforeValidate?f(g.beforeValidate):i.beforeValidate;return c.call(b,a,b)}).then(function(b){var c=g.validate?f(g.validate):i.validate;return c.call(b,a,b)}).then(function(b){var c=g.afterValidate?f(g.afterValidate):i.afterValidate;return c.call(b,a,b)}).then(function(b){var c=g.beforeUpdate?f(g.beforeUpdate):i.beforeUpdate;return c.call(b,a,b)}).then(function(a){return h.notify(i,"beforeUpdate",d.merge({},a)),h.getAdapter(i,g).update(i,b,a,g)}).then(function(b){var c=g.afterUpdate?f(g.afterUpdate):i.afterUpdate;return c.call(b,a,b)}).then(function(b){if(h.notify(i,"afterUpdate",d.merge({},b)),g.cacheResponse){var c=h.store[a],e=h.inject(i.name,b,g),f=e[i.idAttribute];return c.previousAttributes[f]=d.deepMixIn({},e),c.saved[f]=d.updateTimestamp(c.saved[f]),c.observers[f].discardChanges(),h.get(i.name,f) | ||
}return b})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],64:[function(a,b){function c(a,b,c,g){var h=this,i=h.definitions[a];return new d.Promise(function(c,f){g=g||{},i?d.isObject(g)?("cacheResponse"in g||(g.cacheResponse=!0),c(b)):f(new e.IA('"options" must be an object!')):f(new e.NER(a))}).then(function(b){var c=g.beforeValidate?f(g.beforeValidate):i.beforeValidate;return c.call(b,a,b)}).then(function(b){var c=g.validate?f(g.validate):i.validate;return c.call(b,a,b)}).then(function(b){var c=g.afterValidate?f(g.afterValidate):i.afterValidate;return c.call(b,a,b)}).then(function(b){var c=g.beforeUpdate?f(g.beforeUpdate):i.beforeUpdate;return c.call(b,a,b)}).then(function(a){return h.notify(i,"beforeUpdate",d.merge({},a)),h.getAdapter(i,g).updateAll(i,a,c,g)}).then(function(b){var c=g.afterUpdate?f(g.afterUpdate):i.afterUpdate;return c.call(b,a,b)}).then(function(a){return h.notify(i,"afterUpdate",d.merge({},b)),g.cacheResponse?h.inject(i.name,a,g):a})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],65:[function(a,b){function c(a,b,c){c(null,b)}function d(a,b){return b}function e(){}function f(a){this.store={},this.definitions={},this.adapters={},this.defaults=new e,g.deepMixIn(this.defaults,a)}var g=a("../utils"),h=a("../errors"),i=a("./sync_methods"),j=a("./async_methods");g.deepFreeze(i),g.deepFreeze(j),g.deepFreeze(h),g.deepFreeze(g);var k=e.prototype;k.idAttribute="id",k.defaultAdapter="DSHttpAdapter",k.defaultFilter=function(a,b,c,d){var e=this,f=a,h=null,i={skip:"",offset:"",where:"",limit:"",orderBy:"",sort:""};c=c||{},d=d||{},h=g.isObject(c.where)?c.where:{},d.allowSimpleWhere&&g.forOwn(c,function(a,b){b in i||b in h||(h[b]={"==":a})}),g.isEmpty(h)&&(h=null),h&&(f=g.filter(f,function(a){var b=!0,c=!0;return g.forOwn(h,function(d,e){g.isString(d)?d={"===":d}:(g.isNumber(d)||g.isBoolean(d))&&(d={"==":d}),g.isObject(d)&&g.forOwn(d,function(d,f){"=="===f?c=b?a[e]==d:c&&a[e]==d:"==="===f?c=b?a[e]===d:c&&a[e]===d:"!="===f?c=b?a[e]!=d:c&&a[e]!=d:"!=="===f?c=b?a[e]!==d:c&&a[e]!==d:">"===f?c=b?a[e]>d:c&&a[e]>d:">="===f?c=b?a[e]>=d:c&&a[e]>=d:"<"===f?c=b?a[e]<d:c&&a[e]<d:"<="===f?c=b?a[e]<=d:c&&a[e]<=d:"in"===f?c=b?g.contains(d,a[e]):c&&g.contains(d,a[e]):"notIn"===f?c=b?!g.contains(d,a[e]):c&&!g.contains(d,a[e]):"|=="===f?c=b?a[e]==d:c||a[e]==d:"|==="===f?c=b?a[e]===d:c||a[e]===d:"|!="===f?c=b?a[e]!=d:c||a[e]!=d:"|!=="===f?c=b?a[e]!==d:c||a[e]!==d:"|>"===f?c=b?a[e]>d:c||a[e]>d:"|>="===f?c=b?a[e]>=d:c||a[e]>=d:"|<"===f?c=b?a[e]<d:c||a[e]<d:"|<="===f?c=b?a[e]<=d:c||a[e]<=d:"|in"===f?c=b?g.contains(d,a[e]):c||g.contains(d,a[e]):"|notIn"===f&&(c=b?!g.contains(d,a[e]):c||!g.contains(d,a[e])),b=!1})}),c}));var j=null;g.isString(c.orderBy)?j=[[c.orderBy,"ASC"]]:g.isArray(c.orderBy)&&(j=c.orderBy),!j&&g.isString(c.sort)?j=[[c.sort,"ASC"]]:!j&&g.isArray(c.sort)&&(j=c.sort),j&&g.forEach(j,function(a){if(g.isString(a))a=[a,"ASC"];else if(!g.isArray(a))throw new e.errors.IllegalArgumentError("DS.filter(resourceName[, params][, options]): "+g.toJson(a)+": Must be a string or an array!",{params:{"orderBy[i]":{actual:typeof a,expected:"string|array"}}});f=g.sort(f,function(b,c){var d=b[a[0]],e=c[a[0]];return g.isString(d)&&(d=g.upperCase(d)),g.isString(e)&&(e=g.upperCase(e)),"DESC"===a[1]?d>e?-1:e>d?1:0:e>d?-1:d>e?1:0})});var k=g.isNumber(c.limit)?c.limit:null,l=null;return g.isNumber(c.skip)?l=c.skip:g.isNumber(c.offset)&&(l=c.offset),k&&l?f=g.slice(f,l,Math.min(f.length,l+k)):g.isNumber(k)?f=g.slice(f,0,Math.min(f.length,k)):g.isNumber(l)&&(f=l<f.length?g.slice(f,l):[]),f},k.baseUrl="",k.endpoint="",k.useClass=!0,k.keepChangeHistory=!1,k.resetHistoryOnInject=!0,k.beforeValidate=c,k.validate=c,k.afterValidate=c,k.beforeCreate=c,k.afterCreate=c,k.beforeUpdate=c,k.afterUpdate=c,k.beforeDestroy=c,k.afterDestroy=c,k.beforeInject=d,k.afterInject=d,k.beforeEject=d,k.afterEject=d;var l=f.prototype;l.getAdapter=function(a,b){return b=b||{},this.adapters[b.adapter]||this.adapters[a.defaultAdapter]},l.notify=function(a,b){var c=Array.prototype.slice.call(arguments,2);c.unshift(a.name),c.unshift("DS."+b),a.emit.apply(a,c)},l.errors=a("../errors"),l.utils=g,g.deepMixIn(l,i),g.deepMixIn(l,j),b.exports=f},{"../errors":76,"../utils":78,"./async_methods":60,"./sync_methods":70}],66:[function(require,module,exports){function Resource(a){DSUtils.deepMixIn(this,a),this.endpoint="endpoint"in a?a.endpoint:this.name}function defineResource(definition){var _this=this,definitions=_this.definitions;if(DSUtils.isString(definition)&&(definition={name:definition.replace(/\s/gi,"")}),!DSUtils.isObject(definition))throw new DSErrors.IA('"definition" must be an object!');if(!DSUtils.isString(definition.name))throw new DSErrors.IA('"name" must be a string!');if(_this.store[definition.name])throw new DSErrors.R(definition.name+" is already registered!");try{Resource.prototype=_this.defaults,definitions[definition.name]=new Resource(definition);var def=definitions[definition.name];if(!DSUtils.isString(def.idAttribute))throw new DSErrors.IA('"idAttribute" must be a string!');return def.relations&&(def.relationList=[],def.relationFields=[],DSUtils.forOwn(def.relations,function(a,b){DSUtils.forOwn(a,function(c,d){DSUtils.isArray(c)||(a[d]=[c]),DSUtils.forEach(a[d],function(a){a.type=b,a.relation=d,a.name=def.name,def.relationList.push(a),def.relationFields.push(a.localField)})})}),def.relations.belongsTo&&DSUtils.forOwn(def.relations.belongsTo,function(a,b){DSUtils.forEach(a,function(a){a.parent&&(def.parent=b,def.parentKey=a.localKey)})}),DSUtils.deepFreeze(def.relations),DSUtils.deepFreeze(def.relationList)),def.getEndpoint=function(a,b){var c,d,e=this.parent,f=this.parentKey,g=b.endpoint||this.endpoint,h=definitions[e];return delete b.endpoint,b=b||{},b.params=b.params||{},e&&f&&h&&b.params[f]!==!1&&((DSUtils.isNumber(a)||DSUtils.isString(a))&&(c=_this.get(this.name,a)),DSUtils.isObject(a)&&f in a?(delete b.params[f],d=DSUtils.makePath(h.getEndpoint(a,b),a[f],g)):c&&f in c?(delete b.params[f],d=DSUtils.makePath(h.getEndpoint(a,b),c[f],g)):b&&b.params[f]&&(d=DSUtils.makePath(h.getEndpoint(a,b),b.params[f],g),delete b.params[f])),b.params[f]===!1&&delete b.params[f],d||g},def.filter&&(def.defaultFilter=def.filter,delete def.filter),def.class=DSUtils.pascalCase(definition.name),eval("function "+def.class+"() {}"),def[def.class]=eval(def.class),def.methods&&DSUtils.deepMixIn(def[def.class].prototype,def.methods),def.computed&&(DSUtils.forOwn(def.computed,function(a,b){DSUtils.isFunction(a)&&(def.computed[b]=[a],a=def.computed[b]),def.methods&&b in def.methods&&console.warn('Computed property "'+b+'" conflicts with previously defined prototype method!');var c;if(1===a.length){var d=a[0].toString().match(/function.*?\(([\s\S]*?)\)/);c=d[1].split(","),def.computed[b]=c.concat(a),a=def.computed[b],c.length&&console.warn("Use the computed property array syntax for compatibility with minified code!")}c=a.slice(0,a.length-1),DSUtils.forEach(c,function(a,b){c[b]=a.trim()}),a.deps=DSUtils.filter(c,function(a){return!!a})}),def[def.class].prototype.DSCompute=function(){return _this.compute(def.name,this)}),_this.store[def.name]={collection:[],completedQueries:{},pendingQueries:{},index:{},modified:{},saved:{},previousAttributes:{},observers:{},changeHistories:{},changeHistory:[],collectionModified:0},DSUtils.forEach(methodsToProxy,function(a){def[a]=function(){var b=Array.prototype.slice.call(arguments);return b.unshift(def.name),_this[a].apply(_this,b)}}),def.beforeValidate=DSUtils.promisify(def.beforeValidate),def.validate=DSUtils.promisify(def.validate),def.afterValidate=DSUtils.promisify(def.afterValidate),def.beforeCreate=DSUtils.promisify(def.beforeCreate),def.afterCreate=DSUtils.promisify(def.afterCreate),def.beforeUpdate=DSUtils.promisify(def.beforeUpdate),def.afterUpdate=DSUtils.promisify(def.afterUpdate),def.beforeDestroy=DSUtils.promisify(def.beforeDestroy),def.afterDestroy=DSUtils.promisify(def.afterDestroy),DSUtils.Events(def),def}catch(err){throw console.error(err),delete definitions[definition.name],delete _this.store[definition.name],err}}var DSUtils=require("../../utils"),DSErrors=require("../../errors"),methodsToProxy=["changes","changeHistory","create","createInstance","destroy","destroyAll","eject","ejectAll","filter","find","findAll","get","hasChanges","inject","lastModified","lastSaved","link","linkAll","linkInverse","loadRelations","previous","refresh","save","unlinkInverse","update","updateAll"];module.exports=defineResource},{"../../errors":76,"../../utils":78}],67:[function(a,b){function c(a,b,c){var f,g=this,h=g.definitions[a],i=g.store[a],j=!1;if(c=c||{},b=d.resolveId(h,b),!h)throw new e.NER(a);if(!d.isString(b)&&!d.isNumber(b))throw new e.IA('"id" must be a string or a number!');if(!d.isObject(c))throw new e.IA('"options" must be an object!');for(var k=0;k<i.collection.length;k++)if(i.collection[k][h.idAttribute]==b){f=i.collection[k],j=!0;break}return j?("notify"in c||(c.notify=!0),c.notify&&h.beforeEject(h.name,f),g.unlinkInverse(h.name,b),i.collection.splice(k,1),i.observers[b].close(),delete i.observers[b],delete i.index[b],delete i.previousAttributes[b],delete i.completedQueries[b],delete i.pendingQueries[b],d.forEach(i.changeHistories[b],function(a){d.remove(i.changeHistory,a)}),delete i.changeHistories[b],delete i.modified[b],delete i.saved[b],i.collectionModified=d.updateTimestamp(i.collectionModified),c.notify&&(h.afterEject(h.name,f),g.notify(h,"eject",f)),f):void 0}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],68:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(b=b||{},!g)throw new e.NER(a);if(!d.isObject(b))throw new e.IA('"params" must be an object!');var h=f.store[a];d.isEmpty(b)&&(h.completedQueries={});var i=d.toJson(b),j=f.filter(g.name,b),k=d.toLookup(j,g.idAttribute);return d.forOwn(k,function(a,b){f.eject(g.name,b,c)}),delete h.completedQueries[i],h.collectionModified=d.updateTimestamp(h.collectionModified),j}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],69:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||{},!g)throw new e.NER(a);if(b&&!d.isObject(b))throw new e.IA('"params" must be an object!');if(!d.isObject(c))throw new e.IA('"options" must be an object!');var h=f.store[a];b=b||{},"allowSimpleWhere"in c||(c.allowSimpleWhere=!0);var i=d.toJson(b);return i in h.completedQueries||!c.loadFromServer||h.pendingQueries[i]||f.findAll(a,b,c),g.defaultFilter.call(f,h.collection,a,b,c)}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],70:[function(a,b){function c(a,b){var c=this,d=c.definitions[a];if(b=o.resolveId(d,b),!d)throw new p.NER(a);if(!o.isString(b)&&!o.isNumber(b))throw new p.IA('"id" must be a string or a number!');var e=c.get(a,b);if(e){c.store[a].observers[b].deliver();var f=o.diffObjectFromOldObject(e,c.store[a].previousAttributes[b]);return o.forOwn(f,function(a,b){var c=[];o.forOwn(a,function(a,b){o.isFunction(a)||c.push(b)}),f[b]=o.pick(f[b],c)}),o.forEach(d.relationFields,function(a){delete f.added[a],delete f.removed[a],delete f.changed[a]}),f}}function d(a,b){var c=this,d=c.definitions[a],e=c.store[a];if(b=o.resolveId(d,b),a&&!c.definitions[a])throw new p.NER(a);if(b&&!o.isString(b)&&!o.isNumber(b))throw new p.IA('"id" must be a string or a number!');if(d.keepChangeHistory){if(!a)return e.changeHistory;var f=c.get(a,b);if(f)return e.changeHistories[b]}else console.warn("changeHistory is disabled for this resource!")}function e(a,b,c){var d=this.definitions[a];if(b=b||{},c=c||{},!d)throw new p.NER(a);if(b&&!o.isObject(b))throw new p.IA('"attrs" must be an object!');if(!o.isObject(c))throw new p.IA('"options" must be an object!');"useClass"in c||(c.useClass=d.useClass);var e;if(c.useClass){var f=d[d.class];e=new f}else e={};return o.deepMixIn(e,b)}function f(a){return!(o.isEmpty(a.added)&&o.isEmpty(a.removed)&&o.isEmpty(a.changed))}function g(){n.Platform.performMicrotaskCheckpoint()}function h(a,b){var c=this,d=c.definitions[a];if(b=o.resolveItem(c.store[a],b),!d)throw new p.NER(a);if(!o.isObject(b)&&!o.isString(b)&&!o.isNumber(b))throw new p.IA('"instance" must be an object, string or number!');return(o.isString(b)||o.isNumber(b))&&(b=c.get(a,b)),o.forOwn(d.computed,function(a,c){o.compute.call(b,a,c,o)}),b}function i(a,b,c){var d=this;if(c=c||{},!d.definitions[a])throw new p.NER(a);if(!o.isString(b)&&!o.isNumber(b))throw new p.IA('"id" must be a string or a number!');if(!o.isObject(c))throw new p.IA('"options" must be an object!');var e=d.store[a].index[b];return!e&&c.loadFromServer&&d.find(a,b,c),e}function j(a,b){var c=this;if(b=o.resolveId(c.definitions[a],b),!c.definitions[a])throw new p.NER(a);return c.get(a,b)?f(c.changes(a,b)):!1}function k(a,b){var c=this.definitions[a],d=this.store[a];if(b=o.resolveId(c,b),!c)throw new p.NER(a);return b?(b in d.modified||(d.modified[b]=0),d.modified[b]):d.collectionModified}function l(a,b){var c=this.definitions[a],d=this.store[a];if(b=o.resolveId(c,b),!c)throw new p.NER(a);return b in d.saved||(d.saved[b]=0),d.saved[b]}function m(a,b){var c=this,d=c.definitions[a],e=c.store[a];if(b=o.resolveId(d,b),!d)throw new p.NER(a);if(!o.isString(b)&&!o.isNumber(b))throw new p.IA('"id" must be a string or a number!');return e.previousAttributes[b]?o.merge({},e.previousAttributes[b]):void 0}var n=a("../../../lib/observe-js/observe-js"),o=a("../../utils"),p=a("../../errors");b.exports={changes:c,changeHistory:d,compute:h,createInstance:e,defineResource:a("./defineResource"),digest:g,eject:a("./eject"),ejectAll:a("./ejectAll"),filter:a("./filter"),get:i,hasChanges:j,inject:a("./inject"),lastModified:k,lastSaved:l,link:a("./link"),linkAll:a("./linkAll"),linkInverse:a("./linkInverse"),previous:m,unlinkInverse:a("./unlinkInverse")}},{"../../../lib/observe-js/observe-js":1,"../../errors":76,"../../utils":78,"./defineResource":66,"./eject":67,"./ejectAll":68,"./filter":69,"./inject":71,"./link":72,"./linkAll":73,"./linkInverse":74,"./unlinkInverse":75}],71:[function(a,b){function c(a,b,c){return function(d,e,f,h,i){var j,k=this,l=h&&h(b.idAttribute)?h(b.idAttribute):k[b.idAttribute];if(g.forEach(b.relationFields,function(a){delete d[a],delete e[a],delete f[a]}),(!g.isEmpty(d)||!g.isEmpty(e)||!g.isEmpty(f)||i)&&(j=a.get(b.name,l),c.modified[l]=g.updateTimestamp(c.modified[l]),c.collectionModified=g.updateTimestamp(c.collectionModified),b.keepChangeHistory)){var m={resourceName:b.name,target:j,added:d,removed:e,changed:f,timestamp:c.modified[l]};c.changeHistories[l].push(m),c.changeHistory.push(m)}b.computed&&(j=j||a.get(b.name,l),g.forOwn(b.computed,function(a,b){var c=!1;g.forEach(a.deps,function(a){(a in d||a in e||a in f||!(b in j))&&(c=!0)}),c=c||!a.deps.length,c&&g.compute.call(j,a,b,g)})),b.relations&&(j=j||a.get(b.name,l),g.forEach(b.relationList,function(c){j[c.localField]&&(c.localKey in d||c.localKey in e||c.localKey in f)&&a.link(b.name,j[b.idAttribute],[c.relation])})),b.idAttribute in f&&console.error("Doh! You just changed the primary key of an object! I don't know how to handle this yet, so your data for the \""+b.name+'" resource is now in an undefined (probably broken) state.')}}function d(a,b,e,f){var j,k=this,l=c(k,a,b,e,f);if(g.isArray(e)){j=[];for(var m=0;m<e.length;m++)j.push(d.call(k,a,b,e[m],f))}else{var n=a.computed,o=a.idAttribute;if(n&&n[o]){var p=[];g.forEach(n[o].deps,function(a){p.push(e[a])}),e[o]=n[o][n[o].length-1].apply(e,p)}if(!(o in e)){var q=new h.R(a.name+'.inject: "attrs" must contain the property specified by `idAttribute`!');throw console.error(q),q}try{var r=e[o],s=k.get(a.name,r);s?(g.deepMixIn(s,e),a.resetHistoryOnInject&&(b.previousAttributes[r]={},g.deepMixIn(b.previousAttributes[r],e),b.changeHistories[r].length&&(g.forEach(b.changeHistories[r],function(a){g.remove(b.changeHistory,a)}),b.changeHistories[r].splice(0,b.changeHistories[r].length))),b.observers[r].deliver()):(s=f.useClass?e instanceof a[a.class]?e:new a[a.class]:{},b.previousAttributes[r]={},g.deepMixIn(s,e),g.deepMixIn(b.previousAttributes[r],e),b.collection.push(s),b.changeHistories[r]=[],b.observers[r]=new i.ObjectObserver(s),b.observers[r].open(l,s),b.index[r]=s,l.call(s,{},{},{},null,!0)),b.saved[r]=g.updateTimestamp(b.saved[r]),j=s}catch(t){console.error(t),console.error("inject failed!",a.name,e)}}return j}function e(a,b,c){function d(b,d,f){var h=e.definitions[d];if(h&&f[b.localField]&&!k.injectedSoFar[d+f[b.localField][h.idAttribute]])try{k.injectedSoFar[d+f[b.localField][h.idAttribute]]=1,f[b.localField]=e.inject(d,f[b.localField],c)}catch(i){console.error(a.name+": Failed to inject "+b.type+' relation: "'+d+'"!',i)}else c.findBelongsTo&&"belongsTo"===b.type?g.isArray(f)?g.forEach(f,function(b){e.link(a.name,b[a.idAttribute],[d])}):e.link(a.name,f[a.idAttribute],[d]):(c.findHasMany&&"hasMany"===b.type||c.findHasOne&&"hasOne"===b.type)&&(g.isArray(f)?g.forEach(f,function(b){e.link(a.name,b[a.idAttribute],[d])}):e.link(a.name,f[a.idAttribute],[d]))}var e=this;g.forEach(a.relationList,function(a){g.isArray(b)?g.forEach(b,function(b){d(a,a.relation,b)}):d(a,a.relation,b)})}function f(a,b,c){var f=this,i=f.definitions[a];if(c=c||{},!i)throw new h.NER(a);if(!g.isObject(b)&&!g.isArray(b))throw new h.IA(a+'.inject: "attrs" must be an object or an array!');if(!g.isObject(c))throw new h.IA('"options" must be an object!');var l;j++;try{"useClass"in c||(c.useClass=i.useClass),"notify"in c||(c.notify=!0),c.notify&&i.beforeInject(i.name,b),l=d.call(f,i,f.store[a],b,c),i.relations&&e.call(f,i,l,c),c.linkInverse&&(g.isArray(l)&&l.length?f.linkInverse(i.name,l[0][i.idAttribute]):f.linkInverse(i.name,l[i.idAttribute])),c.notify&&(i.afterInject(i.name,l),f.notify(i,"inject",l)),j--}catch(m){throw j--,m}return j||(k.injectedSoFar={}),l}var g=a("../../utils"),h=a("../../errors"),i=a("../../../lib/observe-js/observe-js"),j=0,k={injectedSoFar:{}};b.exports=f},{"../../../lib/observe-js/observe-js":1,"../../errors":76,"../../utils":78}],72:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||[],b=d.resolveId(g,b),!g)throw new e.NER(a);if(!d.isString(b)&&!d.isNumber(b))throw new e.IA('"id" must be a string or a number!');if(!d.isArray(c))throw new e.IA('"relations" must be an array!');var h=f.get(a,b);return h&&d.forEach(g.relationList,function(a){var b=a.relation;if(!c.length||d.contains(c,b)){var e={};if("belongsTo"===a.type){var i=h[a.localKey]?f.get(b,h[a.localKey]):null;i&&(h[a.localField]=i)}else if("hasMany"===a.type)e[a.foreignKey]=h[g.idAttribute],h[a.localField]=f.defaults.constructor.prototype.defaultFilter.call(f,f.store[b].collection,b,e,{allowSimpleWhere:!0});else if("hasOne"===a.type){e[a.foreignKey]=h[g.idAttribute];var j=f.defaults.constructor.prototype.defaultFilter.call(f,f.store[b].collection,b,e,{allowSimpleWhere:!0});j.length&&(h[a.localField]=j[0])}}}),h}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],73:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||[],!g)throw new e.NER(a);if(!d.isArray(c))throw new e.IA('"relations" must be an array!');var h=f.filter(a,b);return h&&d.forEach(g.relationList,function(a){var b=a.relation;(!c.length||d.contains(c,b))&&("belongsTo"===a.type?d.forEach(h,function(c){var d=c[a.localKey]?f.get(b,c[a.localKey]):null;d&&(c[a.localField]=d)}):"hasMany"===a.type?d.forEach(h,function(c){var d={};d[a.foreignKey]=c[g.idAttribute],c[a.localField]=f.defaults.constructor.prototype.defaultFilter.call(f,f.store[b].collection,b,d,{allowSimpleWhere:!0})}):"hasOne"===a.type&&d.forEach(h,function(c){var d={};d[a.foreignKey]=c[g.idAttribute];var e=f.defaults.constructor.prototype.defaultFilter.call(f,f.store[b].collection,b,d,{allowSimpleWhere:!0});e.length&&(c[a.localField]=e[0])}))}),h}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],74:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||[],b=d.resolveId(g,b),!g)throw new e.NER(a);if(!d.isString(b)&&!d.isNumber(b))throw new e.IA('"id" must be a string or a number!');if(!d.isArray(c))throw new e.IA('"relations" must be an array!');var h=f.get(a,b);return h&&d.forOwn(f.definitions,function(a){d.forOwn(a.relations,function(b){d.forOwn(b,function(b,e){(!c.length||d.contains(c,a.name))&&g.name===e&&f.linkAll(a.name,{},[g.name])})})}),h}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],75:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||[],b=d.resolveId(g,b),!g)throw new e.NER(a);if(!d.isString(b)&&!d.isNumber(b))throw new e.IA('"id" must be a string or a number!');if(!d.isArray(c))throw new e.IA('"relations" must be an array!');var h=f.get(a,b);return h&&d.forOwn(f.definitions,function(a){d.forOwn(a.relations,function(a){d.forOwn(a,function(a,b){g.name===b&&d.forEach(a,function(a){d.forEach(f.store[a.name].collection,function(b){if("hasMany"===a.type&&b[a.localField]){var c;d.forEach(b[a.localField],function(a,b){a===h&&(c=b)}),b[a.localField].splice(c,1)}else b[a.localField]===h&&delete b[a.localField]})})})})}),h}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],76:[function(a,b){function c(a){Error.call(this),"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.type=this.constructor.name,this.message=a||"Illegal Argument!"}function d(a){Error.call(this),"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.type=this.constructor.name,this.message=a||"RuntimeError Error!"}function e(a){Error.call(this),"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.type=this.constructor.name,this.message=(a||"")+" is not a registered resource!"}c.prototype=Object.create(Error.prototype),c.prototype.constructor=c,d.prototype=Object.create(Error.prototype),d.prototype.constructor=d,e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,b.exports={IllegalArgumentError:c,IA:c,RuntimeError:d,R:d,NonexistentResourceError:e,NER:e}},{}],77:[function(a,b){var c=a("./datastore");b.exports={DS:c,createStore:function(){return new c},DSUtils:a("./utils"),DSErrors:a("./errors")}},{"./datastore":65,"./errors":76,"./utils":78}],78:[function(a,b){function c(a){var b={};a=a||this,a.on=function(a,c,d){b[a]=b[a]||[],b[a].push({f:c,c:d})},a.off=function(a,c){var d=b[a];if(d)if(c){for(var e=0;e<d.length;e++)if(d[e]===c){d.splice(e,1);break}}else d.splice(0,d.length);else b={}},a.emit=function(){var a=Array.prototype.slice.call(arguments),c=b[a.shift()]||[];if(c)for(var d=0;d<c.length;d++)c[d].f.apply(c[d].c,a)}}b.exports={isBoolean:a("mout/lang/isBoolean"),isString:a("mout/lang/isString"),isArray:a("mout/lang/isArray"),isObject:a("mout/lang/isObject"),isNumber:a("mout/lang/isNumber"),isFunction:a("mout/lang/isFunction"),isEmpty:a("mout/lang/isEmpty"),toJson:JSON.stringify,fromJson:JSON.parse,makePath:a("mout/string/makePath"),upperCase:a("mout/string/upperCase"),pascalCase:a("mout/string/pascalCase"),deepMixIn:a("mout/object/deepMixIn"),forOwn:a("mout/object/forOwn"),forEach:a("mout/array/forEach"),pick:a("mout/object/pick"),set:a("mout/object/set"),merge:a("mout/object/merge"),contains:a("mout/array/contains"),filter:a("mout/array/filter"),toLookup:a("mout/array/toLookup"),remove:a("mout/array/remove"),slice:a("mout/array/slice"),sort:a("mout/array/sort"),resolveItem:function(a,b){return a&&(this.isString(b)||this.isNumber(b))?a.index[b]||b:b},resolveId:function(a,b){return this.isString(b)||this.isNumber(b)?b:b&&a?b[a.idAttribute]||b:b},updateTimestamp:function(a){var b="function"==typeof Date.now?Date.now():(new Date).getTime();return a&&a>=b?a+1:b},Promise:a("es6-promise").Promise,deepFreeze:function d(a){if("function"==typeof Object.freeze){var b,c;Object.freeze(a);for(c in a)b=a[c],a.hasOwnProperty(c)&&"object"==typeof b&&!Object.isFrozen(b)&&d(b)}},compute:function(a,b,c){var d=this,e=[];c.forEach(a.deps,function(a){e.push(d[a])}),this[b]=a[a.length-1].apply(this,e)},diffObjectFromOldObject:function(a,b){var c={},d={},e={};for(var f in b){var g=a[f];(void 0===g||g!==b[f])&&(f in a?g!==b[f]&&(e[f]=g):d[f]=void 0)}for(var h in a)h in b||(c[h]=a[h]);return{added:c,removed:d,changed:e}},promisify:function(a,b){var c=this.Promise;if(a){if("function"!=typeof a)throw new Error("Can only promisify functions!");return function(){var d=Array.prototype.slice.apply(arguments);return new c(function(c,e){d.push(function(a,b){a?e(a):c(b)});try{var f=a.apply(b||this,d);f&&f.then&&f.then(c,e)}catch(g){e(g)}})}}},Events:c}},{"es6-promise":2,"mout/array/contains":13,"mout/array/filter":14,"mout/array/forEach":15,"mout/array/remove":18,"mout/array/slice":19,"mout/array/sort":20,"mout/array/toLookup":21,"mout/lang/isArray":27,"mout/lang/isBoolean":28,"mout/lang/isEmpty":29,"mout/lang/isFunction":30,"mout/lang/isNumber":32,"mout/lang/isObject":33,"mout/lang/isString":35,"mout/object/deepMixIn":39,"mout/object/forOwn":41,"mout/object/merge":43,"mout/object/pick":46,"mout/object/set":47,"mout/string/makePath":50,"mout/string/pascalCase":51,"mout/string/upperCase":54}]},{},[77])(77)}); | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.JSData=a()}}(function(){var define,module,exports;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(require,module,exports){!function(global){"use strict";function detectObjectObserve(){function a(a){b=a}if("function"!=typeof Object.observe||"function"!=typeof Array.observe)return!1;var b=[],c={},d=[];return Object.observe(c,a),Array.observe(d,a),c.id=1,c.id=2,delete c.id,d.push(1,2),d.length=0,Object.deliverChangeRecords(a),5!==b.length?!1:"add"!=b[0].type||"update"!=b[1].type||"delete"!=b[2].type||"splice"!=b[3].type||"splice"!=b[4].type?!1:(Object.unobserve(c,a),Array.unobserve(d,a),!0)}function detectEval(){if("undefined"!=typeof chrome&&chrome.app&&chrome.app.runtime)return!1;try{var a=new Function("","return true;");return a()}catch(b){return!1}}function dirtyCheck(a){for(var b=0;MAX_DIRTY_CHECK_CYCLES>b&&a.check_();)b++;return global.testingExposeCycleCount&&(global.dirtyCheckCycleCount=b),b>0}function objectIsEmpty(a){for(var b in a)return!1;return!0}function diffIsEmpty(a){return objectIsEmpty(a.added)&&objectIsEmpty(a.removed)&&objectIsEmpty(a.changed)}function diffObjectFromOldObject(a,b){var c={},d={},e={};for(var f in b){var g=a[f];(void 0===g||g!==b[f])&&(f in a?g!==b[f]&&(e[f]=g):d[f]=void 0)}for(var f in a)f in b||(c[f]=a[f]);return Array.isArray(a)&&a.length!==b.length&&(e.length=a.length),{added:c,removed:d,changed:e}}function runEOMTasks(){if(!eomTasks.length)return!1;for(var a=0;a<eomTasks.length;a++)eomTasks[a]();return eomTasks.length=0,!0}function newObservedObject(){function a(a){b&&b.state_===OPENED&&!d&&b.check_(a)}var b,c,d=!1,e=!0;return{open:function(c){if(b)throw Error("ObservedObject in use");e||Object.deliverChangeRecords(a),b=c,e=!1},observe:function(b,d){c=b,d?Array.observe(c,a):Object.observe(c,a)},deliver:function(b){d=b,Object.deliverChangeRecords(a),d=!1},close:function(){b=void 0,Object.unobserve(c,a),observedObjectCache.push(this)}}}function getObservedObject(a,b,c){var d=observedObjectCache.pop()||newObservedObject();return d.open(a),d.observe(b,c),d}function Observer(){this.state_=UNOPENED,this.callback_=void 0,this.target_=void 0,this.directObserver_=void 0,this.value_=void 0,this.id_=nextObserverId++}function addToAll(a){Observer._allObserversCount++,collectObservers&&allObservers.push(a)}function removeFromAll(){Observer._allObserversCount--}function ObjectObserver(a){Observer.call(this),this.value_=a,this.oldObject_=void 0}function diffObjectFromChangeRecords(a,b,c){for(var d={},e={},f=0;f<b.length;f++){var g=b[f];expectedRecordTypes[g.type]?(g.name in c||(c[g.name]=g.oldValue),"update"!=g.type&&("add"!=g.type?g.name in d?(delete d[g.name],delete c[g.name]):e[g.name]=!0:g.name in e?delete e[g.name]:d[g.name]=!0)):(console.error("Unknown changeRecord type: "+g.type),console.error(g))}for(var h in d)d[h]=a[h];for(var h in e)e[h]=void 0;var i={};for(var h in c)if(!(h in d||h in e)){var j=a[h];c[h]!==j&&(i[h]=j)}return{added:d,removed:e,changed:i}}var hasObserve=detectObjectObserve(),hasEval=detectEval(),createObject="__proto__"in{}?function(a){return a}:function(a){var b=a.__proto__;if(!b)return a;var c=Object.create(b);return Object.getOwnPropertyNames(a).forEach(function(b){Object.defineProperty(c,b,Object.getOwnPropertyDescriptor(a,b))}),c},MAX_DIRTY_CHECK_CYCLES=1e3,eomTasks=[],runEOM=hasObserve?function(){var a={pingPong:!0},b=!1;return Object.observe(a,function(){runEOMTasks(),b=!1}),function(c){eomTasks.push(c),b||(b=!0,a.pingPong=!a.pingPong)}}():function(){return function(a){eomTasks.push(a)}}(),observedObjectCache=[],UNOPENED=0,OPENED=1,CLOSED=2,nextObserverId=1;Observer.prototype={open:function(a,b){if(this.state_!=UNOPENED)throw Error("Observer has already been opened.");return addToAll(this),this.callback_=a,this.target_=b,this.connect_(),this.state_=OPENED,this.value_},close:function(){this.state_==OPENED&&(removeFromAll(this),this.disconnect_(),this.value_=void 0,this.callback_=void 0,this.target_=void 0,this.state_=CLOSED)},deliver:function(){this.state_==OPENED&&dirtyCheck(this)},report_:function(a){try{this.callback_.apply(this.target_,a)}catch(b){Observer._errorThrownDuringCallback=!0,console.error("Exception caught during observer callback: "+(b.stack||b))}},discardChanges:function(){return this.check_(void 0,!0),this.value_}};var collectObservers=!hasObserve,allObservers;Observer._allObserversCount=0,collectObservers&&(allObservers=[]);var runningMicrotaskCheckpoint=!1,hasDebugForceFullDelivery=hasObserve&&hasEval&&function(){try{return eval("%RunMicrotasks()"),!0}catch(ex){return!1}}();global.Platform=global.Platform||{},global.Platform.performMicrotaskCheckpoint=function(){if(!runningMicrotaskCheckpoint){if(hasDebugForceFullDelivery)return void eval("%RunMicrotasks()");if(collectObservers){runningMicrotaskCheckpoint=!0;var cycles=0,anyChanged,toCheck;do{cycles++,toCheck=allObservers,allObservers=[],anyChanged=!1;for(var i=0;i<toCheck.length;i++){var observer=toCheck[i];observer.state_==OPENED&&(observer.check_()&&(anyChanged=!0),allObservers.push(observer))}runEOMTasks()&&(anyChanged=!0)}while(MAX_DIRTY_CHECK_CYCLES>cycles&&anyChanged);global.testingExposeCycleCount&&(global.dirtyCheckCycleCount=cycles),runningMicrotaskCheckpoint=!1}}},collectObservers&&(global.Platform.clearObservers=function(){allObservers=[]}),ObjectObserver.prototype=createObject({__proto__:Observer.prototype,arrayObserve:!1,connect_:function(){hasObserve?this.directObserver_=getObservedObject(this,this.value_,this.arrayObserve):this.oldObject_=this.copyObject(this.value_)},copyObject:function(a){var b=Array.isArray(a)?[]:{};for(var c in a)b[c]=a[c];return Array.isArray(a)&&(b.length=a.length),b},check_:function(a){var b,c;if(hasObserve){if(!a)return!1;c={},b=diffObjectFromChangeRecords(this.value_,a,c)}else c=this.oldObject_,b=diffObjectFromOldObject(this.value_,this.oldObject_);return diffIsEmpty(b)?!1:(hasObserve||(this.oldObject_=this.copyObject(this.value_)),this.report_([b.added||{},b.removed||{},b.changed||{},function(a){return c[a]}]),!0)},disconnect_:function(){hasObserve?(this.directObserver_.close(),this.directObserver_=void 0):this.oldObject_=void 0},deliver:function(){this.state_==OPENED&&(hasObserve?this.directObserver_.deliver(!1):dirtyCheck(this))},discardChanges:function(){return this.directObserver_?this.directObserver_.deliver(!0):this.oldObject_=this.copyObject(this.value_),this.value_}});var observerSentinel={},expectedRecordTypes={add:!0,update:!0,"delete":!0};global.Observer=Observer,global.Observer.runEOM_=runEOM,global.Observer.observerSentinel_=observerSentinel,global.Observer.hasObjectObserve=hasObserve,global.ObjectObserver=ObjectObserver}((exports.Number={isNaN:window.isNaN})?exports:exports)},{}],2:[function(a,b,c){"use strict";var d=a("./promise/promise").Promise,e=a("./promise/polyfill").polyfill;c.Promise=d,c.polyfill=e},{"./promise/polyfill":6,"./promise/promise":7}],3:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to all.");return new b(function(b,c){function d(a){return function(b){e(a,b)}}function e(a,c){h[a]=c,0===--i&&b(h)}var g,h=[],i=a.length;0===i&&b([]);for(var j=0;j<a.length;j++)g=a[j],g&&f(g.then)?g.then(d(j),c):e(j,g)})}var e=a("./utils").isArray,f=a("./utils").isFunction;c.all=d},{"./utils":11}],4:[function(a,b,c){(function(a,b){"use strict";function d(){return function(){a.nextTick(g)}}function e(){var a=0,b=new k(g),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function f(){return function(){l.setTimeout(g,1)}}function g(){for(var a=0;a<m.length;a++){var b=m[a],c=b[0],d=b[1];c(d)}m=[]}function h(a,b){var c=m.push([a,b]);1===c&&i()}var i,j="undefined"!=typeof window?window:{},k=j.MutationObserver||j.WebKitMutationObserver,l="undefined"!=typeof b?b:void 0===this?window:this,m=[];i="undefined"!=typeof a&&"[object process]"==={}.toString.call(a)?d():k?e():f(),c.asap=h}).call(this,a("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:12}],5:[function(a,b,c){"use strict";function d(a,b){return 2!==arguments.length?e[a]:void(e[a]=b)}var e={instrument:!1};c.config=e,c.configure=d},{}],6:[function(a,b,c){(function(b){"use strict";function d(){var a;a="undefined"!=typeof b?b:"undefined"!=typeof window&&window.document?window:self;var c="Promise"in a&&"resolve"in a.Promise&&"reject"in a.Promise&&"all"in a.Promise&&"race"in a.Promise&&function(){var b;return new a.Promise(function(a){b=a}),f(b)}();c||(a.Promise=e)}var e=a("./promise").Promise,f=a("./utils").isFunction;c.polyfill=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./promise":7,"./utils":11}],7:[function(a,b,c){"use strict";function d(a){if(!q(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof d))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._subscribers=[],e(a,this)}function e(a,b){function c(a){j(b,a)}function d(a){l(b,a)}try{a(c,d)}catch(e){d(e)}}function f(a,b,c,d){var e,f,g,h,k=q(c);if(k)try{e=c(d),g=!0}catch(m){h=!0,f=m}else e=d,g=!0;i(b,e)||(k&&g?j(b,e):h?l(b,f):a===y?j(b,e):a===z&&l(b,e))}function g(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+y]=c,e[f+z]=d}function h(a,b){for(var c,d,e=a._subscribers,g=a._detail,h=0;h<e.length;h+=3)c=e[h],d=e[h+b],f(b,c,d,g);a._subscribers=null}function i(a,b){var c,d=null;try{if(a===b)throw new TypeError("A promises callback cannot return that same promise.");if(p(b)&&(d=b.then,q(d)))return d.call(b,function(d){return c?!0:(c=!0,void(b!==d?j(a,d):k(a,d)))},function(b){return c?!0:(c=!0,void l(a,b))}),!0}catch(e){return c?!0:(l(a,e),!0)}return!1}function j(a,b){a===b?k(a,b):i(a,b)||k(a,b)}function k(a,b){a._state===w&&(a._state=x,a._detail=b,o.async(m,a))}function l(a,b){a._state===w&&(a._state=x,a._detail=b,o.async(n,a))}function m(a){h(a,a._state=y)}function n(a){h(a,a._state=z)}var o=a("./config").config,p=(a("./config").configure,a("./utils").objectOrFunction),q=a("./utils").isFunction,r=(a("./utils").now,a("./all").all),s=a("./race").race,t=a("./resolve").resolve,u=a("./reject").reject,v=a("./asap").asap;o.async=v;var w=void 0,x=0,y=1,z=2;d.prototype={constructor:d,_state:void 0,_detail:void 0,_subscribers:void 0,then:function(a,b){var c=this,d=new this.constructor(function(){});if(this._state){var e=arguments;o.async(function(){f(c._state,d,e[c._state-1],c._detail)})}else g(this,d,a,b);return d},"catch":function(a){return this.then(null,a)}},d.all=r,d.race=s,d.resolve=t,d.reject=u,c.Promise=d},{"./all":3,"./asap":4,"./config":5,"./race":8,"./reject":9,"./resolve":10,"./utils":11}],8:[function(a,b,c){"use strict";function d(a){var b=this;if(!e(a))throw new TypeError("You must pass an array to race.");return new b(function(b,c){for(var d,e=0;e<a.length;e++)d=a[e],d&&"function"==typeof d.then?d.then(b,c):b(d)})}var e=a("./utils").isArray;c.race=d},{"./utils":11}],9:[function(a,b,c){"use strict";function d(a){var b=this;return new b(function(b,c){c(a)})}c.reject=d},{}],10:[function(a,b,c){"use strict";function d(a){if(a&&"object"==typeof a&&a.constructor===this)return a;var b=this;return new b(function(b){b(a)})}c.resolve=d},{}],11:[function(a,b,c){"use strict";function d(a){return e(a)||"object"==typeof a&&null!==a}function e(a){return"function"==typeof a}function f(a){return"[object Array]"===Object.prototype.toString.call(a)}var g=Date.now||function(){return(new Date).getTime()};c.objectOrFunction=d,c.isFunction=e,c.isArray=f,c.now=g},{}],12:[function(a,b){function c(){}var d=b.exports={};d.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){var b=a.source;if((b===window||null===b)&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var d=c.shift();d()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),d.title="browser",d.browser=!0,d.env={},d.argv=[],d.on=c,d.addListener=c,d.once=c,d.off=c,d.removeListener=c,d.removeAllListeners=c,d.emit=c,d.binding=function(){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(){throw new Error("process.chdir is not supported")}},{}],13:[function(a,b){function c(a,b){return-1!==d(a,b)}var d=a("./indexOf");b.exports=c},{"./indexOf":16}],14:[function(a,b){function c(a,b,c){b=d(b,c);var e=[];if(null==a)return e;for(var f,g=-1,h=a.length;++g<h;)f=a[g],b(f,g,a)&&e.push(f);return e}var d=a("../function/makeIterator_");b.exports=c},{"../function/makeIterator_":23}],15:[function(a,b){function c(a,b,c){if(null!=a)for(var d=-1,e=a.length;++d<e&&b.call(c,a[d],d,a)!==!1;);}b.exports=c},{}],16:[function(a,b){function c(a,b,c){if(c=c||0,null==a)return-1;for(var d=a.length,e=0>c?d+c:c;d>e;){if(a[e]===b)return e;e++}return-1}b.exports=c},{}],17:[function(a,b){function c(a){return null!=a&&""!==a}function d(a,b){return b=b||"",e(a,c).join(b)}var e=a("./filter");b.exports=d},{"./filter":14}],18:[function(a,b){function c(a,b){var c=d(a,b);-1!==c&&a.splice(c,1)}var d=a("./indexOf");b.exports=c},{"./indexOf":16}],19:[function(a,b){function c(a,b,c){var d=a.length;b=null==b?0:0>b?Math.max(d+b,0):Math.min(b,d),c=null==c?d:0>c?Math.max(d+c,0):Math.min(c,d);for(var e=[];c>b;)e.push(a[b++]);return e}b.exports=c},{}],20:[function(a,b){function c(a,b){if(null==a)return[];if(a.length<2)return a;null==b&&(b=d);var f,g,h;return f=~~(a.length/2),g=c(a.slice(0,f),b),h=c(a.slice(f,a.length),b),e(g,h,b)}function d(a,b){return b>a?-1:a>b?1:0}function e(a,b,c){for(var d=[];a.length&&b.length;)d.push(c(a[0],b[0])<=0?a.shift():b.shift());return a.length&&d.push.apply(d,a),b.length&&d.push.apply(d,b),d}b.exports=c},{}],21:[function(a,b){function c(a,b){var c={};if(null==a)return c;var e,f=-1,g=a.length;if(d(b))for(;++f<g;)e=a[f],c[b(e)]=e;else for(;++f<g;)e=a[f],c[e[b]]=e;return c}var d=a("../lang/isFunction");b.exports=c},{"../lang/isFunction":30}],22:[function(a,b){function c(a){return a}b.exports=c},{}],23:[function(a,b){function c(a,b){if(null==a)return d;switch(typeof a){case"function":return"undefined"!=typeof b?function(c,d,e){return a.call(b,c,d,e)}:a;case"object":return function(b){return f(b,a)};case"string":case"number":return e(a)}}var d=a("./identity"),e=a("./prop"),f=a("../object/deepMatches");b.exports=c},{"../object/deepMatches":38,"./identity":22,"./prop":24}],24:[function(a,b){function c(a){return function(b){return b[a]}}b.exports=c},{}],25:[function(a,b){function c(a){switch(h(a)){case"Object":return d(a);case"Array":return g(a);case"RegExp":return e(a);case"Date":return f(a);default:return a}}function d(a){return i(a)?j({},a):a}function e(a){var b="";return b+=a.multiline?"m":"",b+=a.global?"g":"",b+=a.ignorecase?"i":"",new RegExp(a.source,b)}function f(a){return new Date(+a)}function g(a){return a.slice()}var h=a("./kindOf"),i=a("./isPlainObject"),j=a("../object/mixIn");b.exports=c},{"../object/mixIn":44,"./isPlainObject":34,"./kindOf":36}],26:[function(a,b){function c(a,b){switch(h(a)){case"Object":return d(a,b);case"Array":return e(a,b);default:return f(a)}}function d(a,b){if(i(a)){var d={};return g(a,function(a,d){this[d]=c(a,b)},d),d}return b?b(a):a}function e(a,b){for(var d=[],e=-1,f=a.length;++e<f;)d[e]=c(a[e],b);return d}var f=a("./clone"),g=a("../object/forOwn"),h=a("./kindOf"),i=a("./isPlainObject");b.exports=c},{"../object/forOwn":41,"./clone":25,"./isPlainObject":34,"./kindOf":36}],27:[function(a,b){var c=a("./isKind"),d=Array.isArray||function(a){return c(a,"Array")};b.exports=d},{"./isKind":31}],28:[function(a,b){function c(a){return d(a,"Boolean")}var d=a("./isKind");b.exports=c},{"./isKind":31}],29:[function(a,b){function c(a){if(null==a)return!0;if("string"==typeof a||e(a))return!a.length;if("object"==typeof a){var b=!0;return d(a,function(){return b=!1,!1}),b}return!0}var d=a("../object/forOwn"),e=a("./isArray");b.exports=c},{"../object/forOwn":41,"./isArray":27}],30:[function(a,b){function c(a){return d(a,"Function")}var d=a("./isKind");b.exports=c},{"./isKind":31}],31:[function(a,b){function c(a,b){return d(a)===b}var d=a("./kindOf");b.exports=c},{"./kindOf":36}],32:[function(a,b){function c(a){return d(a,"Number")}var d=a("./isKind");b.exports=c},{"./isKind":31}],33:[function(a,b){function c(a){return d(a,"Object")}var d=a("./isKind");b.exports=c},{"./isKind":31}],34:[function(a,b){function c(a){return!!a&&"object"==typeof a&&a.constructor===Object}b.exports=c},{}],35:[function(a,b){function c(a){return d(a,"String")}var d=a("./isKind");b.exports=c},{"./isKind":31}],36:[function(a,b){function c(a){return null===a?"Null":a===d?"Undefined":e.exec(f.call(a))[1]}var d,e=/^\[object (.*)\]$/,f=Object.prototype.toString;b.exports=c},{}],37:[function(a,b){function c(a){return null==a?"":a.toString()}b.exports=c},{}],38:[function(a,b){function c(a,b){for(var c=-1,d=a.length;++c<d;)if(f(a[c],b))return!0;return!1}function d(a,b){for(var d=-1,e=b.length;++d<e;)if(!c(a,b[d]))return!1;return!0}function e(a,b){var c=!0;return g(b,function(b,d){return f(a[d],b)?void 0:c=!1}),c}function f(a,b){return a&&"object"==typeof a?h(a)&&h(b)?d(a,b):e(a,b):a===b}var g=a("./forOwn"),h=a("../lang/isArray");b.exports=f},{"../lang/isArray":27,"./forOwn":41}],39:[function(a,b){function c(a){for(var b,c=0,f=arguments.length;++c<f;)b=arguments[c],b&&e(b,d,a);return a}function d(a,b){var d=this[b];f(a)&&f(d)?c(d,a):this[b]=a}var e=a("./forOwn"),f=a("../lang/isPlainObject");b.exports=c},{"../lang/isPlainObject":34,"./forOwn":41}],40:[function(a,b){function c(){g=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=!0;for(var a in{toString:null})f=!1}function d(a,b,d){var i,j=0;null==f&&c();for(i in a)if(e(b,a,i,d)===!1)break;if(f)for(var k=a.constructor,l=!!k&&a===k.prototype;(i=g[j++])&&("constructor"===i&&(l||!h(a,i))||a[i]===Object.prototype[i]||e(b,a,i,d)!==!1););}function e(a,b,c,d){return a.call(d,b[c],c,b)}var f,g,h=a("./hasOwn");b.exports=d},{"./hasOwn":42}],41:[function(a,b){function c(a,b,c){e(a,function(e,f){return d(a,f)?b.call(c,a[f],f,a):void 0})}var d=a("./hasOwn"),e=a("./forIn");b.exports=c},{"./forIn":40,"./hasOwn":42}],42:[function(a,b){function c(a,b){return Object.prototype.hasOwnProperty.call(a,b)}b.exports=c},{}],43:[function(a,b){function c(){var a,b,g,h,i=1;for(h=e(arguments[0]);g=arguments[i++];)for(a in g)d(g,a)&&(b=g[a],h[a]=f(b)&&f(h[a])?c(h[a],b):e(b));return h}var d=a("./hasOwn"),e=a("../lang/deepClone"),f=a("../lang/isObject");b.exports=c},{"../lang/deepClone":26,"../lang/isObject":33,"./hasOwn":42}],44:[function(a,b){function c(a){for(var b,c=0,f=arguments.length;++c<f;)b=arguments[c],null!=b&&e(b,d,a);return a}function d(a,b){this[b]=a}var e=a("./forOwn");b.exports=c},{"./forOwn":41}],45:[function(a,b){function c(a,b){return b?(d(b.split("."),function(b){a[b]||(a[b]={}),a=a[b]}),a):a}var d=a("../array/forEach");b.exports=c},{"../array/forEach":15}],46:[function(a,b){function c(a){for(var b,c="string"!=typeof arguments[1]?arguments[1]:d(arguments,1),e={},f=0;b=c[f++];)e[b]=a[b];return e}var d=a("../array/slice");b.exports=c},{"../array/slice":19}],47:[function(a,b){function c(a,b,c){var e=/^(.+)\.(.+)$/.exec(b);e?d(a,e[1])[e[2]]=c:a[b]=c}var d=a("./namespace");b.exports=c},{"./namespace":45}],48:[function(a,b){function c(a){return a=d(a),a=e(a),a=f(a).replace(/[\-_]/g," ").replace(/\s[a-z]/g,g).replace(/\s+/g,"").replace(/^[A-Z]/g,h)}var d=a("../lang/toString"),e=a("./replaceAccents"),f=a("./removeNonWord"),g=a("./upperCase"),h=a("./lowerCase");b.exports=c},{"../lang/toString":37,"./lowerCase":49,"./removeNonWord":52,"./replaceAccents":53,"./upperCase":54}],49:[function(a,b){function c(a){return a=d(a),a.toLowerCase()}var d=a("../lang/toString");b.exports=c},{"../lang/toString":37}],50:[function(a,b){function c(){var a=d(e(arguments),"/");return a.replace(/([^:\/]|^)\/{2,}/g,"$1/")}var d=a("../array/join"),e=a("../array/slice");b.exports=c},{"../array/join":17,"../array/slice":19}],51:[function(a,b){function c(a){return a=d(a),e(a).replace(/^[a-z]/,f)}var d=a("../lang/toString"),e=a("./camelCase"),f=a("./upperCase");b.exports=c},{"../lang/toString":37,"./camelCase":48,"./upperCase":54}],52:[function(a,b){function c(a){return a=d(a),a.replace(e,"")}var d=a("../lang/toString"),e=/[^\x20\x2D0-9A-Z\x5Fa-z\xC0-\xD6\xD8-\xF6\xF8-\xFF]/g;b.exports=c},{"../lang/toString":37}],53:[function(a,b){function c(a){return a=d(a),a.search(/[\xC0-\xFF]/g)>-1&&(a=a.replace(/[\xC0-\xC5]/g,"A").replace(/[\xC6]/g,"AE").replace(/[\xC7]/g,"C").replace(/[\xC8-\xCB]/g,"E").replace(/[\xCC-\xCF]/g,"I").replace(/[\xD0]/g,"D").replace(/[\xD1]/g,"N").replace(/[\xD2-\xD6\xD8]/g,"O").replace(/[\xD9-\xDC]/g,"U").replace(/[\xDD]/g,"Y").replace(/[\xDE]/g,"P").replace(/[\xE0-\xE5]/g,"a").replace(/[\xE6]/g,"ae").replace(/[\xE7]/g,"c").replace(/[\xE8-\xEB]/g,"e").replace(/[\xEC-\xEF]/g,"i").replace(/[\xF1]/g,"n").replace(/[\xF2-\xF6\xF8]/g,"o").replace(/[\xF9-\xFC]/g,"u").replace(/[\xFE]/g,"p").replace(/[\xFD\xFF]/g,"y")),a}var d=a("../lang/toString");b.exports=c},{"../lang/toString":37}],54:[function(a,b){function c(a){return a=d(a),a.toUpperCase()}var d=a("../lang/toString");b.exports=c},{"../lang/toString":37}],55:[function(a,b){function c(a,b,c){var g=this,h=g.definitions[a],i=new d.Promise(function(d,f){c=c||{},h?("cacheResponse"in c||(c.cacheResponse=!0),"upsert"in c||(c.upsert=!0),"notify"in c||(c.notify=h.notify),d(b)):f(new e.NER(a))});return c.upsert&&b[h.idAttribute]?g.update(a,b[h.idAttribute],b,c):i.then(function(b){var d=c.beforeValidate?f(c.beforeValidate):h.beforeValidate;return d.call(b,a,b)}).then(function(b){var d=c.validate?f(c.validate):h.validate;return d.call(b,a,b)}).then(function(b){var d=c.afterValidate?f(c.afterValidate):h.afterValidate;return d.call(b,a,b)}).then(function(b){var d=c.beforeCreate?f(c.beforeCreate):h.beforeCreate;return d.call(b,a,b)}).then(function(a){return c.notify&&g.emit(h,"beforeCreate",d.merge({},a)),g.getAdapter(h,c).create(h,a,c)}).then(function(b){var d=c.afterCreate?f(c.afterCreate):h.afterCreate;return d.call(b,a,b)}).then(function(b){if(c.notify&&g.emit(h,"afterCreate",d.merge({},b)),c.cacheResponse){var e=g.store[a],f=g.inject(h.name,b,c),i=f[h.idAttribute];return e.completedQueries[i]=(new Date).getTime(),e.previousAttributes[i]=d.deepMixIn({},f),e.saved[i]=d.updateTimestamp(e.saved[i]),g.get(h.name,i)}return g.createInstance(a,b,c)})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],56:[function(a,b){function c(a,b,c){var g,h=this,i=h.definitions[a];return new d.Promise(function(f,j){c=c||{},b=d.resolveId(i,b),i?d.isString(b)||d.isNumber(b)?h.get(a,b)?d.isObject(c)?(g=h.get(a,b),"notify"in c||(c.notify=i.notify),"eagerEject"in c||(c.eagerEject=i.eagerEject),f(g)):j(new e.IA('"options" must be an object!')):j(new e.R('id "'+b+'" not found in cache!')):j(new e.IA('"id" must be a string or a number!')):j(new e.NER(a))}).then(function(b){var d=c.beforeDestroy?f(c.beforeDestroy):i.beforeDestroy;return d.call(b,a,b)}).then(function(e){return c.notify&&h.emit(i,"beforeDestroy",d.merge({},e)),c.eagerEject&&h.eject(a,b),h.getAdapter(i,c).destroy(i,b,c)}).then(function(){var b=c.afterDestroy?f(c.afterDestroy):i.afterDestroy;return b.call(g,a,g)}).then(function(e){return c.notify&&h.emit(i,"afterDestroy",d.merge({},e)),h.eject(a,b),b}).catch(function(b){throw c.eagerEject&&g&&h.inject(a,g,{notify:!1}),b})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],57:[function(a,b){function c(a,b,c){var f,g,h=this,i=h.definitions[a];return new d.Promise(function(b,f){c=c||{},i?d.isObject(c)?("notify"in c||(c.notify=i.notify),"eagerEject"in c||(c.eagerEject=i.eagerEject),b()):f(new e.IA('"options" must be an object!')):f(new e.NER(a))}).then(function(){var e=c.beforeDestroy?d.promisify(c.beforeDestroy):i.beforeDestroy;return g=h.defaults.defaultFilter.call(h,a,b),e(a,g)}).then(function(){return c.notify&&h.emit(i,"beforeDestroy",g),c.eagerEject&&(f=h.ejectAll(a,b)),h.getAdapter(i,c).destroyAll(i,b,c)}).then(function(){var b=c.afterDestroy?d.promisify(c.afterDestroy):i.afterDestroy;return b(a,g)}).then(function(){return c.notify&&h.emit(i,"afterDestroy",g),f||h.ejectAll(a,b)}).catch(function(b){throw c.eagerEject&&f&&h.inject(a,f,{notify:!1}),b})}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],58:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a],h=f.store[a];return new d.Promise(function(i,j){c=c||{},g?d.isString(b)||d.isNumber(b)?d.isObject(c)?("cacheResponse"in c||(c.cacheResponse=!0),(c.bypassCache||!c.cacheResponse)&&delete h.completedQueries[b],b in h.completedQueries?i(f.get(a,b)):i()):j(new e.IA('"options" must be an object!')):j(new e.IA('"id" must be a string or a number!')):j(new e.NER(a))}).then(function(d){return b in h.completedQueries?d:(b in h.pendingQueries||(h.pendingQueries[b]=f.getAdapter(g,c).find(g,b,c).then(function(d){return c.cacheResponse?(delete h.pendingQueries[b],h.completedQueries[b]=(new Date).getTime(),f.inject(a,d,c)):f.createInstance(a,d,c)})),h.pendingQueries[b])}).catch(function(a){throw delete h.pendingQueries[b],a})}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],59:[function(a,b){function c(a,b,c,d){var f=this,g=f.store[b],h=f.definitions[b].idAttribute,i=(new Date).getTime();a=a||[],delete g.pendingQueries[c],g.completedQueries[c]=i,g.collectionModified=e.updateTimestamp(g.collectionModified);var j=f.inject(b,a,d);return e.isArray(j)?e.forEach(j,function(a){a&&a[h]&&(g.completedQueries[a[h]]=i)}):(console.warn(errorPrefix(b)+"response is expected to be an array!"),g.completedQueries[j[h]]=i),j}function d(a,b,d){var g,h=this,i=h.definitions[a],j=h.store[a];return new e.Promise(function(c,i){d=d||{},b=b||{},h.definitions[a]?e.isObject(b)?e.isObject(d)?("cacheResponse"in d||(d.cacheResponse=!0),g=e.toJson(b),(d.bypassCache||!d.cacheResponse)&&delete j.completedQueries[g],g in j.completedQueries?c(h.filter(a,b,d)):c()):i(new f.IA('"options" must be an object!')):i(new f.IA('"params" must be an object!')):i(new f.NER(a))}).then(function(f){return g in j.completedQueries?f:(g in j.pendingQueries||(j.pendingQueries[g]=h.getAdapter(i,d).findAll(i,b,d).then(function(b){return delete j.pendingQueries[g],d.cacheResponse?c.call(h,b,a,g,d):(e.forEach(b,function(c,e){b[e]=h.createInstance(a,c,d)}),b)})),j.pendingQueries[g])}).catch(function(a){throw delete j.pendingQueries[g],a})}var e=a("../../utils"),f=a("../../errors");b.exports=d},{"../../errors":76,"../../utils":78}],60:[function(a,b){function c(a,b,c){var f=this;return new d.Promise(function(g,h){c=c||{},b=d.resolveId(f.definitions[a],b),f.definitions[a]?d.isString(b)||d.isNumber(b)?d.isObject(c)?(c.bypassCache=!0,g(f.get(a,b))):h(new e.IA('"options" must be an object!')):h(new e.IA('"id" must be a string or a number!')):h(new f.errors.NER(a))}).then(function(d){return d?f.find(a,b,c):d})}var d=a("../../utils"),e=a("../../errors");b.exports={create:a("./create"),destroy:a("./destroy"),destroyAll:a("./destroyAll"),find:a("./find"),findAll:a("./findAll"),loadRelations:a("./loadRelations"),refresh:c,save:a("./save"),update:a("./update"),updateAll:a("./updateAll")}},{"../../errors":76,"../../utils":78,"./create":55,"./destroy":56,"./destroyAll":57,"./find":58,"./findAll":59,"./loadRelations":61,"./save":62,"./update":63,"./updateAll":64}],61:[function(a,b){function c(a,b,c,f){var g=this,h=g.definitions[a],i=[];return new d.Promise(function(j,k){if(f=f||{},(d.isString(b)||d.isNumber(b))&&(b=g.get(a,b)),d.isString(c)&&(c=[c]),h)if(d.isObject(b))if(d.isArray(c))if(d.isObject(f)){"findBelongsTo"in f||(f.findBelongsTo=!0),"findHasMany"in f||(f.findHasMany=!0);var l=[];d.forEach(h.relationList,function(a){var e=a.relation;if(d.contains(c,e)){var j,k={};k[a.foreignKey]=b[h.idAttribute],"hasMany"===a.type&&k[a.foreignKey]?j=g.findAll(e,k,f):"hasOne"===a.type?a.localKey&&b[a.localKey]?j=g.find(e,b[a.localKey],f):a.foreignKey&&k[a.foreignKey]&&(j=g.findAll(e,k,f).then(function(a){return a.length?a[0]:null})):b[a.localKey]&&(j=g.find(e,b[a.localKey],f)),j&&(l.push(j),i.push(a.localField))}}),j(l)}else k(new e.IA('"options" must be an object!'));else k(new e.IA('"relations" must be a string or an array!'));else k(new e.IA('"instance(id)" must be a string, number or object!'));else k(new e.NER(a))}).then(function(a){return d.Promise.all(a)}).then(function(a){return d.forEach(i,function(c,d){b[c]=a[d]}),b})}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],62:[function(a,b){function c(a,b,c){var g,h=this,i=h.definitions[a];return new d.Promise(function(f,j){c=c||{},b=d.resolveId(i,b),i?d.isString(b)||d.isNumber(b)?d.isObject(c)?h.get(a,b)?(g=h.get(a,b),"cacheResponse"in c||(c.cacheResponse=!0),"notify"in c||(c.notify=i.notify),f(g)):j(new e.R('id "'+b+'" not found in cache!')):j(new e.IA('"options" must be an object!')):j(new e.IA('"id" must be a string or a number!')):j(new e.NER(a))}).then(function(b){var d=c.beforeValidate?f(c.beforeValidate):i.beforeValidate;return d.call(b,a,b)}).then(function(b){var d=c.validate?f(c.validate):i.validate;return d.call(b,a,b)}).then(function(b){var d=c.afterValidate?f(c.afterValidate):i.afterValidate;return d.call(b,a,b)}).then(function(b){var d=c.beforeUpdate?f(c.beforeUpdate):i.beforeUpdate;return d.call(b,a,b)}).then(function(e){if(c.notify&&h.emit(i,"beforeUpdate",d.merge({},e)),c.changesOnly){var f=h.store[a];f.observers[b].deliver();var g=[],j=h.changes(a,b);for(var k in j.added)g.push(k);for(k in j.changed)g.push(k);if(j=d.pick(e,g),d.isEmpty(j))return e;e=j}return h.getAdapter(i,c).update(i,b,e,c)}).then(function(b){var d=c.afterUpdate?f(c.afterUpdate):i.afterUpdate;return d.call(b,a,b)}).then(function(e){if(c.notify&&h.emit(i,"afterUpdate",d.merge({},e)),c.cacheResponse){var f=h.store[a],g=h.inject(i.name,e,c);return f.previousAttributes[b]=d.deepMixIn({},g),f.saved[b]=d.updateTimestamp(f.saved[b]),f.observers[b].discardChanges(),h.get(a,b)}return e})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],63:[function(a,b){function c(a,b,c,g){var h=this,i=h.definitions[a];return new d.Promise(function(f,h){g=g||{},b=d.resolveId(i,b),i?d.isString(b)||d.isNumber(b)?d.isObject(g)?("cacheResponse"in g||(g.cacheResponse=!0),"notify"in g||(g.notify=i.notify),f(c)):h(new e.IA('"options" must be an object!')):h(new e.IA('"id" must be a string or a number!')):h(new e.NER(a))}).then(function(b){var c=g.beforeValidate?f(g.beforeValidate):i.beforeValidate;return c.call(b,a,b)}).then(function(b){var c=g.validate?f(g.validate):i.validate;return c.call(b,a,b)}).then(function(b){var c=g.afterValidate?f(g.afterValidate):i.afterValidate;return c.call(b,a,b)}).then(function(b){var c=g.beforeUpdate?f(g.beforeUpdate):i.beforeUpdate;return c.call(b,a,b)}).then(function(a){return g.notify&&h.emit(i,"beforeUpdate",d.merge({},a)),h.getAdapter(i,g).update(i,b,a,g) | ||
}).then(function(b){var c=g.afterUpdate?f(g.afterUpdate):i.afterUpdate;return c.call(b,a,b)}).then(function(b){if(g.notify&&h.emit(i,"afterUpdate",d.merge({},b)),g.cacheResponse){var c=h.store[a],e=h.inject(i.name,b,g),f=e[i.idAttribute];return c.previousAttributes[f]=d.deepMixIn({},e),c.saved[f]=d.updateTimestamp(c.saved[f]),c.observers[f].discardChanges(),h.get(i.name,f)}return b})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],64:[function(a,b){function c(a,b,c,g){var h=this,i=h.definitions[a];return new d.Promise(function(c,f){g=g||{},i?d.isObject(g)?("cacheResponse"in g||(g.cacheResponse=!0),"notify"in g||(g.notify=i.notify),c(b)):f(new e.IA('"options" must be an object!')):f(new e.NER(a))}).then(function(b){var c=g.beforeValidate?f(g.beforeValidate):i.beforeValidate;return c.call(b,a,b)}).then(function(b){var c=g.validate?f(g.validate):i.validate;return c.call(b,a,b)}).then(function(b){var c=g.afterValidate?f(g.afterValidate):i.afterValidate;return c.call(b,a,b)}).then(function(b){var c=g.beforeUpdate?f(g.beforeUpdate):i.beforeUpdate;return c.call(b,a,b)}).then(function(a){return g.notify&&h.emit(i,"beforeUpdate",d.merge({},a)),h.getAdapter(i,g).updateAll(i,a,c,g)}).then(function(b){var c=g.afterUpdate?f(g.afterUpdate):i.afterUpdate;return c.call(b,a,b)}).then(function(a){return g.notify&&h.emit(i,"afterUpdate",d.merge({},b)),g.cacheResponse?h.inject(i.name,a,g):a})}var d=a("../../utils"),e=a("../../errors"),f=d.promisify;b.exports=c},{"../../errors":76,"../../utils":78}],65:[function(a,b){function c(a,b,c){c(null,b)}function d(a,b){return b}function e(){}function f(a){this.store={},this.definitions={},this.adapters={},this.defaults=new e,g.deepMixIn(this.defaults,a)}var g=a("../utils"),h=a("../errors"),i=a("./sync_methods"),j=a("./async_methods");g.deepFreeze(i),g.deepFreeze(j),g.deepFreeze(h),g.deepFreeze(g);var k=e.prototype;k.idAttribute="id",k.defaultAdapter="DSHttpAdapter",k.defaultFilter=function(a,b,c,d){var e=this,f=a,h=null,i={skip:"",offset:"",where:"",limit:"",orderBy:"",sort:""};c=c||{},d=d||{},h=g.isObject(c.where)?c.where:{},d.allowSimpleWhere&&g.forOwn(c,function(a,b){b in i||b in h||(h[b]={"==":a})}),g.isEmpty(h)&&(h=null),h&&(f=g.filter(f,function(a){var b=!0,c=!0;return g.forOwn(h,function(d,e){g.isString(d)?d={"===":d}:(g.isNumber(d)||g.isBoolean(d))&&(d={"==":d}),g.isObject(d)&&g.forOwn(d,function(d,f){"=="===f?c=b?a[e]==d:c&&a[e]==d:"==="===f?c=b?a[e]===d:c&&a[e]===d:"!="===f?c=b?a[e]!=d:c&&a[e]!=d:"!=="===f?c=b?a[e]!==d:c&&a[e]!==d:">"===f?c=b?a[e]>d:c&&a[e]>d:">="===f?c=b?a[e]>=d:c&&a[e]>=d:"<"===f?c=b?a[e]<d:c&&a[e]<d:"<="===f?c=b?a[e]<=d:c&&a[e]<=d:"in"===f?c=b?g.contains(d,a[e]):c&&g.contains(d,a[e]):"notIn"===f?c=b?!g.contains(d,a[e]):c&&!g.contains(d,a[e]):"|=="===f?c=b?a[e]==d:c||a[e]==d:"|==="===f?c=b?a[e]===d:c||a[e]===d:"|!="===f?c=b?a[e]!=d:c||a[e]!=d:"|!=="===f?c=b?a[e]!==d:c||a[e]!==d:"|>"===f?c=b?a[e]>d:c||a[e]>d:"|>="===f?c=b?a[e]>=d:c||a[e]>=d:"|<"===f?c=b?a[e]<d:c||a[e]<d:"|<="===f?c=b?a[e]<=d:c||a[e]<=d:"|in"===f?c=b?g.contains(d,a[e]):c||g.contains(d,a[e]):"|notIn"===f&&(c=b?!g.contains(d,a[e]):c||!g.contains(d,a[e])),b=!1})}),c}));var j=null;g.isString(c.orderBy)?j=[[c.orderBy,"ASC"]]:g.isArray(c.orderBy)&&(j=c.orderBy),!j&&g.isString(c.sort)?j=[[c.sort,"ASC"]]:!j&&g.isArray(c.sort)&&(j=c.sort),j&&g.forEach(j,function(a){if(g.isString(a))a=[a,"ASC"];else if(!g.isArray(a))throw new e.errors.IllegalArgumentError("DS.filter(resourceName[, params][, options]): "+g.toJson(a)+": Must be a string or an array!",{params:{"orderBy[i]":{actual:typeof a,expected:"string|array"}}});f=g.sort(f,function(b,c){var d=b[a[0]],e=c[a[0]];return g.isString(d)&&(d=g.upperCase(d)),g.isString(e)&&(e=g.upperCase(e)),"DESC"===a[1]?d>e?-1:e>d?1:0:e>d?-1:d>e?1:0})});var k=g.isNumber(c.limit)?c.limit:null,l=null;return g.isNumber(c.skip)?l=c.skip:g.isNumber(c.offset)&&(l=c.offset),k&&l?f=g.slice(f,l,Math.min(f.length,l+k)):g.isNumber(k)?f=g.slice(f,0,Math.min(f.length,k)):g.isNumber(l)&&(f=l<f.length?g.slice(f,l):[]),f},k.basePath="",k.endpoint="",k.useClass=!0,k.keepChangeHistory=!1,k.resetHistoryOnInject=!0,k.eagerEject=!1,k.eagerInject=!1,k.notify=!0,k.beforeValidate=c,k.validate=c,k.afterValidate=c,k.beforeCreate=c,k.afterCreate=c,k.beforeUpdate=c,k.afterUpdate=c,k.beforeDestroy=c,k.afterDestroy=c,k.beforeInject=d,k.afterInject=d,k.beforeEject=d,k.afterEject=d;var l=f.prototype;l.getAdapter=function(a,b){return b=b||{},this.adapters[b.adapter]||this.adapters[a.defaultAdapter]},l.registerAdapter=function(a,b,c){c=c||{},this.adapters[a]=g.isFunction(b)?new b(c):b,c.default&&(this.defaults.defaultAdapter=a)},l.emit=function(a,b){var c=Array.prototype.slice.call(arguments,2);c.unshift(a.name),c.unshift("DS."+b),a.emit.apply(a,c)},l.errors=a("../errors"),l.utils=g,g.deepMixIn(l,i),g.deepMixIn(l,j),b.exports=f},{"../errors":76,"../utils":78,"./async_methods":60,"./sync_methods":70}],66:[function(require,module,exports){function Resource(a){DSUtils.deepMixIn(this,a),this.endpoint="endpoint"in a?a.endpoint:this.name}function defineResource(definition){var _this=this,definitions=_this.definitions;if(DSUtils.isString(definition)&&(definition={name:definition.replace(/\s/gi,"")}),!DSUtils.isObject(definition))throw new DSErrors.IA('"definition" must be an object!');if(!DSUtils.isString(definition.name))throw new DSErrors.IA('"name" must be a string!');if(_this.store[definition.name])throw new DSErrors.R(definition.name+" is already registered!");try{Resource.prototype=_this.defaults,definitions[definition.name]=new Resource(definition);var def=definitions[definition.name];if(!DSUtils.isString(def.idAttribute))throw new DSErrors.IA('"idAttribute" must be a string!');return def.relations&&(def.relationList=[],def.relationFields=[],DSUtils.forOwn(def.relations,function(a,b){DSUtils.forOwn(a,function(c,d){DSUtils.isArray(c)||(a[d]=[c]),DSUtils.forEach(a[d],function(a){a.type=b,a.relation=d,a.name=def.name,def.relationList.push(a),def.relationFields.push(a.localField)})})}),def.relations.belongsTo&&DSUtils.forOwn(def.relations.belongsTo,function(a,b){DSUtils.forEach(a,function(a){a.parent&&(def.parent=b,def.parentKey=a.localKey)})}),DSUtils.deepFreeze(def.relations),DSUtils.deepFreeze(def.relationList)),def.getEndpoint=function(a,b){var c,d,e=this.parent,f=this.parentKey,g=b.endpoint||this.endpoint,h=definitions[e];return delete b.endpoint,b=b||{},b.params=b.params||{},e&&f&&h&&b.params[f]!==!1&&((DSUtils.isNumber(a)||DSUtils.isString(a))&&(c=_this.get(this.name,a)),DSUtils.isObject(a)&&f in a?(delete b.params[f],d=DSUtils.makePath(h.getEndpoint(a,b),a[f],g)):c&&f in c?(delete b.params[f],d=DSUtils.makePath(h.getEndpoint(a,b),c[f],g)):b&&b.params[f]&&(d=DSUtils.makePath(h.getEndpoint(a,b),b.params[f],g),delete b.params[f])),b.params[f]===!1&&delete b.params[f],d||g},def.filter&&(def.defaultFilter=def.filter,delete def.filter),def.class=DSUtils.pascalCase(definition.name),eval("function "+def.class+"() {}"),def[def.class]=eval(def.class),def.methods&&DSUtils.deepMixIn(def[def.class].prototype,def.methods),def.computed&&(DSUtils.forOwn(def.computed,function(a,b){DSUtils.isFunction(a)&&(def.computed[b]=[a],a=def.computed[b]),def.methods&&b in def.methods&&console.warn('Computed property "'+b+'" conflicts with previously defined prototype method!');var c;if(1===a.length){var d=a[0].toString().match(/function.*?\(([\s\S]*?)\)/);c=d[1].split(","),def.computed[b]=c.concat(a),a=def.computed[b],c.length&&console.warn("Use the computed property array syntax for compatibility with minified code!")}c=a.slice(0,a.length-1),DSUtils.forEach(c,function(a,b){c[b]=a.trim()}),a.deps=DSUtils.filter(c,function(a){return!!a})}),def[def.class].prototype.DSCompute=function(){return _this.compute(def.name,this)}),def[def.class].prototype.DSUpdate=function(){var a=Array.prototype.slice.call(arguments);return a.unshift(this[def.idAttribute]),a.unshift(def.name),_this.update.apply(_this,a)},def[def.class].prototype.DSSave=function(){var a=Array.prototype.slice.call(arguments);return a.unshift(this[def.idAttribute]),a.unshift(def.name),_this.save.apply(_this,a)},_this.store[def.name]={collection:[],completedQueries:{},pendingQueries:{},index:{},modified:{},saved:{},previousAttributes:{},observers:{},changeHistories:{},changeHistory:[],collectionModified:0},DSUtils.forEach(methodsToProxy,function(a){def[a]=function(){var b=Array.prototype.slice.call(arguments);return b.unshift(def.name),_this[a].apply(_this,b)}}),def.beforeValidate=DSUtils.promisify(def.beforeValidate),def.validate=DSUtils.promisify(def.validate),def.afterValidate=DSUtils.promisify(def.afterValidate),def.beforeCreate=DSUtils.promisify(def.beforeCreate),def.afterCreate=DSUtils.promisify(def.afterCreate),def.beforeUpdate=DSUtils.promisify(def.beforeUpdate),def.afterUpdate=DSUtils.promisify(def.afterUpdate),def.beforeDestroy=DSUtils.promisify(def.beforeDestroy),def.afterDestroy=DSUtils.promisify(def.afterDestroy),DSUtils.Events(def),def}catch(err){throw console.error(err),delete definitions[definition.name],delete _this.store[definition.name],err}}var DSUtils=require("../../utils"),DSErrors=require("../../errors"),methodsToProxy=["changes","changeHistory","create","createInstance","destroy","destroyAll","eject","ejectAll","filter","find","findAll","get","hasChanges","inject","lastModified","lastSaved","link","linkAll","linkInverse","loadRelations","previous","refresh","save","unlinkInverse","update","updateAll"];module.exports=defineResource},{"../../errors":76,"../../utils":78}],67:[function(a,b){function c(a,b,c){var f,g=this,h=g.definitions[a],i=g.store[a],j=!1;if(c=c||{},b=d.resolveId(h,b),!h)throw new e.NER(a);if(!d.isString(b)&&!d.isNumber(b))throw new e.IA('"id" must be a string or a number!');if(!d.isObject(c))throw new e.IA('"options" must be an object!');for(var k=0;k<i.collection.length;k++)if(i.collection[k][h.idAttribute]==b){f=i.collection[k],j=!0;break}return j?("notify"in c||(c.notify=h.notify),c.notify&&h.beforeEject(h.name,f),g.unlinkInverse(h.name,b),i.collection.splice(k,1),i.observers[b].close(),delete i.observers[b],delete i.index[b],delete i.previousAttributes[b],delete i.completedQueries[b],delete i.pendingQueries[b],d.forEach(i.changeHistories[b],function(a){d.remove(i.changeHistory,a)}),delete i.changeHistories[b],delete i.modified[b],delete i.saved[b],i.collectionModified=d.updateTimestamp(i.collectionModified),c.notify&&(h.afterEject(h.name,f),g.emit(h,"eject",f)),f):void 0}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],68:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(b=b||{},!g)throw new e.NER(a);if(!d.isObject(b))throw new e.IA('"params" must be an object!');var h=f.store[a];d.isEmpty(b)&&(h.completedQueries={});var i=d.toJson(b),j=f.filter(g.name,b),k=d.toLookup(j,g.idAttribute);return d.forOwn(k,function(a,b){f.eject(g.name,b,c)}),delete h.completedQueries[i],h.collectionModified=d.updateTimestamp(h.collectionModified),j}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],69:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||{},!g)throw new e.NER(a);if(b&&!d.isObject(b))throw new e.IA('"params" must be an object!');if(!d.isObject(c))throw new e.IA('"options" must be an object!');var h=f.store[a];b=b||{},"allowSimpleWhere"in c||(c.allowSimpleWhere=!0);var i=d.toJson(b);return i in h.completedQueries||!c.loadFromServer||h.pendingQueries[i]||f.findAll(a,b,c),g.defaultFilter.call(f,h.collection,a,b,c)}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],70:[function(a,b){function c(a,b){var c=this,d=c.definitions[a];if(b=o.resolveId(d,b),!d)throw new p.NER(a);if(!o.isString(b)&&!o.isNumber(b))throw new p.IA('"id" must be a string or a number!');var e=c.get(a,b);if(e){c.store[a].observers[b].deliver();var f=o.diffObjectFromOldObject(e,c.store[a].previousAttributes[b]);return o.forOwn(f,function(a,b){var c=[];o.forOwn(a,function(a,b){o.isFunction(a)||c.push(b)}),f[b]=o.pick(f[b],c)}),o.forEach(d.relationFields,function(a){delete f.added[a],delete f.removed[a],delete f.changed[a]}),f}}function d(a,b){var c=this,d=c.definitions[a],e=c.store[a];if(b=o.resolveId(d,b),a&&!c.definitions[a])throw new p.NER(a);if(b&&!o.isString(b)&&!o.isNumber(b))throw new p.IA('"id" must be a string or a number!');if(d.keepChangeHistory){if(!a)return e.changeHistory;var f=c.get(a,b);if(f)return e.changeHistories[b]}else console.warn("changeHistory is disabled for this resource!")}function e(a,b,c){var d=this.definitions[a];if(b=b||{},c=c||{},!d)throw new p.NER(a);if(b&&!o.isObject(b))throw new p.IA('"attrs" must be an object!');if(!o.isObject(c))throw new p.IA('"options" must be an object!');"useClass"in c||(c.useClass=d.useClass);var e;if(c.useClass){var f=d[d.class];e=new f}else e={};return o.deepMixIn(e,b)}function f(a){return!(o.isEmpty(a.added)&&o.isEmpty(a.removed)&&o.isEmpty(a.changed))}function g(){n.Platform.performMicrotaskCheckpoint()}function h(a,b){var c=this,d=c.definitions[a];if(b=o.resolveItem(c.store[a],b),!d)throw new p.NER(a);if(!o.isObject(b)&&!o.isString(b)&&!o.isNumber(b))throw new p.IA('"instance" must be an object, string or number!');return(o.isString(b)||o.isNumber(b))&&(b=c.get(a,b)),o.forOwn(d.computed,function(a,c){o.compute.call(b,a,c,o)}),b}function i(a,b,c){var d=this;if(c=c||{},!d.definitions[a])throw new p.NER(a);if(!o.isString(b)&&!o.isNumber(b))throw new p.IA('"id" must be a string or a number!');if(!o.isObject(c))throw new p.IA('"options" must be an object!');var e=d.store[a].index[b];return!e&&c.loadFromServer&&d.find(a,b,c),e}function j(a,b){var c=this;if(b=o.resolveId(c.definitions[a],b),!c.definitions[a])throw new p.NER(a);return c.get(a,b)?f(c.changes(a,b)):!1}function k(a,b){var c=this.definitions[a],d=this.store[a];if(b=o.resolveId(c,b),!c)throw new p.NER(a);return b?(b in d.modified||(d.modified[b]=0),d.modified[b]):d.collectionModified}function l(a,b){var c=this.definitions[a],d=this.store[a];if(b=o.resolveId(c,b),!c)throw new p.NER(a);return b in d.saved||(d.saved[b]=0),d.saved[b]}function m(a,b){var c=this,d=c.definitions[a],e=c.store[a];if(b=o.resolveId(d,b),!d)throw new p.NER(a);if(!o.isString(b)&&!o.isNumber(b))throw new p.IA('"id" must be a string or a number!');return e.previousAttributes[b]?o.merge({},e.previousAttributes[b]):void 0}var n=a("../../../lib/observe-js/observe-js"),o=a("../../utils"),p=a("../../errors");b.exports={changes:c,changeHistory:d,compute:h,createInstance:e,defineResource:a("./defineResource"),digest:g,eject:a("./eject"),ejectAll:a("./ejectAll"),filter:a("./filter"),get:i,hasChanges:j,inject:a("./inject"),lastModified:k,lastSaved:l,link:a("./link"),linkAll:a("./linkAll"),linkInverse:a("./linkInverse"),previous:m,unlinkInverse:a("./unlinkInverse")}},{"../../../lib/observe-js/observe-js":1,"../../errors":76,"../../utils":78,"./defineResource":66,"./eject":67,"./ejectAll":68,"./filter":69,"./inject":71,"./link":72,"./linkAll":73,"./linkInverse":74,"./unlinkInverse":75}],71:[function(a,b){function c(a,b,c){var d=this;h.forEach(a.relationList,function(e){var f=e.relation,g=d.definitions[f];if(g&&b[e.localField])try{b[e.localField]=d.inject(f,b[e.localField],c)}catch(h){console.error(a.name+": Failed to inject "+e.type+' relation: "'+f+'"!',h)}})}function d(a,b,c){return function(d,e,f,g,i){var j,k=this,l=g&&g(b.idAttribute)?g(b.idAttribute):k[b.idAttribute];if(h.forEach(b.relationFields,function(a){delete d[a],delete e[a],delete f[a]}),(!h.isEmpty(d)||!h.isEmpty(e)||!h.isEmpty(f)||i)&&(j=a.get(b.name,l),c.modified[l]=h.updateTimestamp(c.modified[l]),c.collectionModified=h.updateTimestamp(c.collectionModified),b.keepChangeHistory)){var m={resourceName:b.name,target:j,added:d,removed:e,changed:f,timestamp:c.modified[l]};c.changeHistories[l].push(m),c.changeHistory.push(m)}b.computed&&(j=j||a.get(b.name,l),h.forOwn(b.computed,function(a,b){var c=!1;h.forEach(a.deps,function(a){(a in d||a in e||a in f||!(b in j))&&(c=!0)}),c=c||!a.deps.length,c&&h.compute.call(j,a,b,h)})),b.relations&&(j=j||a.get(b.name,l),h.forEach(b.relationList,function(c){j[c.localField]&&(c.localKey in d||c.localKey in e||c.localKey in f)&&a.link(b.name,j[b.idAttribute],[c.relation])})),b.idAttribute in f&&console.error("Doh! You just changed the primary key of an object! I don't know how to handle this yet, so your data for the \""+b.name+'" resource is now in an undefined (probably broken) state.')}}function e(a,b,f,g){var k,l=this,m=d(l,a,b,f,g);if(h.isArray(f)){k=[];for(var n=0;n<f.length;n++)k.push(e.call(l,a,b,f[n],g))}else{var o=a.computed,p=a.idAttribute;if(o&&o[p]){var q=[];h.forEach(o[p].deps,function(a){q.push(f[a])}),f[p]=o[p][o[p].length-1].apply(f,q)}if(!(p in f)){var r=new i.R(a.name+'.inject: "attrs" must contain the property specified by `idAttribute`!');throw console.error(r),r}try{var s=f[p],t=l.get(a.name,s);t?(h.deepMixIn(t,f),a.resetHistoryOnInject&&(b.previousAttributes[s]={},h.deepMixIn(b.previousAttributes[s],f),b.changeHistories[s].length&&(h.forEach(b.changeHistories[s],function(a){h.remove(b.changeHistory,a)}),b.changeHistories[s].splice(0,b.changeHistories[s].length))),b.observers[s].deliver()):(t=g.useClass?f instanceof a[a.class]?f:new a[a.class]:{},b.previousAttributes[s]={},h.deepMixIn(t,f),h.deepMixIn(b.previousAttributes[s],f),b.collection.push(t),b.changeHistories[s]=[],b.observers[s]=new j.ObjectObserver(t),b.observers[s].open(m,t),b.index[s]=t,m.call(t,{},{},{},null,!0),a.relations&&c.call(l,a,t,g)),b.saved[s]=h.updateTimestamp(b.saved[s]),k=t}catch(u){console.error(u),console.error("inject failed!",a.name,f)}}return k}function f(a,b,c){var d=this;h.forEach(a.relationList,function(e){c.findBelongsTo&&"belongsTo"===e.type&&b[a.idAttribute]?d.link(a.name,b[a.idAttribute],[e.relation]):(c.findHasMany&&"hasMany"===e.type||c.findHasOne&&"hasOne"===e.type)&&d.link(a.name,b[a.idAttribute],[e.relation])})}function g(a,b,c){var d=this,g=d.definitions[a];if(c=c||{},!g)throw new i.NER(a);if(!h.isObject(b)&&!h.isArray(b))throw new i.IA(a+'.inject: "attrs" must be an object or an array!');if(!h.isObject(c))throw new i.IA('"options" must be an object!');var j;return"useClass"in c||(c.useClass=g.useClass),"notify"in c||(c.notify=g.notify),c.notify&&g.beforeInject(g.name,b),j=e.call(d,g,d.store[a],b,c),c.linkInverse&&(h.isArray(j)&&j.length?d.linkInverse(g.name,j[0][g.idAttribute]):d.linkInverse(g.name,j[g.idAttribute])),h.isArray(j)?h.forEach(j,function(a){f.call(d,g,a,c)}):f.call(d,g,j,c),c.notify&&(g.afterInject(g.name,j),d.emit(g,"inject",j)),j}var h=a("../../utils"),i=a("../../errors"),j=a("../../../lib/observe-js/observe-js");b.exports=g},{"../../../lib/observe-js/observe-js":1,"../../errors":76,"../../utils":78}],72:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||[],b=d.resolveId(g,b),!g)throw new e.NER(a);if(!d.isString(b)&&!d.isNumber(b))throw new e.IA('"id" must be a string or a number!');if(!d.isArray(c))throw new e.IA('"relations" must be an array!');var h=f.get(a,b);return h&&d.forEach(g.relationList,function(a){var b=a.relation;if(!c.length||d.contains(c,b)){var e={};if("belongsTo"===a.type){var i=h[a.localKey]?f.get(b,h[a.localKey]):null;i&&(h[a.localField]=i)}else if("hasMany"===a.type)e[a.foreignKey]=h[g.idAttribute],h[a.localField]=f.defaults.constructor.prototype.defaultFilter.call(f,f.store[b].collection,b,e,{allowSimpleWhere:!0});else if("hasOne"===a.type){e[a.foreignKey]=h[g.idAttribute];var j=f.defaults.constructor.prototype.defaultFilter.call(f,f.store[b].collection,b,e,{allowSimpleWhere:!0});j.length&&(h[a.localField]=j[0])}}}),h}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],73:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||[],!g)throw new e.NER(a);if(!d.isArray(c))throw new e.IA('"relations" must be an array!');var h=f.filter(a,b);return h&&d.forEach(g.relationList,function(a){var b=a.relation;(!c.length||d.contains(c,b))&&("belongsTo"===a.type?d.forEach(h,function(c){var d=c[a.localKey]?f.get(b,c[a.localKey]):null;d&&(c[a.localField]=d)}):"hasMany"===a.type?d.forEach(h,function(c){var d={};d[a.foreignKey]=c[g.idAttribute],c[a.localField]=f.defaults.constructor.prototype.defaultFilter.call(f,f.store[b].collection,b,d,{allowSimpleWhere:!0})}):"hasOne"===a.type&&d.forEach(h,function(c){var d={};d[a.foreignKey]=c[g.idAttribute];var e=f.defaults.constructor.prototype.defaultFilter.call(f,f.store[b].collection,b,d,{allowSimpleWhere:!0});e.length&&(c[a.localField]=e[0])}))}),h}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],74:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||[],b=d.resolveId(g,b),!g)throw new e.NER(a);if(!d.isString(b)&&!d.isNumber(b))throw new e.IA('"id" must be a string or a number!');if(!d.isArray(c))throw new e.IA('"relations" must be an array!');var h=f.get(a,b);return h&&d.forOwn(f.definitions,function(a){d.forOwn(a.relations,function(b){d.forOwn(b,function(b,e){(!c.length||d.contains(c,a.name))&&g.name===e&&f.linkAll(a.name,{},[g.name])})})}),h}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],75:[function(a,b){function c(a,b,c){var f=this,g=f.definitions[a];if(c=c||[],b=d.resolveId(g,b),!g)throw new e.NER(a);if(!d.isString(b)&&!d.isNumber(b))throw new e.IA('"id" must be a string or a number!');if(!d.isArray(c))throw new e.IA('"relations" must be an array!');var h=f.get(a,b);return h&&d.forOwn(f.definitions,function(a){d.forOwn(a.relations,function(a){d.forOwn(a,function(a,b){g.name===b&&d.forEach(a,function(a){d.forEach(f.store[a.name].collection,function(b){if("hasMany"===a.type&&b[a.localField]){var c;d.forEach(b[a.localField],function(a,b){a===h&&(c=b)}),b[a.localField].splice(c,1)}else b[a.localField]===h&&delete b[a.localField]})})})})}),h}var d=a("../../utils"),e=a("../../errors");b.exports=c},{"../../errors":76,"../../utils":78}],76:[function(a,b){function c(a){Error.call(this),"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.type=this.constructor.name,this.message=a||"Illegal Argument!"}function d(a){Error.call(this),"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.type=this.constructor.name,this.message=a||"RuntimeError Error!"}function e(a){Error.call(this),"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.type=this.constructor.name,this.message=(a||"")+" is not a registered resource!"}c.prototype=Object.create(Error.prototype),c.prototype.constructor=c,d.prototype=Object.create(Error.prototype),d.prototype.constructor=d,e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,b.exports={IllegalArgumentError:c,IA:c,RuntimeError:d,R:d,NonexistentResourceError:e,NER:e}},{}],77:[function(a,b){var c=a("./datastore");b.exports={DS:c,createStore:function(){return new c},DSUtils:a("./utils"),DSErrors:a("./errors")}},{"./datastore":65,"./errors":76,"./utils":78}],78:[function(a,b){function c(a){var b={};a=a||this,a.on=function(a,c,d){b[a]=b[a]||[],b[a].push({f:c,c:d})},a.off=function(a,c){var d=b[a];if(d)if(c){for(var e=0;e<d.length;e++)if(d[e]===c){d.splice(e,1);break}}else d.splice(0,d.length);else b={}},a.emit=function(){var a=Array.prototype.slice.call(arguments),c=b[a.shift()]||[];if(c)for(var d=0;d<c.length;d++)c[d].f.apply(c[d].c,a)}}b.exports={isBoolean:a("mout/lang/isBoolean"),isString:a("mout/lang/isString"),isArray:a("mout/lang/isArray"),isObject:a("mout/lang/isObject"),isNumber:a("mout/lang/isNumber"),isFunction:a("mout/lang/isFunction"),isEmpty:a("mout/lang/isEmpty"),toJson:JSON.stringify,fromJson:JSON.parse,makePath:a("mout/string/makePath"),upperCase:a("mout/string/upperCase"),pascalCase:a("mout/string/pascalCase"),deepMixIn:a("mout/object/deepMixIn"),forOwn:a("mout/object/forOwn"),forEach:a("mout/array/forEach"),pick:a("mout/object/pick"),set:a("mout/object/set"),merge:a("mout/object/merge"),contains:a("mout/array/contains"),filter:a("mout/array/filter"),toLookup:a("mout/array/toLookup"),remove:a("mout/array/remove"),slice:a("mout/array/slice"),sort:a("mout/array/sort"),resolveItem:function(a,b){return a&&(this.isString(b)||this.isNumber(b))?a.index[b]||b:b},resolveId:function(a,b){return this.isString(b)||this.isNumber(b)?b:b&&a?b[a.idAttribute]||b:b},updateTimestamp:function(a){var b="function"==typeof Date.now?Date.now():(new Date).getTime();return a&&a>=b?a+1:b},Promise:a("es6-promise").Promise,deepFreeze:function d(a){if("function"==typeof Object.freeze){var b,c;Object.freeze(a);for(c in a)b=a[c],a.hasOwnProperty(c)&&"object"==typeof b&&!Object.isFrozen(b)&&d(b)}},compute:function(a,b,c){var d=this,e=[];c.forEach(a.deps,function(a){e.push(d[a])}),this[b]=a[a.length-1].apply(this,e)},diffObjectFromOldObject:function(a,b){var c={},d={},e={};for(var f in b){var g=a[f];(void 0===g||g!==b[f])&&(f in a?g!==b[f]&&(e[f]=g):d[f]=void 0)}for(var h in a)h in b||(c[h]=a[h]);return{added:c,removed:d,changed:e}},promisify:function(a,b){var c=this.Promise;if(a){if("function"!=typeof a)throw new Error("Can only promisify functions!");return function(){var d=Array.prototype.slice.apply(arguments);return new c(function(c,e){d.push(function(a,b){a?e(a):c(b)});try{var f=a.apply(b||this,d);f&&f.then&&f.then(c,e)}catch(g){e(g)}})}}},Events:c}},{"es6-promise":2,"mout/array/contains":13,"mout/array/filter":14,"mout/array/forEach":15,"mout/array/remove":18,"mout/array/slice":19,"mout/array/sort":20,"mout/array/toLookup":21,"mout/lang/isArray":27,"mout/lang/isBoolean":28,"mout/lang/isEmpty":29,"mout/lang/isFunction":30,"mout/lang/isNumber":32,"mout/lang/isObject":33,"mout/lang/isString":35,"mout/object/deepMixIn":39,"mout/object/forOwn":41,"mout/object/merge":43,"mout/object/pick":46,"mout/object/set":47,"mout/string/makePath":50,"mout/string/pascalCase":51,"mout/string/upperCase":54}]},{},[77])(77)}); |
@@ -98,3 +98,3 @@ // Setup global test variables | ||
datastore = new JSData.DS({ | ||
baseUrl: 'http://test.js-data.io', | ||
basePath: 'http://test.js-data.io', | ||
beforeValidate: lifecycle.beforeValidate, | ||
@@ -115,3 +115,4 @@ validate: lifecycle.validate, | ||
serialize: lifecycle.serialize, | ||
deserialize: lifecycle.deserialize | ||
deserialize: lifecycle.deserialize, | ||
log: function () {} | ||
}); | ||
@@ -118,0 +119,0 @@ dsLocalStorageAdapter = new DSLocalStorageAdapter(); |
{ | ||
"name": "js-data", | ||
"description": "Data store.", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"homepage": "http://www.js-data.io", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -5,30 +5,21 @@ <img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="64" height="64" /> | ||
Inspired by [Ember Data](https://github.com/emberjs/data), JSData is the model layer you've been craving. It consists of a convenient framework-agnostic in-memory cache for managing your data, which uses adapters for communicating with various persistence layers. | ||
Inspired by [Ember Data](https://github.com/emberjs/data), js-data is the model layer you've been craving. It consists of a convenient framework-agnostic, in-memory cache for managing your data, which users adapters to communicate with various persistence layers. | ||
You can use the [http adapter](http://www.js-data.io/js-data-http), which is perfect for communicating with your RESTful backend. You could also use the [localStorage adapter](http://www.js-data.io/js-data-localstorage). More adapters are coming, and you're free to implement your own. | ||
Unlike Backbone and Ember Models, JSData does not require the use of getters and setters, and doesn't wrap your data with custom classes if you don't want it to. JSData's internal dirty-checking (via [observe-js](https://github.com/Polymer/observe-js) or `Object.observe` in supporting browsers) allows for powerful use cases and an easy avenue for implementing your own [3-way data-binding](https://www.firebase.com/blog/2013-10-04-firebase-angular-data-binding.html). | ||
Unlike Backbone and Ember Models, js-data does not require the use of getters and setters, and doesn't wrap your data with custom classes if you don't want it to. js-data's internal dirty-checking (via [observe-js](https://github.com/Polymer/observe-js) or `Object.observe` in supporting browsers) allows for powerful use cases and an easy avenue for implementing your own [3-way data-binding](https://www.firebase.com/blog/2013-10-04-firebase-angular-data-binding.html). | ||
Supporting relations, computed properties, model lifecycle control and a slew of other features, JSData is the tool for giving your data the respect it deserves. | ||
Supporting relations, computed properties, model lifecycle control and a slew of other features, js-data is the tool for giving your data the respect it deserves. | ||
__Latest Release:__ [0.3.1](https://github.com/js-data/js-data/releases/tag/0.3.1) | ||
__Latest Release:__ [0.4.0](https://github.com/js-data/js-data/releases/tag/0.4.0) | ||
JSData is pre-alpha. The API is subject to change, though the current api is well tested. | ||
js-data is pre-alpha. The API is subject to change, though the current api is well tested. | ||
If you want to use JSData, keep a close eye on the changelog. 1.0.0 will introduce strict semver (until then, minor number is bumped for breaking changes). | ||
If you want to use js-data, keep a close eye on the changelog. 1.0.0 will introduce strict semver (until then, minor number is bumped for breaking changes). | ||
## Project Status | ||
| Branch | Master | | ||
| ------ | ------ | | ||
| Bower | [![Bower version](https://badge.fury.io/bo/js-data.png)](http://badge.fury.io/bo/js-data) | | ||
| NPM | [![NPM version](https://badge.fury.io/js/js-data.png)](http://badge.fury.io/js/js-data) | | ||
| Build Status | [![Build Status](https://travis-ci.org/js-data/js-data.png?branch=master)](https://travis-ci.org/js-data/js-data) | | ||
| Code Climate | [![Code Climate](https://codeclimate.com/github/js-data/js-data.png)](https://codeclimate.com/github/js-data/js-data) | | ||
| Dependency Status | [![Dependency Status](https://gemnasium.com/js-data/js-data.png)](https://gemnasium.com/js-data/js-data) | | ||
| Coverage | [![Coverage Status](https://coveralls.io/repos/js-data/js-data/badge.png?branch=master)](https://coveralls.io/r/js-data/js-data?branch=master) | | ||
## Quick Start | ||
`bower install --save js-data js-data-http` or `npm install --save js-data js-data-http`. | ||
Load `js-data-http.js` after `js-data.js`. | ||
```js | ||
@@ -39,2 +30,6 @@ var dataStore = new JSData.DS(); | ||
// use http by default for async operations | ||
dataStore.defaults.defaultAdapter = 'DSHttpAdapter'; | ||
// simplest model definition | ||
var User = dataStore.defineResource('user'); | ||
@@ -50,8 +45,7 @@ | ||
## API | ||
- [Overview](http://www.js-data.io) | ||
- [DS](https://github.com/js-data/js-data/wiki/DS) | ||
- [DSHttpAdapter](https://github.com/js-data/js-data/wiki/DSHttpAdapter) | ||
- [DSLocalStorageAdapter](https://github.com/js-data/js-data/wiki/DSLocalStorageAdapter) | ||
- [DSFirebaseAdapter](https://github.com/js-data/js-data/wiki/DSLocalStorageAdapter) | ||
- [Schemator](https://github.com/js-data/js-data/wiki/Schemator) | ||
- [DS](DS) | ||
- [DSHttpAdapter](DSHttpAdapter) | ||
- [DSLocalStorageAdapter](DSLocalStorageAdapter) | ||
- [DSFirebaseAdapter](DSFirebaseAdapter) | ||
- [Schemator](Schemator) | ||
@@ -65,3 +59,3 @@ ## Changelog | ||
## Community | ||
- [Mailing List](https://groups.google.com/forum/?fromgroups#!forum/js-data-project) - Ask your questions! | ||
- [Mailing List](https://groups.io/org/groupsio/jsdata) - Ask your questions! | ||
- [Issues](https://github.com/js-data/js-data/issues) - Found a bug? Feature request? Submit an issue! | ||
@@ -73,3 +67,3 @@ - [GitHub](https://github.com/js-data/js-data) - View the source code for js-data. | ||
First, feel free to contact me with questions. [Mailing List](https://groups.google.com/forum/?fromgroups#!forum/js-data-project). [Issues](https://github.com/js-data/js-data/issues). | ||
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data/issues). | ||
@@ -76,0 +70,0 @@ 1. Contribute to the issue that is the reason you'll be developing in the first place |
@@ -22,2 +22,5 @@ var DSUtils = require('../../utils'); | ||
} | ||
if (!('notify' in options)) { | ||
options.notify = definition.notify; | ||
} | ||
resolve(attrs); | ||
@@ -48,3 +51,5 @@ } | ||
.then(function (attrs) { | ||
_this.notify(definition, 'beforeCreate', DSUtils.merge({}, attrs)); | ||
if (options.notify) { | ||
_this.emit(definition, 'beforeCreate', DSUtils.merge({}, attrs)); | ||
} | ||
return _this.getAdapter(definition, options).create(definition, attrs, options); | ||
@@ -57,3 +62,5 @@ }) | ||
.then(function (attrs) { | ||
_this.notify(definition, 'afterCreate', DSUtils.merge({}, attrs)); | ||
if (options.notify) { | ||
_this.emit(definition, 'afterCreate', DSUtils.merge({}, attrs)); | ||
} | ||
if (options.cacheResponse) { | ||
@@ -60,0 +67,0 @@ var resource = _this.store[resourceName]; |
@@ -20,7 +20,12 @@ var DSUtils = require('../../utils'); | ||
reject(new DSErrors.R('id "' + id + '" not found in cache!')); | ||
} else if (!DSUtils.isObject(options)) { | ||
reject(new DSErrors.IA('"options" must be an object!')); | ||
} else { | ||
item = _this.get(resourceName, id); | ||
if (!('notify' in options)) { | ||
options.notify = true; | ||
options.notify = definition.notify; | ||
} | ||
if (!('eagerEject' in options)) { | ||
options.eagerEject = definition.eagerEject; | ||
} | ||
resolve(item); | ||
@@ -30,12 +35,8 @@ } | ||
.then(function (attrs) { | ||
if (options.notify) { | ||
var func = options.beforeDestroy ? promisify(options.beforeDestroy) : definition.beforeDestroy; | ||
return func.call(attrs, resourceName, attrs); | ||
} else { | ||
return attrs; | ||
} | ||
var func = options.beforeDestroy ? promisify(options.beforeDestroy) : definition.beforeDestroy; | ||
return func.call(attrs, resourceName, attrs); | ||
}) | ||
.then(function (attrs) { | ||
if (options.notify) { | ||
_this.notify(definition, 'beforeDestroy', DSUtils.merge({}, attrs)); | ||
_this.emit(definition, 'beforeDestroy', DSUtils.merge({}, attrs)); | ||
} | ||
@@ -48,12 +49,8 @@ if (options.eagerEject) { | ||
.then(function () { | ||
if (options.notify) { | ||
var func = options.afterDestroy ? promisify(options.afterDestroy) : definition.afterDestroy; | ||
return func.call(item, resourceName, item); | ||
} else { | ||
return item; | ||
} | ||
var func = options.afterDestroy ? promisify(options.afterDestroy) : definition.afterDestroy; | ||
return func.call(item, resourceName, item); | ||
}) | ||
.then(function (item) { | ||
if (options.notify) { | ||
_this.notify(definition, 'afterDestroy', DSUtils.merge({}, item)); | ||
_this.emit(definition, 'afterDestroy', DSUtils.merge({}, item)); | ||
} | ||
@@ -60,0 +57,0 @@ _this.eject(resourceName, id); |
@@ -10,10 +10,19 @@ var DSUtils = require('../../utils'); | ||
return new DSUtils.Promise(function (resolve, reject) { | ||
options = options || {}; | ||
if (!definition) { | ||
reject(new DSErrors.NER(resourceName)); | ||
} else if (!DSUtils.isObject(options)) { | ||
reject(new DSErrors.IA('"options" must be an object!')); | ||
} else { | ||
options = options || {}; | ||
if (!('notify' in options)) { | ||
options.notify = definition.notify; | ||
} | ||
if (!('eagerEject' in options)) { | ||
options.eagerEject = definition.eagerEject; | ||
} | ||
resolve(); | ||
} | ||
}).then(function () { | ||
var func = options.beforeDestroy ? promisify(options.beforeDestroy) : definition.beforeDestroy; | ||
var func = options.beforeDestroy ? DSUtils.promisify(options.beforeDestroy) : definition.beforeDestroy; | ||
toEject = _this.defaults.defaultFilter.call(_this, resourceName, params); | ||
@@ -23,3 +32,3 @@ return func(resourceName, toEject); | ||
if (options.notify) { | ||
_this.notify(definition, 'beforeDestroy', toEject); | ||
_this.emit(definition, 'beforeDestroy', toEject); | ||
} | ||
@@ -31,7 +40,7 @@ if (options.eagerEject) { | ||
}).then(function () { | ||
var func = options.afterDestroy ? promisify(options.afterDestroy) : definition.afterDestroy; | ||
var func = options.afterDestroy ? DSUtils.promisify(options.afterDestroy) : definition.afterDestroy; | ||
return func(resourceName, toEject); | ||
}).then(function () { | ||
if (options.notify) { | ||
_this.notify(definition, 'afterDestroy', toEject); | ||
_this.emit(definition, 'afterDestroy', toEject); | ||
} | ||
@@ -38,0 +47,0 @@ return ejected || _this.ejectAll(resourceName, params); |
@@ -27,2 +27,5 @@ var DSUtils = require('../../utils'); | ||
} | ||
if (!('notify' in options)) { | ||
options.notify = definition.notify; | ||
} | ||
resolve(item); | ||
@@ -47,3 +50,5 @@ } | ||
.then(function (attrs) { | ||
_this.notify(definition, 'beforeUpdate', DSUtils.merge({}, attrs)); | ||
if (options.notify) { | ||
_this.emit(definition, 'beforeUpdate', DSUtils.merge({}, attrs)); | ||
} | ||
if (options.changesOnly) { | ||
@@ -76,3 +81,5 @@ var resource = _this.store[resourceName]; | ||
.then(function (attrs) { | ||
_this.notify(definition, 'afterUpdate', DSUtils.merge({}, attrs)); | ||
if (options.notify) { | ||
_this.emit(definition, 'afterUpdate', DSUtils.merge({}, attrs)); | ||
} | ||
if (options.cacheResponse) { | ||
@@ -79,0 +86,0 @@ var resource = _this.store[resourceName]; |
@@ -23,2 +23,5 @@ var DSUtils = require('../../utils'); | ||
} | ||
if (!('notify' in options)) { | ||
options.notify = definition.notify; | ||
} | ||
resolve(attrs); | ||
@@ -43,3 +46,5 @@ } | ||
.then(function (attrs) { | ||
_this.notify(definition, 'beforeUpdate', DSUtils.merge({}, attrs)); | ||
if (options.notify) { | ||
_this.emit(definition, 'beforeUpdate', DSUtils.merge({}, attrs)); | ||
} | ||
return _this.getAdapter(definition, options).update(definition, id, attrs, options); | ||
@@ -52,3 +57,5 @@ }) | ||
.then(function (attrs) { | ||
_this.notify(definition, 'afterUpdate', DSUtils.merge({}, attrs)); | ||
if (options.notify) { | ||
_this.emit(definition, 'afterUpdate', DSUtils.merge({}, attrs)); | ||
} | ||
if (options.cacheResponse) { | ||
@@ -55,0 +62,0 @@ var resource = _this.store[resourceName]; |
@@ -20,2 +20,5 @@ var DSUtils = require('../../utils'); | ||
} | ||
if (!('notify' in options)) { | ||
options.notify = definition.notify; | ||
} | ||
resolve(attrs); | ||
@@ -40,3 +43,5 @@ } | ||
.then(function (attrs) { | ||
_this.notify(definition, 'beforeUpdate', DSUtils.merge({}, attrs)); | ||
if (options.notify) { | ||
_this.emit(definition, 'beforeUpdate', DSUtils.merge({}, attrs)); | ||
} | ||
return _this.getAdapter(definition, options).updateAll(definition, attrs, params, options); | ||
@@ -49,3 +54,5 @@ }) | ||
.then(function (data) { | ||
_this.notify(definition, 'afterUpdate', DSUtils.merge({}, attrs)); | ||
if (options.notify) { | ||
_this.emit(definition, 'afterUpdate', DSUtils.merge({}, attrs)); | ||
} | ||
if (options.cacheResponse) { | ||
@@ -52,0 +59,0 @@ return _this.inject(definition.name, data, options); |
@@ -206,3 +206,3 @@ var DSUtils = require('../utils'); | ||
}; | ||
defaultsPrototype.baseUrl = ''; | ||
defaultsPrototype.basePath = ''; | ||
defaultsPrototype.endpoint = ''; | ||
@@ -212,2 +212,6 @@ defaultsPrototype.useClass = true; | ||
defaultsPrototype.resetHistoryOnInject = true; | ||
defaultsPrototype.eagerEject = false; | ||
// TODO: Implement eagerInject in DS#create | ||
defaultsPrototype.eagerInject = false; | ||
defaultsPrototype.notify = true; | ||
defaultsPrototype.beforeValidate = lifecycleNoopCb; | ||
@@ -242,3 +246,15 @@ defaultsPrototype.validate = lifecycleNoopCb; | ||
dsPrototype.notify = function (definition, event) { | ||
dsPrototype.registerAdapter = function (name, Adapter, options) { | ||
options = options || {}; | ||
if (DSUtils.isFunction(Adapter)) { | ||
this.adapters[name] = new Adapter(options); | ||
} else { | ||
this.adapters[name] = Adapter; | ||
} | ||
if (options.default) { | ||
this.defaults.defaultAdapter = name; | ||
} | ||
}; | ||
dsPrototype.emit = function (definition, event) { | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
@@ -245,0 +261,0 @@ args.unshift(definition.name); |
@@ -187,2 +187,16 @@ /*jshint evil:true*/ | ||
def[def.class].prototype.DSUpdate = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
args.unshift(this[def.idAttribute]); | ||
args.unshift(def.name); | ||
return _this.update.apply(_this, args); | ||
}; | ||
def[def.class].prototype.DSSave = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
args.unshift(this[def.idAttribute]); | ||
args.unshift(def.name); | ||
return _this.save.apply(_this, args); | ||
}; | ||
// Initialize store data for the new resource | ||
@@ -189,0 +203,0 @@ _this.store[def.name] = { |
@@ -31,3 +31,3 @@ var DSUtils = require('../../utils'); | ||
if (!('notify' in options)) { | ||
options.notify = true; | ||
options.notify = definition.notify; | ||
} | ||
@@ -56,3 +56,3 @@ if (options.notify) { | ||
definition.afterEject(definition.name, item); | ||
_this.notify(definition, 'eject', item); | ||
_this.emit(definition, 'eject', item); | ||
} | ||
@@ -59,0 +59,0 @@ |
var DSUtils = require('../../utils'); | ||
var DSErrors = require('../../errors'); | ||
var observe = require('../../../lib/observe-js/observe-js'); | ||
var stack = 0; | ||
var data = { | ||
injectedSoFar: {} | ||
}; | ||
function _injectRelations(definition, injected, options) { | ||
var _this = this; | ||
DSUtils.forEach(definition.relationList, function (def) { | ||
var relationName = def.relation; | ||
var relationDef = _this.definitions[relationName]; | ||
if (relationDef && injected[def.localField]) { | ||
try { | ||
injected[def.localField] = _this.inject(relationName, injected[def.localField], options); | ||
} catch (err) { | ||
console.error(definition.name + ': Failed to inject ' + def.type + ' relation: "' + relationName + '"!', err); | ||
} | ||
} | ||
}); | ||
} | ||
function _getReactFunction(DS, definition, resource) { | ||
@@ -126,2 +138,6 @@ return function _react(added, removed, changed, oldValueFn, firstTime) { | ||
_react.call(item, {}, {}, {}, null, true); | ||
if (definition.relations) { | ||
_injectRelations.call(_this, definition, item, options); | ||
} | ||
} else { | ||
@@ -152,41 +168,11 @@ DSUtils.deepMixIn(item, attrs); | ||
function _injectRelations(definition, injected, options) { | ||
function _link(definition, injected, options) { | ||
var _this = this; | ||
function _process(def, relationName, injected) { | ||
var relationDef = _this.definitions[relationName]; | ||
if (relationDef && injected[def.localField] && !data.injectedSoFar[relationName + injected[def.localField][relationDef.idAttribute]]) { | ||
try { | ||
data.injectedSoFar[relationName + injected[def.localField][relationDef.idAttribute]] = 1; | ||
injected[def.localField] = _this.inject(relationName, injected[def.localField], options); | ||
} catch (err) { | ||
console.error(definition.name + ': Failed to inject ' + def.type + ' relation: "' + relationName + '"!', err); | ||
} | ||
} else if (options.findBelongsTo && def.type === 'belongsTo') { | ||
if (DSUtils.isArray(injected)) { | ||
DSUtils.forEach(injected, function (injectedItem) { | ||
_this.link(definition.name, injectedItem[definition.idAttribute], [relationName]); | ||
}); | ||
} else { | ||
_this.link(definition.name, injected[definition.idAttribute], [relationName]); | ||
} | ||
DSUtils.forEach(definition.relationList, function (def) { | ||
if (options.findBelongsTo && def.type === 'belongsTo' && injected[definition.idAttribute]) { | ||
_this.link(definition.name, injected[definition.idAttribute], [def.relation]); | ||
} else if ((options.findHasMany && def.type === 'hasMany') || (options.findHasOne && def.type === 'hasOne')) { | ||
if (DSUtils.isArray(injected)) { | ||
DSUtils.forEach(injected, function (injectedItem) { | ||
_this.link(definition.name, injectedItem[definition.idAttribute], [relationName]); | ||
}); | ||
} else { | ||
_this.link(definition.name, injected[definition.idAttribute], [relationName]); | ||
} | ||
_this.link(definition.name, injected[definition.idAttribute], [def.relation]); | ||
} | ||
} | ||
DSUtils.forEach(definition.relationList, function (def) { | ||
if (DSUtils.isArray(injected)) { | ||
DSUtils.forEach(injected, function (injectedI) { | ||
_process(def, def.relation, injectedI); | ||
}); | ||
} else { | ||
_process(def, def.relation, injected); | ||
} | ||
}); | ||
@@ -210,41 +196,33 @@ } | ||
stack++; | ||
if (!('useClass' in options)) { | ||
options.useClass = definition.useClass; | ||
} | ||
if (!('notify' in options)) { | ||
options.notify = definition.notify; | ||
} | ||
if (options.notify) { | ||
definition.beforeInject(definition.name, attrs); | ||
} | ||
try { | ||
if (!('useClass' in options)) { | ||
options.useClass = definition.useClass; | ||
} | ||
if (!('notify' in options)) { | ||
options.notify = true; | ||
} | ||
if (options.notify) { | ||
definition.beforeInject(definition.name, attrs); | ||
} | ||
injected = _inject.call(_this, definition, _this.store[resourceName], attrs, options); | ||
injected = _inject.call(_this, definition, _this.store[resourceName], attrs, options); | ||
if (definition.relations) { | ||
_injectRelations.call(_this, definition, injected, options); | ||
if (options.linkInverse) { | ||
if (DSUtils.isArray(injected) && injected.length) { | ||
_this.linkInverse(definition.name, injected[0][definition.idAttribute]); | ||
} else { | ||
_this.linkInverse(definition.name, injected[definition.idAttribute]); | ||
} | ||
} | ||
if (options.linkInverse) { | ||
if (DSUtils.isArray(injected) && injected.length) { | ||
_this.linkInverse(definition.name, injected[0][definition.idAttribute]); | ||
} else { | ||
_this.linkInverse(definition.name, injected[definition.idAttribute]); | ||
} | ||
} | ||
if (options.notify) { | ||
definition.afterInject(definition.name, injected); | ||
_this.notify(definition, 'inject', injected); | ||
} | ||
stack--; | ||
} catch (err) { | ||
stack--; | ||
throw err; | ||
if (DSUtils.isArray(injected)) { | ||
DSUtils.forEach(injected, function (injectedI) { | ||
_link.call(_this, definition, injectedI, options); | ||
}); | ||
} else { | ||
_link.call(_this, definition, injected, options); | ||
} | ||
if (!stack) { | ||
data.injectedSoFar = {}; | ||
if (options.notify) { | ||
definition.afterInject(definition.name, injected); | ||
_this.emit(definition, 'inject', injected); | ||
} | ||
@@ -251,0 +229,0 @@ |
@@ -14,3 +14,3 @@ describe('DS.create(resourceName, attrs[, options])', function () { | ||
datastore.create('post', { author: 'John', age: 30 }).then(function (post) { | ||
assert.deepEqual(post, p1, 'post 5 should have been created'); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p1), 'post 5 should have been created'); | ||
assert.equal(lifecycle.beforeCreate.callCount, 1, 'beforeCreate should have been called'); | ||
@@ -22,3 +22,3 @@ assert.equal(lifecycle.afterCreate.callCount, 1, 'afterCreate should have been called'); | ||
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called'); | ||
assert.deepEqual(datastore.get('post', 5), p1); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(p1)); | ||
done(); | ||
@@ -41,3 +41,3 @@ }).catch(function (err) { | ||
datastore.create('post', { author: 'John', age: 30 }, { cacheResponse: false }).then(function (post) { | ||
assert.deepEqual(post, p1, 'post 5 should have been created'); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p1), 'post 5 should have been created'); | ||
assert.equal(lifecycle.beforeCreate.callCount, 1, 'beforeCreate should have been called'); | ||
@@ -68,6 +68,6 @@ assert.equal(lifecycle.afterCreate.callCount, 1, 'afterCreate should have been called'); | ||
datastore.create('post', { author: 'John', age: 30, id: 5 }).then(function (post) { | ||
assert.deepEqual(post, p1, 'post 5 should have been created'); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p1), 'post 5 should have been created'); | ||
datastore.create('post', { author: 'Sue', age: 70, id: 6 }, { upsert: false }).then(function (post) { | ||
assert.deepEqual(post, p2, 'post 6 should have been created'); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p2), 'post 6 should have been created'); | ||
assert.equal(lifecycle.beforeUpdate.callCount, 1, 'beforeUpdate should have been called'); | ||
@@ -129,3 +129,3 @@ assert.equal(lifecycle.afterUpdate.callCount, 1, 'afterUpdate should have been called'); | ||
}).then(function (user) { | ||
assert.deepEqual(user.id, payload.id, 'user should have been created'); | ||
assert.equal(user.id, payload.id, 'user should have been created'); | ||
@@ -138,5 +138,5 @@ assert.equal(lifecycle.beforeCreate.callCount, 1, 'beforeCreate should have been called twice'); | ||
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called'); | ||
assert.deepEqual(datastore.get('user', 99).id, payload.id); | ||
assert.equal(datastore.get('user', 99).id, payload.id); | ||
assert.isObject(datastore.get('user', 99).profile); | ||
assert.deepEqual(datastore.get('profile', 999).id, 999); | ||
assert.equal(datastore.get('profile', 999).id, 999); | ||
assert.isObject(datastore.get('profile', 999).user); | ||
@@ -182,4 +182,4 @@ | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment); | ||
assert.deepEqual(comment, datastore.get('comment', 5)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 5))); | ||
@@ -193,4 +193,4 @@ datastore.create('comment', { | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment2); | ||
assert.deepEqual(comment, datastore.get('comment', 6)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment2)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 6))); | ||
@@ -205,4 +205,4 @@ datastore.create('comment', { | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment2); | ||
assert.deepEqual(comment, datastore.get('comment', 6)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment2)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 6))); | ||
done(); | ||
@@ -209,0 +209,0 @@ }).catch(function () { |
@@ -32,3 +32,3 @@ describe('DS.destroyAll(resourceName, params[, options]): ', function () { | ||
datastore.destroyAll('post', {}).then(function () { | ||
assert.deepEqual(datastore.filter('post', {}), [], 'The posts should not be in the store yet'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', {})), JSON.stringify([]), 'The posts should not be in the store yet'); | ||
done(); | ||
@@ -35,0 +35,0 @@ }, function (err) { |
@@ -33,4 +33,4 @@ describe('DS.find(resourceName, id[, options]): ', function () { | ||
datastore.find('post', 5).then(function (post) { | ||
assert.deepEqual(post, p1); | ||
assert.deepEqual(datastore.get('post', 5), p1, 'The post is now in the datastore'); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p1)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(p1), 'The post is now in the datastore'); | ||
assert.isNumber(datastore.lastModified('post', 5)); | ||
@@ -47,4 +47,4 @@ assert.isNumber(datastore.lastSaved('post', 5)); | ||
datastore.find('post', 5).then(function (post) { | ||
assert.deepEqual(post, p1); | ||
assert.deepEqual(datastore.get('post', 5), p1, 'The post is now in the datastore'); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p1)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(p1), 'The post is now in the datastore'); | ||
assert.isNumber(datastore.lastModified('post', 5)); | ||
@@ -57,6 +57,6 @@ assert.isNumber(datastore.lastSaved('post', 5)); | ||
datastore.find('post', 5).then(function (post) { | ||
assert.deepEqual(post, p1); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p1)); | ||
// Should make a request because bypassCache is set to true | ||
datastore.find('post', 5, { bypassCache: true }).then(function (post) { | ||
assert.deepEqual(post, p1); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p1)); | ||
@@ -99,3 +99,3 @@ assert.equal(lifecycle.beforeInject.callCount, 2, 'beforeInject should have been called'); | ||
datastore.find('post', 5, { cacheResponse: false }).then(function (post) { | ||
assert.deepEqual(post, p1); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(p1)); | ||
@@ -152,4 +152,4 @@ assert.isUndefined(datastore.get('post', 5), 'The post should not have been injected into the store'); | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment); | ||
assert.deepEqual(comment, datastore.get('comment', 5)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 5))); | ||
@@ -159,4 +159,4 @@ datastore.find('comment', 5, { | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment); | ||
assert.deepEqual(comment, datastore.get('comment', 5)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 5))); | ||
@@ -169,4 +169,4 @@ datastore.find('comment', 5, { | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment); | ||
assert.deepEqual(comment, datastore.get('comment', 5)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 5))); | ||
@@ -180,4 +180,4 @@ datastore.find('comment', 19, { | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, comment19); | ||
assert.deepEqual(comment, datastore.get('comment', 19)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(comment19)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 19))); | ||
@@ -184,0 +184,0 @@ done(); |
@@ -35,3 +35,3 @@ describe('DS.findAll(resourceName, params[, options]): ', function () { | ||
datastore.findAll('post', {}).then(function (data) { | ||
assert.deepEqual(data, [p1, p2, p3, p4]); | ||
assert.deepEqual(JSON.stringify(data), JSON.stringify([p1, p2, p3, p4])); | ||
}).catch(function (err) { | ||
@@ -42,9 +42,9 @@ console.error(err.stack); | ||
assert.deepEqual(datastore.filter('post', {}), [], 'The posts should not be in the store yet'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', {})), JSON.stringify([]), 'The posts should not be in the store yet'); | ||
// Should have no effect because there is already a pending query | ||
datastore.findAll('post', {}).then(function (data) { | ||
assert.deepEqual(data, [p1, p2, p3, p4]); | ||
assert.deepEqual(JSON.stringify(data), JSON.stringify([p1, p2, p3, p4])); | ||
assert.deepEqual(datastore.filter('post', {}), [p1, p2, p3, p4], 'The posts are now in the store'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', {})), JSON.stringify([p1, p2, p3, p4]), 'The posts are now in the store'); | ||
assert.isNumber(datastore.lastModified('post', 5)); | ||
@@ -56,3 +56,3 @@ assert.isNumber(datastore.lastSaved('post', 5)); | ||
datastore.findAll('post', {}).then(function (data) { | ||
assert.deepEqual(data, [p1, p2, p3, p4]); | ||
assert.deepEqual(JSON.stringify(data), JSON.stringify([p1, p2, p3, p4])); | ||
}).catch(function (err) { | ||
@@ -65,3 +65,3 @@ console.error(err.stack); | ||
datastore.findAll('post', {}, { bypassCache: true }).then(function (data) { | ||
assert.deepEqual(data, [p1, p2, p3, p4]); | ||
assert.deepEqual(JSON.stringify(data), JSON.stringify([p1, p2, p3, p4])); | ||
assert.equal(lifecycle.beforeInject.callCount, 2, 'beforeInject should have been called'); | ||
@@ -103,3 +103,3 @@ assert.equal(lifecycle.afterInject.callCount, 2, 'afterInject should have been called'); | ||
assert(err.message, 'post.inject: "attrs" must contain the property specified by `idAttribute`!'); | ||
assert.deepEqual(datastore.filter('post', {}), [], 'The posts should not be in the store'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', {})), JSON.stringify([]), 'The posts should not be in the store'); | ||
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called once'); | ||
@@ -127,5 +127,5 @@ assert.equal(lifecycle.afterInject.callCount, 0, 'afterInject should not have been called'); | ||
datastore.findAll('post', {}, { cacheResponse: false }).then(function (data) { | ||
assert.deepEqual(data, [p1, p2, p3, p4]); | ||
assert.deepEqual(JSON.stringify(data), JSON.stringify([p1, p2, p3, p4])); | ||
assert.deepEqual(datastore.filter('post', {}), [], 'The posts should not have been injected into the store'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', {})), JSON.stringify([]), 'The posts should not have been injected into the store'); | ||
@@ -174,4 +174,4 @@ assert.equal(lifecycle.beforeInject.callCount, 0, 'beforeInject should have been called'); | ||
datastore.findAll('post').then(function (data) { | ||
assert.deepEqual(data, [p1, p2, p3, p4]); | ||
assert.deepEqual(datastore.filter('post', {}), [p1, p2, p3, p4], 'The posts are now in the store'); | ||
assert.deepEqual(JSON.stringify(data), JSON.stringify([p1, p2, p3, p4])); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', {})), JSON.stringify([p1, p2, p3, p4]), 'The posts are now in the store'); | ||
@@ -204,5 +204,5 @@ assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called'); | ||
datastore.findAll('post', params).then(function (data) { | ||
assert.deepEqual(data, [p4, p5]); | ||
assert.deepEqual(datastore.filter('post', params), [p4, p5], 'The posts are now in the store'); | ||
assert.deepEqual(datastore.filter('post', { | ||
assert.deepEqual(JSON.stringify(data), JSON.stringify([p4, p5])); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p4, p5]), 'The posts are now in the store'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', { | ||
where: { | ||
@@ -213,3 +213,3 @@ id: { | ||
} | ||
}), [p5], 'The posts are now in the store'); | ||
})), JSON.stringify([p5]), 'The posts are now in the store'); | ||
@@ -255,13 +255,13 @@ assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called'); | ||
datastore.findAll('person').then(function (data) { | ||
assert.deepEqual(data, [ | ||
assert.deepEqual(JSON.stringify(data), JSON.stringify([ | ||
DSUtils.deepMixIn(new datastore.definitions.person[datastore.definitions.person.class](), u1), | ||
DSUtils.deepMixIn(new datastore.definitions.person[datastore.definitions.person.class](), u2) | ||
]); | ||
])); | ||
DSUtils.forEach(data, function (person) { | ||
assert.isTrue(person instanceof datastore.definitions.person[datastore.definitions.person.class], 'should be an instance of User'); | ||
}); | ||
assert.deepEqual(datastore.filter('person'), [ | ||
assert.deepEqual(JSON.stringify(datastore.filter('person')), JSON.stringify([ | ||
DSUtils.deepMixIn(new datastore.definitions.person[datastore.definitions.person.class](), u1), | ||
DSUtils.deepMixIn(new datastore.definitions.person[datastore.definitions.person.class](), u2) | ||
], 'The users are now in the store'); | ||
]), 'The users are now in the store'); | ||
@@ -305,6 +305,6 @@ assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called'); | ||
}).then(function (comments) { | ||
assert.deepEqual(comments, [testComment, testComment2]); | ||
assert.deepEqual(comments, datastore.filter('comment', { | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify([testComment, testComment2])); | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify(datastore.filter('comment', { | ||
content: 'test' | ||
})); | ||
}))); | ||
datastore.ejectAll('comment'); | ||
@@ -317,6 +317,6 @@ | ||
}).then(function (comments) { | ||
assert.deepEqual(comments, [testComment, testComment2]); | ||
assert.deepEqual(comments, datastore.filter('comment', { | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify([testComment, testComment2])); | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify(datastore.filter('comment', { | ||
content: 'test' | ||
})); | ||
}))); | ||
datastore.ejectAll('comment'); | ||
@@ -332,6 +332,6 @@ | ||
}).then(function (comments) { | ||
assert.deepEqual(comments, [testComment, testComment2]); | ||
assert.deepEqual(comments, datastore.filter('comment', { | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify([testComment, testComment2])); | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify(datastore.filter('comment', { | ||
content: 'test' | ||
})); | ||
}))); | ||
done(); | ||
@@ -338,0 +338,0 @@ }).catch(function () { |
@@ -51,7 +51,7 @@ describe('DS.loadRelations(resourceName, instance(Id), relations[, options]): ', function () { | ||
assert.deepEqual(user.comments[0].id, datastore.get('comment', user.comments[0].id).id); | ||
assert.deepEqual(user.comments[0].user, datastore.get('comment', user.comments[0].id).user); | ||
assert.deepEqual(user.comments[0].user.id, datastore.get('comment', user.comments[0].id).user.id); | ||
assert.deepEqual(user.comments[1].id, datastore.get('comment', user.comments[1].id).id); | ||
assert.deepEqual(user.comments[1].user, datastore.get('comment', user.comments[1].id).user); | ||
assert.deepEqual(user.comments[1].user.id, datastore.get('comment', user.comments[1].id).user.id); | ||
assert.deepEqual(user.comments[2].id, datastore.get('comment', user.comments[2].id).id); | ||
assert.deepEqual(user.comments[2].user, datastore.get('comment', user.comments[2].id).user); | ||
assert.deepEqual(user.comments[2].user.id, datastore.get('comment', user.comments[2].id).user.id); | ||
assert.deepEqual(user.organization.id, datastore.get('organization', 14).id); | ||
@@ -113,9 +113,9 @@ assert.deepEqual(user.profile.id, datastore.get('profile', 15).id); | ||
datastore.loadRelations('user', 10, ['comment', 'profile', 'organization'], { cacheResponse: false }).then(function (user) { | ||
assert.deepEqual(user.comments, [ | ||
assert.deepEqual(JSON.stringify(user.comments), JSON.stringify([ | ||
comment11, | ||
comment12, | ||
comment13 | ||
]); | ||
assert.deepEqual(user.organization, organization14); | ||
assert.deepEqual(user.profile, profile15); | ||
])); | ||
assert.deepEqual(JSON.stringify(user.organization), JSON.stringify(organization14)); | ||
assert.deepEqual(JSON.stringify(user.profile), JSON.stringify(profile15)); | ||
@@ -122,0 +122,0 @@ assert.isUndefined(datastore.get('comment', 11)); |
@@ -45,3 +45,3 @@ describe('DS.refresh(resourceName, id[, options]): ', function () { | ||
datastore.inject('post', p1); | ||
assert.deepEqual(datastore.get('post', 5), p1, 'The post is now in the store'); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(p1), 'The post is now in the store'); | ||
@@ -52,3 +52,3 @@ var initialLastModified = datastore.lastModified('post', 5); | ||
datastore.refresh('post', 5).then(function (post) { | ||
assert.deepEqual(post, { author: 'Jake', age: 31, id: 5 }); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify({ author: 'Jake', age: 31, id: 5 })); | ||
}).catch(function (err) { | ||
@@ -61,4 +61,4 @@ console.error(err.stack); | ||
datastore.refresh('post', 5).then(function (post) { | ||
assert.deepEqual(post, { author: 'Jake', age: 31, id: 5 }); | ||
assert.deepEqual(datastore.get('post', 5), { author: 'Jake', age: 31, id: 5 }, 'The post has been refreshed'); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify({ author: 'Jake', age: 31, id: 5 })); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify({ author: 'Jake', age: 31, id: 5 }), 'The post has been refreshed'); | ||
assert.notEqual(datastore.lastModified('post', 5), initialLastModified); | ||
@@ -65,0 +65,0 @@ done(); |
@@ -45,7 +45,7 @@ describe('DS.save(resourceName, id[, options])', function () { | ||
assert.equal(lifecycle.afterUpdate.callCount, 1, 'afterUpdate should have been called'); | ||
assert.deepEqual(datastore.get('post', 5), { | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify({ | ||
author: 'Jake', | ||
id: 5, | ||
age: 30 | ||
}); | ||
age: 30, | ||
id: 5 | ||
})); | ||
datastore.digest(); | ||
@@ -103,2 +103,58 @@ assert.notEqual(datastore.lastModified('post', 5), initialModified); | ||
}); | ||
it('should save an item to the server and inject the result via the instance method', function (done) { | ||
var _this = this; | ||
var post = datastore.inject('post', p1); | ||
var initialModified = datastore.lastModified('post', 5); | ||
var initialSaved = datastore.lastSaved('post', 5); | ||
datastore.get('post', 5).author = 'Jake'; | ||
post.DSSave().then(function (post) { | ||
try { | ||
assert.deepEqual(DSUtils.toJson(post), DSUtils.toJson(datastore.get('post', 5)), 'post 5 should have been saved'); | ||
assert.equal(post.author, 'Jake'); | ||
assert.equal(lifecycle.beforeUpdate.callCount, 1, 'beforeUpdate should have been called'); | ||
assert.equal(lifecycle.afterUpdate.callCount, 1, 'afterUpdate should have been called'); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify({ | ||
author: 'Jake', | ||
age: 30, | ||
id: 5 | ||
})); | ||
datastore.digest(); | ||
assert.notEqual(datastore.lastModified('post', 5), initialModified); | ||
assert.notEqual(datastore.lastSaved('post', 5), initialSaved); | ||
done(); | ||
} catch (err) { | ||
done(err); | ||
} | ||
}, function (err) { | ||
console.log(err); | ||
done(err); | ||
}).catch(function (err) { | ||
console.error(stack); | ||
done(err); | ||
}); | ||
setTimeout(function () { | ||
try { | ||
assert.equal(1, _this.requests.length); | ||
assert.equal(_this.requests[0].url, 'http://test.js-data.io/posts/5'); | ||
assert.equal(_this.requests[0].method, 'put'); | ||
assert.equal(_this.requests[0].requestBody, DSUtils.toJson({ | ||
author: 'Jake', | ||
age: 30, | ||
id: 5 | ||
})); | ||
_this.requests[0].respond(200, {'Content-Type': 'application/json'}, DSUtils.toJson({ | ||
author: 'Jake', | ||
id: 5, | ||
age: 30 | ||
})); | ||
} catch (err) { | ||
console.log(err.stack); | ||
done(err); | ||
} | ||
}, 30); | ||
}); | ||
it('should save an item to the server but not inject the result', function (done) { | ||
@@ -113,5 +169,5 @@ var _this = this; | ||
datastore.save('post', 5, { cacheResponse: false }).then(function (post) { | ||
assert.deepEqual(post, { | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify({ | ||
random: 'stuff' | ||
}, 'should have the right response'); | ||
}), 'should have the right response'); | ||
assert.equal(lifecycle.beforeUpdate.callCount, 1, 'beforeUpdate should have been called'); | ||
@@ -121,7 +177,7 @@ assert.equal(lifecycle.afterUpdate.callCount, 1, 'afterUpdate should have been called'); | ||
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called only once'); | ||
assert.deepEqual(datastore.get('post', 5), { | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify({ | ||
author: 'Jake', | ||
id: 5, | ||
age: 30 | ||
}); | ||
age: 30, | ||
id: 5 | ||
})); | ||
// item wasn't injected | ||
@@ -164,7 +220,7 @@ assert.equal(datastore.lastModified('post', 5), initialModified); | ||
datastore.save('post', 5, { changesOnly: true }).then(function (post) { | ||
assert.deepEqual(post, post1, 'post 5 should have been saved'); | ||
assert.deepEqual(JSON.stringify(post), JSON.stringify(post1), 'post 5 should have been saved'); | ||
assert.equal(post.author, 'Jake'); | ||
assert.equal(lifecycle.beforeUpdate.callCount, 1, 'beforeUpdate should have been called'); | ||
assert.equal(lifecycle.afterUpdate.callCount, 1, 'afterUpdate should have been called'); | ||
assert.deepEqual(datastore.get('post', 5), post1); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(post1)); | ||
assert.notEqual(datastore.lastModified('post', 5), initialModified); | ||
@@ -198,4 +254,4 @@ assert.notEqual(datastore.lastSaved('post', 5), initialSaved); | ||
author: 'Jake', | ||
id: 5, | ||
age: 30 | ||
age: 30, | ||
id: 5 | ||
})); | ||
@@ -202,0 +258,0 @@ } catch (err) { |
@@ -37,3 +37,3 @@ describe('DS.update(resourceName, id, attrs[, options])', function () { | ||
datastore.update('post', 5, { author: 'Jake' }).then(function (p) { | ||
assert.deepEqual(p, post, 'post 5 should have been updated'); | ||
assert.deepEqual(JSON.stringify(p), JSON.stringify(post), 'post 5 should have been updated'); | ||
assert.equal(p.author, 'Jake'); | ||
@@ -48,3 +48,3 @@ assert.equal(post.author, 'Jake'); | ||
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called'); | ||
assert.deepEqual(datastore.get('post', 5), post); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(post)); | ||
assert.notEqual(datastore.lastModified('post', 5), initialModified); | ||
@@ -54,4 +54,4 @@ assert.notEqual(datastore.lastSaved('post', 5), initialSaved); | ||
datastore.update('post', 6, { author: 'Jane' }).then(function (p) { | ||
assert.deepEqual(p, datastore.get('post', 6)); | ||
assert.deepEqual(p, { author: 'Jane', age: 31, id: 6 }); | ||
assert.deepEqual(JSON.stringify(p), JSON.stringify(datastore.get('post', 6))); | ||
assert.deepEqual(JSON.stringify(p), JSON.stringify({ author: 'Jane', age: 31, id: 6 })); | ||
assert.equal(lifecycle.beforeInject.callCount, 3, 'beforeInject should have been called'); | ||
@@ -87,2 +87,37 @@ assert.equal(lifecycle.afterInject.callCount, 3, 'afterInject should have been called'); | ||
}); | ||
it('should update an item via the instance method', function (done) { | ||
var _this = this; | ||
var post = datastore.inject('post', p1); | ||
var initialModified = datastore.lastModified('post', 5); | ||
var initialSaved = datastore.lastSaved('post', 5); | ||
post.DSUpdate({ author: 'Jake' }).then(function (p) { | ||
assert.deepEqual(JSON.stringify(p), JSON.stringify(post), 'post 5 should have been updated'); | ||
assert.equal(p.author, 'Jake'); | ||
assert.equal(post.author, 'Jake'); | ||
assert.equal(lifecycle.beforeUpdate.callCount, 1, 'beforeUpdate should have been called'); | ||
assert.equal(lifecycle.afterUpdate.callCount, 1, 'afterUpdate should have been called'); | ||
assert.equal(lifecycle.beforeInject.callCount, 2, 'beforeInject should have been called'); | ||
assert.equal(lifecycle.afterInject.callCount, 2, 'afterInject should have been called'); | ||
assert.equal(lifecycle.serialize.callCount, 1, 'serialize should have been called'); | ||
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called'); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(post)); | ||
assert.notEqual(datastore.lastModified('post', 5), initialModified); | ||
assert.notEqual(datastore.lastSaved('post', 5), initialSaved); | ||
done(); | ||
}).catch(function (err) { | ||
console.error(err.stack); | ||
done('should not have rejected'); | ||
}); | ||
setTimeout(function () { | ||
assert.equal(1, _this.requests.length); | ||
assert.equal(_this.requests[0].url, 'http://test.js-data.io/posts/5'); | ||
assert.equal(_this.requests[0].method, 'put'); | ||
assert.equal(_this.requests[0].requestBody, DSUtils.toJson({ author: 'Jake' })); | ||
_this.requests[0].respond(200, {'Content-Type': 'application/json'}, DSUtils.toJson({ author: 'Jake', age: 30, id: 5 })); | ||
}, 30); | ||
}); | ||
it('should handle nested resources', function (done) { | ||
@@ -106,8 +141,8 @@ var _this = this; | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment); | ||
assert.deepEqual(comment, datastore.get('comment', 5)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 5))); | ||
var c = Comment.inject(testComment2); | ||
function onBeforeUpdate (resourceName, attrs) { | ||
function onBeforeUpdate(resourceName, attrs) { | ||
attrs.other = 'stuff'; | ||
@@ -134,4 +169,4 @@ assert.equal(resourceName, 'comment'); | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment2); | ||
assert.deepEqual(comment, datastore.get('comment', 6)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment2)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 6))); | ||
@@ -147,4 +182,4 @@ datastore.inject('comment', testComment2); | ||
}).then(function (comment) { | ||
assert.deepEqual(comment, testComment2); | ||
assert.deepEqual(comment, datastore.get('comment', 6)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(testComment2)); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify(datastore.get('comment', 6))); | ||
done(); | ||
@@ -151,0 +186,0 @@ }).catch(function () { |
@@ -32,3 +32,3 @@ describe('DS.updateAll(resourceName, attrs, params[, options])', function () { | ||
datastore.updateAll('post', { age: 27 }, { where: { age: { '==': 33 } } }).then(function (ps) { | ||
assert.deepEqual(ps, posts, '2 posts should have been updated'); | ||
assert.deepEqual(JSON.stringify(ps), JSON.stringify(posts), '2 posts should have been updated'); | ||
assert.equal(posts[0].age, 27); | ||
@@ -40,3 +40,3 @@ assert.equal(posts[1].age, 27); | ||
assert.equal(lifecycle.afterUpdate.callCount, 1, 'afterUpdate should have been called'); | ||
assert.deepEqual(datastore.filter('post', { where: { age: { '==': 27 } } }), posts); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', { where: { age: { '==': 27 } } })), JSON.stringify(posts)); | ||
assert.notEqual(datastore.lastModified('post', 8), initialModified); | ||
@@ -46,4 +46,4 @@ assert.notEqual(datastore.lastSaved('post', 8), initialSaved); | ||
datastore.updateAll('post', { age: 5 }, { where: { age: { '==': 31 } } }).then(function (ps) { | ||
assert.deepEqual(ps, datastore.filter('post', { where: { age: { '==': 5 } } })); | ||
assert.deepEqual(ps[0], { author: 'Jane', age: 5, id: 6 }); | ||
assert.deepEqual(JSON.stringify(ps), JSON.stringify(datastore.filter('post', { where: { age: { '==': 5 } } }))); | ||
assert.deepEqual(JSON.stringify(ps[0]), JSON.stringify({ author: 'Jane', age: 5, id: 6 })); | ||
assert.equal(lifecycle.beforeInject.callCount, 4, 'beforeInject should have been called'); | ||
@@ -108,6 +108,6 @@ assert.equal(lifecycle.afterInject.callCount, 4, 'afterInject should have been called'); | ||
}).then(function (comments) { | ||
assert.deepEqual(comments, [testComment, testComment2]); | ||
assert.deepEqual(comments, datastore.filter('comment', { | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify([testComment, testComment2])); | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify(datastore.filter('comment', { | ||
content: 'stuff' | ||
})); | ||
}))); | ||
datastore.ejectAll('comment'); | ||
@@ -122,7 +122,7 @@ | ||
}).then(function (comments) { | ||
assert.deepEqual(comments, [testComment, testComment2]); | ||
assert.deepEqual(comments, datastore.filter('comment', { | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify([testComment, testComment2])); | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify(datastore.filter('comment', { | ||
content: 'stuff', | ||
sort: 'id' | ||
})); | ||
}))); | ||
datastore.ejectAll('comment'); | ||
@@ -141,7 +141,7 @@ | ||
}).then(function (comments) { | ||
assert.deepEqual(comments, [testComment, testComment2]); | ||
assert.deepEqual(comments, datastore.filter('comment', { | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify([testComment, testComment2])); | ||
assert.deepEqual(JSON.stringify(comments), JSON.stringify(datastore.filter('comment', { | ||
content: 'stuff', | ||
sort: 'id' | ||
})); | ||
}))); | ||
done(); | ||
@@ -148,0 +148,0 @@ }).catch(function () { |
@@ -50,3 +50,3 @@ describe('DS.defineResource(definition)', function () { | ||
name: 'Comment', | ||
baseUrl: 'hello/', | ||
basePath: 'hello/', | ||
validate: test.validate | ||
@@ -74,6 +74,6 @@ }); | ||
setTimeout(function () { | ||
assert.deepEqual(datastore.get('Comment', 1), { name: 'Sally', id: 1 }); | ||
assert.deepEqual(JSON.stringify(datastore.get('Comment', 1)), JSON.stringify({ name: 'Sally', id: 1 })); | ||
datastore.create('Comment', { name: 'John' }).then(function (comment) { | ||
assert.deepEqual(comment, { name: 'John', id: 2 }); | ||
assert.deepEqual(JSON.stringify(comment), JSON.stringify({ name: 'John', id: 2 })); | ||
assert.equal(callCount, 1, 'overridden validate should have been called once'); | ||
@@ -80,0 +80,0 @@ assert.equal(lifecycle.validate.callCount, 0, 'global validate should not have been called'); |
@@ -57,6 +57,6 @@ describe('DS.ejectAll(resourceName[, params])', function () { | ||
assert.deepEqual(datastore.get('post', 5), p1); | ||
assert.deepEqual(datastore.get('post', 6), p2); | ||
assert.deepEqual(datastore.get('post', 7), p3); | ||
assert.deepEqual(datastore.get('post', 8), p4); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(p1)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 6)), JSON.stringify(p2)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 7)), JSON.stringify(p3)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 8)), JSON.stringify(p4)); | ||
@@ -69,3 +69,3 @@ datastore.store.post.completedQueries.test = 'stuff'; | ||
assert.deepEqual(datastore.store.post.completedQueries, {}); | ||
assert.deepEqual(JSON.stringify(datastore.store.post.completedQueries), JSON.stringify({})); | ||
assert.isUndefined(datastore.get('post', 5)); | ||
@@ -72,0 +72,0 @@ assert.isUndefined(datastore.get('post', 6)); |
@@ -30,3 +30,3 @@ describe('DS.filter(resourceName[, params][, options])', function () { | ||
assert.deepEqual(datastore.filter('post', { | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', { | ||
where: { | ||
@@ -37,5 +37,5 @@ author: { | ||
} | ||
}, { loadFromServer: true }), [], 'should be an empty array'); | ||
}, { loadFromServer: true })), JSON.stringify([]), 'should be an empty array'); | ||
assert.deepEqual(datastore.filter('post', { | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', { | ||
where: { | ||
@@ -46,3 +46,3 @@ author: { | ||
} | ||
}, { loadFromServer: true }), [], 'should still be an empty array because the request is pending'); | ||
}, { loadFromServer: true })), JSON.stringify([]), 'should still be an empty array because the request is pending'); | ||
@@ -55,3 +55,3 @@ setTimeout(function () { | ||
setTimeout(function () { | ||
assert.deepEqual(datastore.filter('post', { | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', { | ||
where: { | ||
@@ -62,5 +62,5 @@ author: { | ||
} | ||
}), [ | ||
})), JSON.stringify([ | ||
p1 | ||
], 'should no longer be empty'); | ||
]), 'should no longer be empty'); | ||
done(); | ||
@@ -86,3 +86,3 @@ }, 30); | ||
assert.deepEqual(datastore.filter('post', params), [p1], 'should default a string to "=="'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1]), 'should default a string to "=="'); | ||
@@ -94,3 +94,3 @@ params = { | ||
assert.deepEqual(datastore.filter('post', params), [p5], 'should default a string to "=="'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p5]), 'should default a string to "=="'); | ||
@@ -103,3 +103,3 @@ params = { | ||
assert.deepEqual(datastore.filter('post', params), [p1], 'should default a string to "=="'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1]), 'should default a string to "=="'); | ||
@@ -110,3 +110,3 @@ params.where.author = { | ||
assert.deepEqual(datastore.filter('post', params), [p1], 'should accept normal "==" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1]), 'should accept normal "==" clause'); | ||
@@ -117,3 +117,3 @@ params.where.author = { | ||
assert.deepEqual(datastore.filter('post', params), [], 'should accept normal "===" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([]), 'should accept normal "===" clause'); | ||
@@ -124,3 +124,3 @@ params.where.author = { | ||
assert.deepEqual(datastore.filter('post', params), [p2, p3, p4, p5], 'should accept normal "!=" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p2, p3, p4, p5]), 'should accept normal "!=" clause'); | ||
@@ -133,3 +133,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p3, p4, p5], 'should accept normal ">" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p3, p4, p5]), 'should accept normal ">" clause'); | ||
@@ -142,3 +142,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p2, p3, p4, p5], 'should accept normal ">=" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p2, p3, p4, p5]), 'should accept normal ">=" clause'); | ||
@@ -151,3 +151,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p1], 'should accept normal "<" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1]), 'should accept normal "<" clause'); | ||
@@ -161,3 +161,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p2, p3], 'should accept dual "<" and ">" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p2, p3]), 'should accept dual "<" and ">" clause'); | ||
@@ -171,3 +171,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3, p4, p5], 'should accept or "<" and ">" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3, p4, p5]), 'should accept or "<" and ">" clause'); | ||
@@ -183,3 +183,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p4, p5], 'should accept or "<=" and "==" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p4, p5]), 'should accept or "<=" and "==" clause'); | ||
@@ -192,3 +192,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2], 'should accept normal "<=" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2]), 'should accept normal "<=" clause'); | ||
@@ -204,3 +204,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p1, p4, p5], 'should accept normal "in" clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p4, p5]), 'should accept normal "in" clause'); | ||
@@ -216,3 +216,3 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p2, p4], 'should accept and/or clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p2, p4]), 'should accept and/or clause'); | ||
@@ -225,7 +225,7 @@ params.where = { | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3, p5], 'should accept notIn clause'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3, p5]), 'should accept notIn clause'); | ||
params.where = { age: { garbage: 'should have no effect' } }; | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3, p4, p5], 'should return all elements'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3, p4, p5]), 'should return all elements'); | ||
}); | ||
@@ -244,7 +244,7 @@ it('should correctly apply "orderBy" predicates', function () { | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3, p4], 'should accept a single string and sort in ascending order for numbers'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3, p4]), 'should accept a single string and sort in ascending order for numbers'); | ||
params.orderBy = 'author'; | ||
assert.deepEqual(datastore.filter('post', params), [p4, p1, p3, p2], 'should accept a single string and sort in ascending for strings'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p4, p1, p3, p2]), 'should accept a single string and sort in ascending for strings'); | ||
@@ -255,3 +255,3 @@ params.orderBy = [ | ||
assert.deepEqual(datastore.filter('post', params), [p4, p3, p2, p1], 'should accept an array of an array and sort in descending for numbers'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p4, p3, p2, p1]), 'should accept an array of an array and sort in descending for numbers'); | ||
@@ -262,11 +262,11 @@ params.orderBy = [ | ||
assert.deepEqual(datastore.filter('post', params), [p2, p3, p1, p4], 'should accept an array of an array and sort in descending for strings'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p2, p3, p1, p4]), 'should accept an array of an array and sort in descending for strings'); | ||
params.orderBy = ['age']; | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3, p4], 'should accept an array of a string and sort in ascending for numbers'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3, p4]), 'should accept an array of a string and sort in ascending for numbers'); | ||
params.orderBy = ['author']; | ||
assert.deepEqual(datastore.filter('post', params), [p4, p1, p3, p2], 'should accept an array of a string and sort in ascending for strings'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p4, p1, p3, p2]), 'should accept an array of a string and sort in ascending for strings'); | ||
}); | ||
@@ -285,12 +285,12 @@ it('should correctly apply "skip" predicates', function () { | ||
assert.deepEqual(datastore.filter('post', params), [p2, p3, p4], 'should skip 1'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p2, p3, p4]), 'should skip 1'); | ||
params.skip = 2; | ||
assert.deepEqual(datastore.filter('post', params), [p3, p4], 'should skip 2'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p3, p4]), 'should skip 2'); | ||
params.skip = 3; | ||
assert.deepEqual(datastore.filter('post', params), [p4], 'should skip 3'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p4]), 'should skip 3'); | ||
params.skip = 4; | ||
assert.deepEqual(datastore.filter('post', params), [], 'should skip 4'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([]), 'should skip 4'); | ||
}); | ||
@@ -309,12 +309,12 @@ it('should correctly apply "limit" predicates', function () { | ||
assert.deepEqual(datastore.filter('post', params), [p1], 'should limit to 1'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1]), 'should limit to 1'); | ||
params.limit = 2; | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2], 'should limit to 2'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2]), 'should limit to 2'); | ||
params.limit = 3; | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3], 'should limit to 3'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3]), 'should limit to 3'); | ||
params.limit = 4; | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3, p4], 'should limit to 4'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3, p4]), 'should limit to 4'); | ||
}); | ||
@@ -334,29 +334,29 @@ it('should correctly apply "limit" and "skip" predicates together', function () { | ||
assert.deepEqual(datastore.filter('post', params), [p2], 'should limit to 1 and skip 2'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p2]), 'should limit to 1 and skip 2'); | ||
params.limit = 2; | ||
assert.deepEqual(datastore.filter('post', params), [p2, p3], 'should limit to 2 and skip 1'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p2, p3]), 'should limit to 2 and skip 1'); | ||
params.skip = 2; | ||
assert.deepEqual(datastore.filter('post', params), [p3, p4], 'should limit to 2 and skip 2'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p3, p4]), 'should limit to 2 and skip 2'); | ||
params.limit = 1; | ||
params.skip = 3; | ||
assert.deepEqual(datastore.filter('post', params), [p4], 'should limit to 1 and skip 3'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p4]), 'should limit to 1 and skip 3'); | ||
params.limit = 8; | ||
params.skip = 0; | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3, p4], 'should return all items'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3, p4]), 'should return all items'); | ||
params.limit = 1; | ||
params.skip = 5; | ||
assert.deepEqual(datastore.filter('post', params), [], 'should return nothing if skip if greater than the number of items'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([]), 'should return nothing if skip if greater than the number of items'); | ||
params.limit = 8; | ||
delete params.skip; | ||
assert.deepEqual(datastore.filter('post', params), [p1, p2, p3, p4], 'should return all items'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([p1, p2, p3, p4]), 'should return all items'); | ||
delete params.limit; | ||
params.skip = 5; | ||
assert.deepEqual(datastore.filter('post', params), [], 'should return nothing if skip if greater than the number of items'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('post', params)), JSON.stringify([]), 'should return nothing if skip if greater than the number of items'); | ||
}); | ||
@@ -393,4 +393,4 @@ it('should allow custom filter function', function () { | ||
assert.deepEqual(datastore.filter('Comment', params), [p1, p2], 'should keep p1 and p2'); | ||
assert.deepEqual(JSON.stringify(datastore.filter('Comment', params)), JSON.stringify([p1, p2]), 'should keep p1 and p2'); | ||
}); | ||
}); |
@@ -38,3 +38,3 @@ describe('DS.get(resourceName, id[, options])', function () { | ||
setTimeout(function () { | ||
assert.deepEqual(datastore.get('post', 5), p1, 'p1 should now be in the store'); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(p1), 'p1 should now be in the store'); | ||
assert.isNumber(datastore.lastModified('post', 5)); | ||
@@ -41,0 +41,0 @@ assert.isNumber(datastore.lastSaved('post', 5)); |
@@ -21,3 +21,3 @@ describe('DS.inject(resourceName, attrs[, options])', function () { | ||
assert.doesNotThrow(function () { | ||
assert.deepEqual(datastore.inject('post', p1), p1); | ||
assert.deepEqual(JSON.stringify(datastore.inject('post', p1)), JSON.stringify(p1)); | ||
}); | ||
@@ -53,9 +53,9 @@ assert.notEqual(datastore.lastModified('post', 5), 0); | ||
assert.doesNotThrow(function () { | ||
assert.deepEqual(datastore.inject('post', [p1, p2, p3, p4]), [p1, p2, p3, p4]); | ||
assert.deepEqual(JSON.stringify(datastore.inject('post', [p1, p2, p3, p4])), JSON.stringify([p1, p2, p3, p4])); | ||
}); | ||
assert.deepEqual(datastore.get('post', 5), p1); | ||
assert.deepEqual(datastore.get('post', 6), p2); | ||
assert.deepEqual(datastore.get('post', 7), p3); | ||
assert.deepEqual(datastore.get('post', 8), p4); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify(p1)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 6)), JSON.stringify(p2)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 7)), JSON.stringify(p3)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 8)), JSON.stringify(p4)); | ||
}); | ||
@@ -69,4 +69,4 @@ it('should inject relations', function () { | ||
assert.deepEqual(datastore.get('user', 1), user1); | ||
assert.deepEqual(datastore.get('organization', 2), organization2); | ||
assert.deepEqual(JSON.stringify(datastore.get('user', 1)), JSON.stringify(user1)); | ||
assert.deepEqual(JSON.stringify(datastore.get('organization', 2)), JSON.stringify(organization2)); | ||
assert.deepEqual(datastore.get('comment', 3).id, comment3.id); | ||
@@ -95,19 +95,19 @@ assert.deepEqual(datastore.get('profile', 4).id, profile4.id); | ||
// user10 relations | ||
assert.deepEqual(datastore.get('comment', 11), datastore.get('user', 10).comments[0]); | ||
assert.deepEqual(datastore.get('comment', 12), datastore.get('user', 10).comments[1]); | ||
assert.deepEqual(datastore.get('comment', 13), datastore.get('user', 10).comments[2]); | ||
assert.deepEqual(datastore.get('organization', 14), datastore.get('user', 10).organization); | ||
assert.deepEqual(datastore.get('profile', 15), datastore.get('user', 10).profile); | ||
assert.deepEqual(JSON.stringify(datastore.get('comment', 11)), JSON.stringify(datastore.get('user', 10).comments[0])); | ||
assert.deepEqual(JSON.stringify(datastore.get('comment', 12)), JSON.stringify(datastore.get('user', 10).comments[1])); | ||
assert.deepEqual(JSON.stringify(datastore.get('comment', 13)), JSON.stringify(datastore.get('user', 10).comments[2])); | ||
assert.deepEqual(JSON.stringify(datastore.get('organization', 14)), JSON.stringify(datastore.get('user', 10).organization)); | ||
assert.deepEqual(JSON.stringify(datastore.get('profile', 15)), JSON.stringify(datastore.get('user', 10).profile)); | ||
// organization15 relations | ||
assert.deepEqual(datastore.get('user', 16), datastore.get('organization', 15).users[0]); | ||
assert.deepEqual(datastore.get('user', 17), datastore.get('organization', 15).users[1]); | ||
assert.deepEqual(datastore.get('user', 18), datastore.get('organization', 15).users[2]); | ||
assert.deepEqual(JSON.stringify(datastore.get('user', 16)), JSON.stringify(datastore.get('organization', 15).users[0])); | ||
assert.deepEqual(JSON.stringify(datastore.get('user', 17)), JSON.stringify(datastore.get('organization', 15).users[1])); | ||
assert.deepEqual(JSON.stringify(datastore.get('user', 18)), JSON.stringify(datastore.get('organization', 15).users[2])); | ||
// comment19 relations | ||
assert.deepEqual(datastore.get('user', 20), datastore.get('comment', 19).user); | ||
assert.deepEqual(datastore.get('user', 19), datastore.get('comment', 19).approvedByUser); | ||
assert.deepEqual(JSON.stringify(datastore.get('user', 20)), JSON.stringify(datastore.get('comment', 19).user)); | ||
assert.deepEqual(JSON.stringify(datastore.get('user', 19)), JSON.stringify(datastore.get('comment', 19).approvedByUser)); | ||
// profile21 relations | ||
assert.deepEqual(datastore.get('user', 22), datastore.get('profile', 21).user); | ||
assert.deepEqual(JSON.stringify(datastore.get('user', 22)), JSON.stringify(datastore.get('profile', 21).user)); | ||
}); | ||
@@ -131,2 +131,64 @@ it('should find inverse links', function () { | ||
}); | ||
it('should inject cyclic dependencies', function () { | ||
datastore.defineResource({ | ||
name: 'foo', | ||
relations: { | ||
hasMany: { | ||
foo: { | ||
localField: 'children', | ||
foreignKey: 'parentId' | ||
} | ||
} | ||
} | ||
}); | ||
var injected = datastore.inject('foo', [{ | ||
id: 1, | ||
children: [ | ||
{ | ||
id: 2, | ||
parentId: 1, | ||
children: [ | ||
{ | ||
id: 4, | ||
parentId: 2 | ||
}, | ||
{ | ||
id: 5, | ||
parentId: 2 | ||
} | ||
] | ||
}, | ||
{ | ||
id: 3, | ||
parentId: 1, | ||
children: [ | ||
{ | ||
id: 6, | ||
parentId: 3 | ||
}, | ||
{ | ||
id: 7, | ||
parentId: 3 | ||
} | ||
] | ||
} | ||
] | ||
}]); | ||
assert.equal(injected[0].id, 1); | ||
assert.equal(injected[0].children[0].id, 2); | ||
assert.equal(injected[0].children[1].id, 3); | ||
assert.equal(injected[0].children[0].children[0].id, 4); | ||
assert.equal(injected[0].children[0].children[1].id, 5); | ||
assert.equal(injected[0].children[1].children[0].id, 6); | ||
assert.equal(injected[0].children[1].children[1].id, 7); | ||
assert.isDefined(datastore.get('foo', 1)); | ||
assert.isDefined(datastore.get('foo', 2)); | ||
assert.isDefined(datastore.get('foo', 3)); | ||
assert.isDefined(datastore.get('foo', 4)); | ||
assert.isDefined(datastore.get('foo', 5)); | ||
assert.isDefined(datastore.get('foo', 6)); | ||
assert.isDefined(datastore.get('foo', 7)); | ||
}); | ||
}); |
@@ -22,3 +22,3 @@ describe('DS.previous(resourceName, id)', function () { | ||
assert.deepEqual(datastore.previous('post', 5), p1); | ||
assert.deepEqual(JSON.stringify(datastore.previous('post', 5)), JSON.stringify(p1)); | ||
@@ -29,8 +29,8 @@ post.author = 'Jake'; | ||
assert.deepEqual(datastore.previous('post', 5), p1); | ||
assert.deepEqual(datastore.get('post', 5), { author: 'Jake', age: 30, id: 5 }); | ||
assert.deepEqual(JSON.stringify(datastore.previous('post', 5)), JSON.stringify(p1)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify({ author: 'Jake', age: 30, id: 5 })); | ||
datastore.save('post', 5).then(function () { | ||
assert.deepEqual(datastore.previous('post', 5), { author: 'Jake', age: 30, id: 5 }, 'previous attributes should have been updated'); | ||
assert.deepEqual(datastore.get('post', 5), { author: 'Jake', age: 30, id: 5 }); | ||
assert.deepEqual(JSON.stringify(datastore.previous('post', 5)), JSON.stringify({ author: 'Jake', age: 30, id: 5 }), 'previous attributes should have been updated'); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify({ author: 'Jake', age: 30, id: 5 })); | ||
done(); | ||
@@ -52,3 +52,3 @@ }).catch(done); | ||
assert.deepEqual(datastore.previous('post', 5), p1); | ||
assert.deepEqual(JSON.stringify(datastore.previous('post', 5)), JSON.stringify(p1)); | ||
@@ -59,8 +59,8 @@ post.author = 'Jake'; | ||
assert.deepEqual(datastore.previous('post', 5), p1); | ||
assert.deepEqual(datastore.get('post', 5), { author: 'Jake', age: 30, id: 5 }); | ||
assert.deepEqual(JSON.stringify(datastore.previous('post', 5)), JSON.stringify(p1)); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify({ author: 'Jake', age: 30, id: 5 })); | ||
datastore.save('post', 5, { changesOnly: true }).then(function () { | ||
assert.deepEqual(datastore.previous('post', 5), { author: 'Jake', age: 30, id: 5 }, 'previous attributes should have been updated'); | ||
assert.deepEqual(datastore.get('post', 5), { author: 'Jake', age: 30, id: 5 }); | ||
assert.deepEqual(JSON.stringify(datastore.previous('post', 5)), JSON.stringify({ author: 'Jake', age: 30, id: 5 }), 'previous attributes should have been updated'); | ||
assert.deepEqual(JSON.stringify(datastore.get('post', 5)), JSON.stringify({ author: 'Jake', age: 30, id: 5 })); | ||
done(); | ||
@@ -67,0 +67,0 @@ }).catch(done); |
Sorry, the diff of this file is too big to display
505822
10736
94