UNPKG

fake-json-api-server

Version:

Simple json-api server running on client. Useful for test runners and setting up fake backend api server for client applications.

13 lines 43.4 kB
var FakeJsonApiServer=function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e){function r(t){return t instanceof Array}function n(t,e,n){if(r(t))for(var i=0;i<t.length;i++)e.call(n,t[i],i);else for(var o in t)t.hasOwnProperty(o)&&e.call(n,t[o],o)}function i(t,e,r){return r.forEach(function(r){e.hasOwnProperty(r)&&(t[r]=e[r])}),t}function o(t){for(var e=1;e<arguments.length;e++)n(arguments[e],function(e,r){void 0!==e&&(t[r]=e)});return t}function s(t,e){return t.filter(function(t){var r=!0;for(var n in e)if(e.hasOwnProperty(n)&&!(r=e[n]===t[n]))break;return r})}function a(t,e){var r=s(t,e);return r.length?r[0]:void 0}t.exports={assign:o,each:n,isArray:r,pick:i,where:s,findWhere:a}},function(t,e,r){var n,i,o;!function(r,s){i=[],n=s,void 0!==(o="function"==typeof n?n.apply(e,i):n)&&(t.exports=o)}(0,function(){function t(t,r){if(e(t))for(var n=0;n<t.length&&!1!==r(t[n],n);n++);else for(var i in t)t.hasOwnProperty(i)&&r(t[i],i)}function e(t){return t&&t.constructor===Array}function r(t){return"[object Object]"===Object.prototype.toString.call(t)}function n(t,e){return"function"==typeof t?t.call(e):t}function i(e){for(var r=1;r<arguments.length;r++)t(arguments[r],function(t,r){void 0!==t&&(e[r]=t)});return e}function o(r,n,i){var s;if(e(n))return s=!1,t(n,function(t){if(o(r,t))return s=!0,!1}),s;s=!0;var h=a.indexOf(n),c=h<0,f=h>=0&&u[h];return c?r instanceof n||(s=!1):"array"===f?!e(r)&&(s=!1):typeof r!==f&&(s=!1),s}function s(t,e,r){e=e||{};var n=e.hasOwnProperty("constructor")?e.constructor:function(){t?t.apply(this,arguments):(this.assignOptions&&(this.writeOptions.apply(this,arguments),this.optionRules&&this.validateOptions(this.options,this.optionRules)),this.initialize&&this.initialize.apply(this,arguments))};if(t){var o=function(){this.constructor=n};o.prototype=t.prototype,n.prototype=new o,i(n,t)}else i(e,h);return r&&i(n,r),i(n.prototype,e),n}var a=[String,Number,Boolean,Function,Object,Array],u=["string","number","boolean","function","object","array"],h={writeOptions:function(e){var o=n(this.defaults,this),s={},a=this;this.optionRules&&t(this.optionRules,function(t,e){s[e]=t.default}),this.optionRules&&t(this.optionRules,function(t,e){r(t)&&void 0!==t.default&&(s[e]=n(t.default,a))}),this.options=i({},o,s,e)},validateOptions:function(e,n){var i=[];return t(n,function(t,n){var s=e[n],a=typeof s;if(!1!==t.required||"undefined"!==a){var u=r(t)?t.type:t;u&&!o(s,u)&&i.push('Invalid type for option "'+n+'" ("'+a+'").'),t.validator&&!t.validator(s)&&i.push('Validation of option "'+n+'" failed.')}}),this.handleValidateOptionsErrors(i)},handleValidateOptionsErrors:function(t){if(t.length)throw new Error(t.join(" "))}};return function(t,e){var r=s(null,t,e);return r.extend=function(t,e){return s(this,t,e)},r}})},function(t,e,r){function n(t,e){var r=h(t)?t:[t],i=[];return e=e||r.map(function(t){return t.id+"@"+t.type}),u(r,function(t){u(t.relationships||{},function(t){u(h(t.data)?t.data:[t.data],function(t){if(t){var r=t.id+"@"+t.type;if(e.indexOf(r)<0){var s=o.find(t.type,t.id);i.push(s),e.push(r),s.relationships&&(i=i.concat(n(s,e)))}}})})}),i}var i=r(1),o=r(3),s=r(0),a=s.assign,u=s.each,h=s.isArray,c=i({initialize:function(t){this.type=t,this.data=o.getCollection(t).slice(),this.setSize(this.data.length)},setSize:function(t){return this.size=t,this},paginate:function(t,e){return t=void 0===t?0:parseInt(t,10),e=void 0===e?this.data.length:parseInt(e,10),this.data=this.data.slice(t,t+e),this},filter:function(t,e){return this.data=this.data.filter(function(r){var n=void 0!==r.attributes[t]?r.attributes[t]:r.relationships&&r.relationships[t]&&r.relationships[t].data;return e(n,r)}),this.size=this.data.length,this},renderForApi:function(){var t=n(this.data);return a({jsonapi:{version:"1.0"},meta:{total:String(this.size)},data:this.data},t.length?{included:t}:void 0)}}),f=i({initialize:function(t){this.type=t,this.data={}},getAttributes:function(){return this.data.attributes},getRelationships:function(){return this.data.relationships},getType:function(){return this.type},getId:function(){return this.data.id},isNew:function(){return!this.getId()},find:function(t){return this.data=o.find(this.getType(),t)||{},this},create:function(t){return a(this.data,{attributes:t.attributes,relationships:t.relationships}),this},edit:function(t){return a(this.data.attributes,t.attributes),a(this.data.relationships,t.relationships),this},save:function(){var t=this.isNew()?o.add(this):o.update(this);return this.find(t)},remove:function(){return o.remove(this),this},isEmpty:function(){return 0===Object.keys(this.data).length&&this.data.constructor===Object},setValidationRules:function(t){return this.validationRules=t,this},validate:function(t){var e=t.attributes||{},r=t.relationships;return this.validationErrors=[],u(this.validationRules||{},function(t,n){var i=r&&r[n],o=void 0!==e[n]?e[n]:i&&r[n].data,s=t.rule;void 0===o||s(o)||this.validationErrors.push({title:t.message,source:{pointer:"/data/"+(i?"relationships":"attributes")+"/"+n}})},this),this},hasValidationErrors:function(){return this.validationErrors&&this.validationErrors.length>0},getValidationErrors:function(){return this.validationErrors},renderForApi:function(){var t=n(this.data);return a({jsonapi:{version:"1.0"},data:this.data},t.length?{included:t}:void 0)}});t.exports={Collection:c,Model:f}},function(t,e,r){function n(t){s&&localStorage.setItem(s,JSON.stringify(t))}var i,o,s,a=r(0),u=a.assign,h=a.findWhere,c=a.each,f="v1";t.exports={getCollection:function(t){return o.resources[t]},find:function(t,e){return h(this.getCollection(t),{id:e})},update:function(t){var e=this.find(t.getType(),t.getId()),r=t.getRelationships();return u(e.attributes,t.getAttributes()),r&&(e.relationships=u({},e.relationships,r)),n(o),e.id},add:function(t){var e=this.getCollection(t.getType()),r=(0===e.length?1:parseInt(e[e.length-1].id)+1).toString(),i=t.getRelationships(),s={id:r,type:t.getType(),attributes:t.getAttributes()};return i&&(s.relationships=i),e.push(s),n(o),r},remove:function(t){var e=this.getCollection(t.getType()),r=this.find(t.getType(),t.getId());return e.splice(e.indexOf(r),1),n(o),t},reset:function(){return n(i),o=JSON.parse(JSON.stringify(i)),this},import:function(t){var e={version:f,resources:{}};if(c(t,function(t,r){e.resources[r]="function"==typeof t.data?t.data(this.random):t.data},this),i=e,s){var r=JSON.parse(localStorage.getItem(s));r&&void 0!==r.version&&f===r.version||n(e),o=JSON.parse(localStorage.getItem(s))}else o=JSON.parse(JSON.stringify(e));return this},setStorageKey:function(t){return s=t.toString(),this},setStorageVersion:function(t){return f=t.toString(),this},clear:function(){return i=null,o=null,s&&localStorage.removeItem(s),this},random:{boolean:function(){return Math.random()>=.5},int:function(t,e){return parseInt(Math.random()*(e-t)+t,10)},id:function(t,e){return String(this.int(t,e))}}}},function(t,e,r){var n=r(5),i=r(1),o=r(10),s=r(3),a=r(11),u=r(0),h=u.assign,c=u.each,f=u.pick,p=i({defaults:{baseApiUrl:"/",storageKey:void 0,storageVersion:void 0,resources:{},getResourceSlug:function(t){return t},delay:void 0},constructor:function(t){this.options=h({},this.defaults,t),t.storageKey&&s.setStorageKey(t.storageKey),t.storageVersion&&s.setStorageVersion(t.storageVersion),s.import(this.options.resources),this.start()},start:function(){var t=this,e=this.options,r=this.pretender=new n,i=function(e,r){t.trigger("request",e);var n;try{n=r(e)}catch(t){n=[500,{"Content-Type":"application/json"},t.toString()]}return t.trigger("response",n),n};return c(e.resources,function(t,n){var s=e.getResourceSlug(n),a=e.baseApiUrl+s,u=o.extend({resourceType:n}),h=new u(f({pagination:e.pagination},t,["filters","validationRules"]));r.get(a,function(t){return i(t,function(){return h.list(t)})},e.delay),r.get(a+"/:id",function(t){return i(t,function(){return h.show(t.params.id,t)})},e.delay),["put","patch","post"].forEach(function(t){r[t](a+"/:id",function(t){return i(t,function(){return h.edit(t.params.id,t)})},e.delay)}),r.post(a,function(t){return i(t,function(){return h.create(t)})},e.delay),r.delete(a+"/:id",function(t){return i(t,function(){return h.delete(t.params.id,t)})},e.delay)}),this},stop:function(){return s.clear(),this.pretender.shutdown(),this},resetData:function(){return s.reset(),this}},{resetData:function(){return s.reset(),this}});a(p.prototype),t.exports=p},function(t,e,r){(function(e){!function(n){"use strict";function i(t){return t.default||t}function o(t){var e=document.createElement("a");e.href=t,e.host||(e.href=e.href);var r=e.pathname;"/"!==r.charAt(0)&&(r="/"+r);var n=e.host;return"80"!==e.port&&"443"!==e.port||(n=e.hostname),{host:n,protocol:e.protocol,search:e.search,hash:e.hash,href:e.href,pathname:r,fullpath:r+(e.search||"")+(e.hash||"")}}function s(){this.verbs={GET:new d,PUT:new d,POST:new d,DELETE:new d,PATCH:new d,HEAD:new d,OPTIONS:new d}}function a(){this._registries={}}function u(){this.hosts=new a;var t=arguments[arguments.length-1],e="object"==typeof t?t:null,r=e&&!1===e.trackRequests,i={push:function(){},length:0};this.handlers=[],this.handledRequests=r?i:[],this.passthroughRequests=r?i:[],this.unhandledRequests=r?i:[],this.requestReferences=[],this.forcePassthrough=e&&!0===e.forcePassthrough,this.disableUnhandled=e&&!0===e.disableUnhandled,this._nativeXMLHttpRequest=n.XMLHttpRequest,this.running=!1;var o={pretender:this};this.ctx=o,n.XMLHttpRequest=h(o),this._fetchProps=["fetch","Headers","Request","Response"],this._fetchProps.forEach(function(t){this["_native"+t]=n[t],n[t]=v[t]},this),this.running=!0;for(var s=e?arguments.length-1:arguments.length,u=0;u<s;u++)this.map(arguments[u])}function h(t){function e(){y.call(this)}function r(e){function r(t,e,r){for(var n=0;n<t.length;n++){var i=t[n];i in e&&(r[i]=e[i])}}function n(t,e,r){t.dispatchEvent(r),t["on"+e]&&t["on"+e](r)}var i=["error","timeout","abort","readystatechange"],o=[],s=["readyState","responseText","responseXML","status","statusText"],a=e._passthroughRequest=new t.pretender._nativeXMLHttpRequest;a.open(e.method,e.url,e.async,e.username,e.password),"arraybuffer"===e.responseType&&(s=["readyState","response","status","statusText"],a.responseType=e.responseType),"onload"in a&&i.push("load"),e.async&&"arraybuffer"!==e.responseType&&(i.push("progress"),o.push("progress"));var u;for(u=0;u<i.length;u++)!function(t){a["on"+t]=function(i){r(s,a,e),n(e,t,i)}}(i[u]);for(u=0;u<o.length;u++)!function(t){a.upload&&(a.upload["on"+t]=function(r){n(e.upload,t,r)})}(o[u]);e.async&&(a.timeout=e.timeout,a.withCredentials=e.withCredentials);for(var h in e.requestHeaders)a.setRequestHeader(h,e.requestHeaders[h]);return a}return e.prototype=Object.create(y.prototype),e.prototype.constructor=e,e.prototype.send=function(){if(!t.pretender.running)throw new Error("You shut down a Pretender instance while there was a pending request. That request just tried to complete. Check to see if you accidentally shut down a pretender earlier than you intended to");if(y.prototype.send.apply(this,arguments),t.pretender.checkPassthrough(this)){var e=r(this);e.send.apply(e,arguments)}else t.pretender.handleRequest(this)},e.prototype._passthroughCheck=function(t,e){return this._passthroughRequest?this._passthroughRequest[t].apply(this._passthroughRequest,e):y.prototype[t].apply(this,e)},e.prototype.abort=function(){return this._passthroughCheck("abort",arguments)},e.prototype.getResponseHeader=function(){return this._passthroughCheck("getResponseHeader",arguments)},e.prototype.getAllResponseHeaders=function(){return this._passthroughCheck("getAllResponseHeaders",arguments)},t.pretender._nativeXMLHttpRequest.prototype._passthroughCheck&&console.warn("You created a second Pretender instance while there was already one running. Running two Pretender servers at once will lead to unexpected results and will be removed entirely in a future major version.Please call .shutdown() on your instances when you no longer need them to respond."),e}function c(t){return function(e,r,n){return this.register(t,e,r,n)}}function f(t,e,r){setTimeout(function(){if(!t.aborted&&!t.status){var n=(new Date).getTime()-e.getTime();t.upload._progress(!0,n,r),t._progress(!0,n,r),f(t,e,r)}},50)}function p(t){return"[object Array]"===Object.prototype.toString.call(t)}var l=void 0!==n&&void 0!==e&&("[object Object]"===Object.prototype.toString.call(e)||"[object process]"===Object.prototype.toString.call(e)),d=l?i(r(7)):n.RouteRecognizer,y=l?i(r(8)):n.FakeXMLHttpRequest,v=l?i(r(9)):n.WHATWGFetch;a.prototype.forURL=function(t){var e=o(t).host,r=this._registries[e];return void 0===r&&(r=this._registries[e]=new s(e)),r.verbs};var g={};u.prototype={get:c("GET"),post:c("POST"),put:c("PUT"),delete:c("DELETE"),patch:c("PATCH"),head:c("HEAD"),options:c("OPTIONS"),map:function(t){t.call(this)},register:function(t,e,r,n){if(!r)throw new Error("The function you tried passing to Pretender to handle "+t+" "+e+" is undefined or missing.");return r.numberOfCalls=0,r.async=n,this.handlers.push(r),this.hosts.forURL(e)[t].add([{path:o(e).fullpath,handler:r}]),r},passthrough:g,checkPassthrough:function(t){var e=t.method.toUpperCase(),r=o(t.url).fullpath,n=this.hosts.forURL(t.url)[e].recognize(r),i=n&&n[0];return!!(i&&i.handler===g||this.forcePassthrough)&&(this.passthroughRequests.push(t),this.passthroughRequest(e,r,t),!0)},handleRequest:function(t){var e=t.method.toUpperCase(),r=t.url,n=this._handlerFor(e,r,t);if(n){n.handler.numberOfCalls++;var i=n.handler.async;this.handledRequests.push(t);var o=this,s=function(n){if(!p(n)){throw new Error("Nothing returned by handler for "+r+". Remember to `return [status, headers, body];` in your route handler.")}var s=n[0],a=o.prepareHeaders(n[1]),u=o.prepareBody(n[2],a);o.handleResponse(t,i,function(){t.respond(s,a,u),o.handledRequest(e,r,t)})};try{var a=n.handler(t);a&&"function"==typeof a.then?a.then(function(t){s(t)}):s(a)}catch(n){this.erroredRequest(e,r,t,n),this.resolve(t)}}else this.disableUnhandled||(this.unhandledRequests.push(t),this.unhandledRequest(e,r,t))},handleResponse:function(t,e,r){var n="function"==typeof e?e():e;if(!1===(n="boolean"==typeof n||"number"==typeof n?n:0))r();else{var i=this;i.requestReferences.push({request:t,callback:r}),!0!==n&&(f(t,new Date,n),setTimeout(function(){i.resolve(t)},n))}},resolve:function(t){for(var e=0,r=this.requestReferences.length;e<r;e++){var n=this.requestReferences[e];if(n.request===t){n.callback(),this.requestReferences.splice(e,1);break}}},requiresManualResolution:function(t,e){var r=this._handlerFor(t.toUpperCase(),e,{});if(!r)return!1;var n=r.handler.async;return"function"==typeof n?!0===n():!0===n},prepareBody:function(t){return t},prepareHeaders:function(t){return t},handledRequest:function(){},passthroughRequest:function(){},unhandledRequest:function(t,e){throw new Error("Pretender intercepted "+t+" "+e+" but no handler was defined for this type of request")},erroredRequest:function(t,e,r,n){throw n.message="Pretender intercepted "+t+" "+e+" but encountered an error: "+n.message,n},_handlerFor:function(t,e,r){var n=this.hosts.forURL(e)[t],i=n.recognize(o(e).fullpath),s=i?i[0]:null;return s&&(r.params=s.params,r.queryParams=i.queryParams),s},shutdown:function(){n.XMLHttpRequest=this._nativeXMLHttpRequest,this._fetchProps.forEach(function(t){n[t]=this["_native"+t]},this),this.ctx.pretender=void 0,this.running=!1}},u.parseURL=o,u.Hosts=a,u.Registry=s,t.exports=u,n.Pretender=u}(self)}).call(e,r(6))},function(t,e){function r(){throw new Error("setTimeout has not been defined")}function n(){throw new Error("clearTimeout has not been defined")}function i(t){if(c===setTimeout)return setTimeout(t,0);if((c===r||!c)&&setTimeout)return c=setTimeout,setTimeout(t,0);try{return c(t,0)}catch(e){try{return c.call(null,t,0)}catch(e){return c.call(this,t,0)}}}function o(t){if(f===clearTimeout)return clearTimeout(t);if((f===n||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(t);try{return f(t)}catch(e){try{return f.call(null,t)}catch(e){return f.call(this,t)}}}function s(){y&&l&&(y=!1,l.length?d=l.concat(d):v=-1,d.length&&a())}function a(){if(!y){var t=i(s);y=!0;for(var e=d.length;e;){for(l=d,d=[];++v<e;)l&&l[v].run();v=-1,e=d.length}l=null,y=!1,o(t)}}function u(t,e){this.fun=t,this.array=e}function h(){}var c,f,p=t.exports={};!function(){try{c="function"==typeof setTimeout?setTimeout:r}catch(t){c=r}try{f="function"==typeof clearTimeout?clearTimeout:n}catch(t){f=n}}();var l,d=[],y=!1,v=-1;p.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];d.push(new u(t,e)),1!==d.length||y||i(a)},u.prototype.run=function(){this.fun.apply(null,this.array)},p.title="browser",p.browser=!0,p.env={},p.argv=[],p.version="",p.versions={},p.on=h,p.addListener=h,p.once=h,p.off=h,p.removeListener=h,p.removeAllListeners=h,p.emit=h,p.prependListener=h,p.prependOnceListener=h,p.listeners=function(t){return[]},p.binding=function(t){throw new Error("process.binding is not supported")},p.cwd=function(){return"/"},p.chdir=function(t){throw new Error("process.chdir is not supported")},p.umask=function(){return 0}},function(t,e,r){"use strict";function n(){var t=m(null);return t.__=void 0,delete t.__,t}function i(t,e,r){function n(n,o){var s=t+n;if(!o)return new b(s,e,r);o(i(s,e,r))}return n}function o(t,e,r){for(var n=0,i=0;i<t.length;i++)n+=t[i].path.length;e=e.substr(n);var o={path:e,handler:r};t.push(o)}function s(t,e,r,n){for(var i=e.routes,a=Object.keys(i),u=0;u<a.length;u++){var h=a[u],c=t.slice();o(c,h,i[h]);var f=e.children[h];f?s(c,f,r,n):r.call(n,c)}}function a(t){return t.split("/").map(u).join("/")}function u(t){return t.length<3||-1===t.indexOf("%")?t:decodeURIComponent(t).replace(R,encodeURIComponent)}function h(t){return encodeURIComponent(t).replace(T,decodeURIComponent)}function c(t,e){if("object"!=typeof t||null===t)throw new Error("You must pass an object as the second argument to `generate`.");if(!O.call(t,e))throw new Error("You must provide param `"+e+"` to `generate`.");var r=t[e],n="string"==typeof r?r:""+r;if(0===n.length)throw new Error("You must provide a param `"+e+"`.");return n}function f(t,e,r){e.length>0&&47===e.charCodeAt(0)&&(e=e.substr(1));for(var n=e.split("/"),i=void 0,o=void 0,s=0;s<n.length;s++){var a=n[s],h=0,c=0;c=""===a?4:58===a.charCodeAt(0)?1:42===a.charCodeAt(0)?2:0,h=2<<c,12&h&&(a=a.slice(1),i=i||[],i.push(a),o=o||[],o.push(0!=(4&h))),14&h&&r[c]++,t.push({type:c,value:u(a)})}return{names:i||D,shouldDecodes:o||D}}function p(t,e,r){return t.char===e&&t.negate===r}function l(t,e){return t.negate?t.char!==e&&-1!==t.char:t.char===e||-1===t.char}function d(t){return t.sort(function(t,e){var r=t.types||[0,0,0],n=r[0],i=r[1],o=r[2],s=e.types||[0,0,0],a=s[0],u=s[1],h=s[2];if(o!==h)return o-h;if(o){if(n!==a)return a-n;if(i!==u)return u-i}return i!==u?i-u:n!==a?a-n:0})}function y(t,e){for(var r=[],n=0,i=t.length;n<i;n++){var o=t[n];r=r.concat(o.match(e))}return r}function v(t,e,r){var n=t.handlers,i=t.regex();if(!i||!n)throw new Error("state not initialized");var o=e.match(i),s=1,a=new N(r);a.length=n.length;for(var u=0;u<n.length;u++){var h=n[u],c=h.names,f=h.shouldDecodes,p=P,l=!1;if(c!==D&&f!==D)for(var d=0;d<c.length;d++){l=!0;var y=c[d],v=o&&o[s++];p===P&&(p={}),L.ENCODE_AND_DECODE_PATH_SEGMENTS&&f[d]?p[y]=v&&decodeURIComponent(v):p[y]=v}a[u]={handler:h.handler,params:p,isDynamic:l}}return a}function g(t){t=t.replace(/\+/gm,"%20");var e;try{e=decodeURIComponent(t)}catch(t){e=""}return e}Object.defineProperty(e,"__esModule",{value:!0});var m=Object.create,b=function(t,e,r){this.path=t,this.matcher=e,this.delegate=r};b.prototype.to=function(t,e){var r=this.delegate;if(r&&r.willAddRoute&&(t=r.willAddRoute(this.matcher.target,t)),this.matcher.add(this.path,t),e){if(0===e.length)throw new Error("You must have an argument in the function passed to `to`");this.matcher.addChild(this.path,t,e,this.delegate)}};var w=function(t){this.routes=n(),this.children=n(),this.target=t};w.prototype.add=function(t,e){this.routes[t]=e},w.prototype.addChild=function(t,e,r,n){var o=new w(e);this.children[t]=o;var s=i(t,o,n);n&&n.contextEntered&&n.contextEntered(e,s),r(s)};var E=function(t,e){var r=new w;t(i("",r,this.delegate)),s([],r,function(t){e?e(this,t):this.add(t)},this)},R=/%|\//g,T=/%(?:2(?:4|6|B|C)|3(?:B|D|A)|40)/g,_=/(\/|\.|\*|\+|\?|\||\(|\)|\[|\]|\{|\}|\\)/g,S=Array.isArray,O=Object.prototype.hasOwnProperty,A=[];A[0]=function(t,e){for(var r=e,n=t.value,i=0;i<n.length;i++){var o=n.charCodeAt(i);r=r.put(o,!1,!1)}return r},A[1]=function(t,e){return e.put(47,!0,!0)},A[2]=function(t,e){return e.put(-1,!1,!0)},A[4]=function(t,e){return e};var C=[];C[0]=function(t){return t.value.replace(_,"\\$1")},C[1]=function(){return"([^/]+)"},C[2]=function(){return"(.+)"},C[4]=function(){return""};var x=[];x[0]=function(t){return t.value},x[1]=function(t,e){var r=c(e,t.value);return L.ENCODE_AND_DECODE_PATH_SEGMENTS?h(r):r},x[2]=function(t,e){return c(e,t.value)},x[4]=function(){return""};var P=Object.freeze({}),D=Object.freeze([]),q=function(t,e,r,n,i){this.states=t,this.id=e,this.char=r,this.negate=n,this.nextStates=i?e:null,this.pattern="",this._regex=void 0,this.handlers=void 0,this.types=void 0};q.prototype.regex=function(){return this._regex||(this._regex=new RegExp(this.pattern)),this._regex},q.prototype.get=function(t,e){var r=this,n=this.nextStates;if(null!==n)if(S(n))for(var i=0;i<n.length;i++){var o=r.states[n[i]];if(p(o,t,e))return o}else{var s=this.states[n];if(p(s,t,e))return s}},q.prototype.put=function(t,e,r){var n;if(n=this.get(t,e))return n;var i=this.states;return n=new q(i,i.length,t,e,r),i[i.length]=n,null==this.nextStates?this.nextStates=n.id:S(this.nextStates)?this.nextStates.push(n.id):this.nextStates=[this.nextStates,n.id],n},q.prototype.match=function(t){var e=this,r=this.nextStates;if(!r)return[];var n=[];if(S(r))for(var i=0;i<r.length;i++){var o=e.states[r[i]];l(o,t)&&n.push(o)}else{var s=this.states[r];l(s,t)&&n.push(s)}return n};var N=function(t){this.length=0,this.queryParams=t||{}};N.prototype.splice=Array.prototype.splice,N.prototype.slice=Array.prototype.slice,N.prototype.push=Array.prototype.push;var L=function(){this.names=n();var t=[],e=new q(t,0,-1,!0,!1);t[0]=e,this.states=t,this.rootState=e};L.prototype.add=function(t,e){for(var r=this.rootState,n="^",i=[0,0,0],o=new Array(t.length),s=[],a=!0,u=0,h=0;h<t.length;h++){for(var c=t[h],p=f(s,c.path,i),l=p.names,d=p.shouldDecodes;u<s.length;u++){var y=s[u];4!==y.type&&(a=!1,r=r.put(47,!1,!1),n+="/",r=A[y.type](y,r),n+=C[y.type](y))}o[h]={handler:c.handler,names:l,shouldDecodes:d}}a&&(r=r.put(47,!1,!1),n+="/"),r.handlers=o,r.pattern=n+"$",r.types=i;var v;"object"==typeof e&&null!==e&&e.as&&(v=e.as),v&&(this.names[v]={segments:s,handlers:o})},L.prototype.handlersFor=function(t){var e=this.names[t];if(!e)throw new Error("There is no route named "+t);for(var r=new Array(e.handlers.length),n=0;n<e.handlers.length;n++){var i=e.handlers[n];r[n]=i}return r},L.prototype.hasRoute=function(t){return!!this.names[t]},L.prototype.generate=function(t,e){var r=this.names[t],n="";if(!r)throw new Error("There is no route named "+t);for(var i=r.segments,o=0;o<i.length;o++){var s=i[o];4!==s.type&&(n+="/",n+=x[s.type](s,e))}return"/"!==n.charAt(0)&&(n="/"+n),e&&e.queryParams&&(n+=this.generateQueryString(e.queryParams)),n},L.prototype.generateQueryString=function(t){var e=[],r=Object.keys(t);r.sort();for(var n=0;n<r.length;n++){var i=r[n],o=t[i];if(null!=o){var s=encodeURIComponent(i);if(S(o))for(var a=0;a<o.length;a++){var u=i+"[]="+encodeURIComponent(o[a]);e.push(u)}else s+="="+encodeURIComponent(o),e.push(s)}}return 0===e.length?"":"?"+e.join("&")},L.prototype.parseQueryString=function(t){for(var e=t.split("&"),r={},n=0;n<e.length;n++){var i=e[n].split("="),o=g(i[0]),s=o.length,a=!1,u=void 0;1===i.length?u="true":(s>2&&"[]"===o.slice(s-2)&&(a=!0,o=o.slice(0,s-2),r[o]||(r[o]=[])),u=i[1]?g(i[1]):""),a?r[o].push(u):r[o]=u}return r},L.prototype.recognize=function(t){var e,r=[this.rootState],n={},i=!1,o=t.indexOf("#");-1!==o&&(t=t.substr(0,o));var s=t.indexOf("?");if(-1!==s){var u=t.substr(s+1,t.length);t=t.substr(0,s),n=this.parseQueryString(u)}"/"!==t.charAt(0)&&(t="/"+t);var h=t;L.ENCODE_AND_DECODE_PATH_SEGMENTS?t=a(t):(t=decodeURI(t),h=decodeURI(h));var c=t.length;c>1&&"/"===t.charAt(c-1)&&(t=t.substr(0,c-1),h=h.substr(0,h.length-1),i=!0);for(var f=0;f<t.length&&(r=y(r,t.charCodeAt(f)),r.length);f++);for(var p=[],l=0;l<r.length;l++)r[l].handlers&&p.push(r[l]);r=d(p);var g=p[0];return g&&g.handlers&&(i&&g.pattern&&"(.+)$"===g.pattern.slice(-5)&&(h+="/"),e=v(g,h,n)),e},L.VERSION="0.3.4",L.ENCODE_AND_DECODE_PATH_SEGMENTS=!0,L.Normalizer={normalizeSegment:u,normalizePath:a,encodePathSegment:h},L.prototype.map=E,e.default=L},function(t,e,r){"use strict";function n(t){var e;if("undefined"!=typeof DOMParser){e=(new DOMParser).parseFromString(t,"text/xml")}else e=new ActiveXObject("Microsoft.XMLDOM"),e.async="false",e.loadXML(t);return e}function i(t,e){e.addEventListener(t,function(r){var n=e["on"+t];n&&"function"==typeof n&&n.call(r.target,r)})}function o(){this._eventListeners={};for(var t=["loadstart","progress","load","abort","loadend"],e=t.length-1;e>=0;e--)i(t[e],this)}function s(){o.call(this),this.readyState=s.UNSENT,this.requestHeaders={},this.requestBody=null,this.status=0,this.statusText="",this.upload=new o}function a(t){if(t.readyState!==s.OPENED)throw new Error("INVALID_STATE_ERR");if(t.sendFlag)throw new Error("INVALID_STATE_ERR")}function u(t){if(t.readyState==s.DONE)throw new Error("Request done")}function h(t){if(t.async&&t.readyState!=s.HEADERS_RECEIVED)throw new Error("No headers received")}function c(t){if("string"!=typeof t){var e=new Error("Attempted to respond to fake XMLHttpRequest with "+t+", which is not a string.");throw e.name="InvalidBodyException",e}}Object.defineProperty(e,"__esModule",{value:!0});/** * Minimal Event interface implementation * * Original implementation by Sven Fuchs: https://gist.github.com/995028 * Modifications and tests by Christian Johansen. * * @author Sven Fuchs (svenfuchs@artweb-design.de) * @author Christian Johansen (christian@cjohansen.no) * @license BSD * * Copyright (c) 2011 Sven Fuchs, Christian Johansen */ var f=function(t,e,r,n){this.type=t,this.bubbles=e,this.cancelable=r,this.target=n};f.prototype={stopPropagation:function(){},preventDefault:function(){this.defaultPrevented=!0}};var p={100:"Continue",101:"Switching Protocols",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",300:"Multiple Choice",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Requested Range Not Satisfiable",417:"Expectation Failed",422:"Unprocessable Entity",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported"},l={"Accept-Charset":!0,"Accept-Encoding":!0,Connection:!0,"Content-Length":!0,Cookie:!0,Cookie2:!0,"Content-Transfer-Encoding":!0,Date:!0,Expect:!0,Host:!0,"Keep-Alive":!0,Referer:!0,TE:!0,Trailer:!0,"Transfer-Encoding":!0,Upgrade:!0,"User-Agent":!0,Via:!0};o.prototype={addEventListener:function(t,e){this._eventListeners[t]=this._eventListeners[t]||[],this._eventListeners[t].push(e)},removeEventListener:function(t,e){for(var r=this._eventListeners[t]||[],n=0,i=r.length;n<i;++n)if(r[n]==e)return r.splice(n,1)},dispatchEvent:function(t){for(var e=t.type,r=this._eventListeners[e]||[],n=0;n<r.length;n++)"function"==typeof r[n]?r[n].call(this,t):r[n].handleEvent(t);return!!t.defaultPrevented},_progress:function(t,e,r){var n=new f("progress");n.target=this,n.lengthComputable=t,n.loaded=e,n.total=r,this.dispatchEvent(n)}},s.prototype=new o,s.UNSENT=0,s.OPENED=1,s.HEADERS_RECEIVED=2,s.LOADING=3,s.DONE=4;var d={UNSENT:0,OPENED:1,HEADERS_RECEIVED:2,LOADING:3,DONE:4,async:!0,withCredentials:!1,open:function(t,e,r,n,i){this.method=t,this.url=e,this.async="boolean"!=typeof r||r,this.username=n,this.password=i,this.responseText=null,this.responseXML=null,this.responseURL=e,this.requestHeaders={},this.sendFlag=!1,this._readyStateChange(s.OPENED)},setRequestHeader:function(t,e){if(a(this),l[t]||/^(Sec-|Proxy-)/.test(t))throw new Error('Refused to set unsafe header "'+t+'"');this.requestHeaders[t]?this.requestHeaders[t]+=","+e:this.requestHeaders[t]=e},send:function(t){if(a(this),!/^(get|head)$/i.test(this.method)){var e=!1;Object.keys(this.requestHeaders).forEach(function(t){"content-type"===t.toLowerCase()&&(e=!0)}),e||(t||"").toString().match("FormData")||(this.requestHeaders["Content-Type"]="text/plain;charset=UTF-8"),this.requestBody=t}this.errorFlag=!1,this.sendFlag=this.async,this._readyStateChange(s.OPENED),"function"==typeof this.onSend&&this.onSend(this),this.dispatchEvent(new f("loadstart",!1,!1,this))},abort:function(){this.aborted=!0,this.responseText=null,this.errorFlag=!0,this.requestHeaders={},this.dispatchEvent(new f("abort",!1,!1,this)),this.readyState>s.UNSENT&&this.sendFlag&&(this._readyStateChange(s.UNSENT),this.sendFlag=!1),"function"==typeof this.onerror&&this.onerror()},getResponseHeader:function(t){if(this.readyState<s.HEADERS_RECEIVED)return null;if(/^Set-Cookie2?$/i.test(t))return null;t=t.toLowerCase();for(var e in this.responseHeaders)if(e.toLowerCase()==t)return this.responseHeaders[e];return null},getAllResponseHeaders:function(){if(this.readyState<s.HEADERS_RECEIVED)return"";var t="";for(var e in this.responseHeaders)this.responseHeaders.hasOwnProperty(e)&&!/^Set-Cookie2?$/i.test(e)&&(t+=e+": "+this.responseHeaders[e]+"\r\n");return t},overrideMimeType:function(t){"string"==typeof t&&(this.forceMimeType=t.toLowerCase())},_readyStateChange:function(t){this.readyState=t,"function"==typeof this.onreadystatechange&&this.onreadystatechange(new f("readystatechange")),this.dispatchEvent(new f("readystatechange")),this.readyState==s.DONE&&this.dispatchEvent(new f("load",!1,!1,this)),this.readyState!=s.UNSENT&&this.readyState!=s.DONE||this.dispatchEvent(new f("loadend",!1,!1,this))},_setResponseHeaders:function(t){this.responseHeaders={};for(var e in t)t.hasOwnProperty(e)&&(this.responseHeaders[e]=t[e]);this.forceMimeType&&(this.responseHeaders["Content-Type"]=this.forceMimeType),this.async?this._readyStateChange(s.HEADERS_RECEIVED):this.readyState=s.HEADERS_RECEIVED},_setResponseBody:function(t){u(this),h(this),c(t);var e=this.chunkSize||10,r=0;this.responseText="";do{this.async&&this._readyStateChange(s.LOADING),this.responseText+=t.substring(r,r+e),r+=e}while(r<t.length);var i=this.getResponseHeader("Content-Type");if(this.responseText&&(!i||/(text\/xml)|(application\/xml)|(\+xml)/.test(i)))try{this.responseXML=n(this.responseText)}catch(t){}this.async?this._readyStateChange(s.DONE):this.readyState=s.DONE},respond:function(t,e,r){this._setResponseHeaders(e||{}),this.status="number"==typeof t?t:200,this.statusText=p[this.status],this._setResponseBody(r||"")}};for(var y in d)s.prototype[y]=d[y];e.default=s},function(t,e,r){"use strict";function n(t){return t&&DataView.prototype.isPrototypeOf(t)}function i(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function s(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return E.iterable&&(e[Symbol.iterator]=function(){return e}),e}function a(t){this.map={},t instanceof a?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function u(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function h(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function c(t){var e=new FileReader,r=h(e);return e.readAsArrayBuffer(t),r}function f(t){var e=new FileReader,r=h(e);return e.readAsText(t),r}function p(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}function l(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function d(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(E.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(E.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(E.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(E.arrayBuffer&&E.blob&&n(t))this._bodyArrayBuffer=l(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!E.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!T(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=l(t)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):E.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},E.blob&&(this.blob=function(){var t=u(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(c)}),this.text=function(){var t=u(this);if(t)return t;if(this._bodyBlob)return f(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(p(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},E.formData&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}function y(t){var e=t.toUpperCase();return _.indexOf(e)>-1?e:t}function v(t,e){e=e||{};var r=e.body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new a(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new a(e.headers)),this.method=y(e.method||this.method||"GET"),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function g(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),i=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(i))}}),e}function m(t){var e=new a;return t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var r=t.split(":"),n=r.shift().trim();if(n){var i=r.join(":").trim();e.append(n,i)}}),e}function b(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new a(e.headers),this.url=e.url||"",this._initBody(t)}function w(t,e){return new Promise(function(r,n){function i(){s.abort()}var o=new v(t,e);if(o.signal&&o.signal.aborted)return n(new O("Aborted","AbortError"));var s=new XMLHttpRequest;s.onload=function(){var t={status:s.status,statusText:s.statusText,headers:m(s.getAllResponseHeaders()||"")};t.url="responseURL"in s?s.responseURL:t.headers.get("X-Request-URL");var e="response"in s?s.response:s.responseText;r(new b(e,t))},s.onerror=function(){n(new TypeError("Network request failed"))},s.ontimeout=function(){n(new TypeError("Network request failed"))},s.onabort=function(){n(new O("Aborted","AbortError"))},s.open(o.method,o.url,!0),"include"===o.credentials?s.withCredentials=!0:"omit"===o.credentials&&(s.withCredentials=!1),"responseType"in s&&E.blob&&(s.responseType="blob"),o.headers.forEach(function(t,e){s.setRequestHeader(e,t)}),o.signal&&(o.signal.addEventListener("abort",i),s.onreadystatechange=function(){4===s.readyState&&o.signal.removeEventListener("abort",i)}),s.send(void 0===o._bodyInit?null:o._bodyInit)})}Object.defineProperty(e,"__esModule",{value:!0}),e.Headers=a,e.Request=v,e.Response=b,r.d(e,"DOMException",function(){return O}),e.fetch=w;var E={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(E.arrayBuffer)var R=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],T=ArrayBuffer.isView||function(t){return t&&R.indexOf(Object.prototype.toString.call(t))>-1};a.prototype.append=function(t,e){t=i(t),e=o(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},a.prototype.delete=function(t){delete this.map[i(t)]},a.prototype.get=function(t){return t=i(t),this.has(t)?this.map[t]:null},a.prototype.has=function(t){return this.map.hasOwnProperty(i(t))},a.prototype.set=function(t,e){this.map[i(t)]=o(e)},a.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},a.prototype.keys=function(){var t=[];return this.forEach(function(e,r){t.push(r)}),s(t)},a.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),s(t)},a.prototype.entries=function(){var t=[];return this.forEach(function(e,r){t.push([r,e])}),s(t)},E.iterable&&(a.prototype[Symbol.iterator]=a.prototype.entries);var _=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},d.call(v.prototype),d.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new a(this.headers),url:this.url})},b.error=function(){var t=new b(null,{status:0,statusText:""});return t.type="error",t};var S=[301,302,303,307,308];b.redirect=function(t,e){if(-1===S.indexOf(e))throw new RangeError("Invalid status code");return new b(null,{status:e,headers:{location:t}})};var O=self.DOMException;try{new O}catch(t){O=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},O.prototype=Object.create(Error.prototype),O.prototype.constructor=O}w.polyfill=!0,self.fetch||(self.fetch=w,self.Headers=a,self.Request=v,self.Response=b)},function(t,e,r){var n=r(1),i=r(2).Collection,o=r(2).Model,s=r(0),a=s.assign,u=s.each;t.exports=n({resourceType:null,assignOptions:!0,defaults:{filters:{},validationRules:{},pagination:{strategy:"offsetBased",offsetKey:"offset",limitKey:"limit"}},getRequestBodyData:function(t){var e,r=t.requestBody;return e="undefined"!=typeof window&&r instanceof window.FormData?JSON.parse(r.get("data")):"string"==typeof r?JSON.parse(r).data:r.data,"string"==typeof e&&(e=JSON.parse(e)),e},list:function(t){var e=new i(this.resourceType),r=t.queryParams;u(this.options.filters,function(t,n){var i=r.filter&&r.filter[n]?r.filter[n]:r["filter["+n+"]"];i&&e.filter(n,function(e,r){return t(e,i,r)})});var n,o,s=this.options.pagination,a=s.limitKey;if("offsetBased"===s.strategy){var h=s.offsetKey;n=r.page?r.page[h]:r["page["+h+"]"],o=r.page?r.page[a]:r["page["+a+"]"]}else if("pageBased"===s.strategy){var c=s.numberKey,f=r.page?r.page[c]:r["page["+c+"]"];o=r.page?r.page[a]:r["page["+a+"]"],o&&(o=parseInt(o,10)||void 0),o&&f&&(n=((parseInt(f,10)||1)-1)*o)}return e.paginate(n,o),this.response(t,e.renderForApi())},show:function(t,e){var r=new o(this.resourceType).find(t);return r.isEmpty()?this.response(e,"",{statusCode:404}):this.response(e,r.renderForApi())},edit:function(t,e){var r=this.getRequestBodyData(e),n=new o(this.resourceType).find(t);return n.setValidationRules(this.options.validationRules).validate(r),n.hasValidationErrors()?this.response(e,{errors:n.getValidationErrors()},{statusCode:409}):(n.edit(r).save(),this.response(e,n.renderForApi()))},create:function(t){var e=this.getRequestBodyData(t),r=new o(this.resourceType).create(e);return r.setValidationRules(this.options.validationRules).validate(e),r.hasValidationErrors()?this.response(t,{errors:r.getValidationErrors()},{statusCode:409}):(r.save(),this.response(t,r.renderForApi()))},delete:function(t,e){return new o(this.resourceType).find(t).remove(),this.response(e,"",{statusCode:204})},response:function(t,e,r){return r=a({statusCode:200,headers:{"Content-Type":"application/json"}},r),[r.statusCode,r.headers,JSON.stringify(e)]}})},function(t,e,r){var n,i,o;!function(r,s){i=[],n=s,void 0!==(o="function"==typeof n?n.apply(e,i):n)&&(t.exports=o)}(0,function(){function t(t,e){if(t instanceof Array)for(var r=0;r<t.length;r++)e(t[r],r);else for(var n in t)t.hasOwnProperty(n)&&e(n,t[n])}function e(t,e){if(Array.prototype.indexOf)return t.indexOf(e);for(var r=0;r<t.length;r++)if(t[r]===e)return r;return-1}function r(t,e,r,n){t._mittyOn=t._mittyOn||[],t._mittyOn.push({listener:e,eventName:r,callback:n})}function n(e,r,n,i){if(e._mittyOn&&e._mittyOn.length){var o={},s=[];r&&(o.listener=r),i&&(o.callback=i),n&&(o.eventName=n),t(e._mittyOn,function(e){var r=!0;t(o,function(t,n){e[t]!==n&&(r=!1)}),!r&&s.push(e)}),e._mittyOn=s}}function i(t,e){if(t._mittyOn)for(var r=0;r<t._mittyOn.length;r++)if(t._mittyOn[r].listener===e)return!0;return!1}function o(r,o,s,a){var u=r._mittyListenTo&&r._mittyListenTo.length>0;o&&u?(n(o,r,s,a),i(o,r)||r._mittyListenTo.splice(e(r._mittyListenTo,o),1)):u&&(t(r._mittyListenTo,function(t){n(t,r)}),r._mittyListenTo=[])}var s={on:function(t,e){return r(this,this,t,e),this},listenTo:function(t,n,i){return r(t,this,n,i),this._mittyListenTo=this._mittyListenTo||[],e(this._mittyListenTo,t)<0&&this._mittyListenTo.push(t),this},off:function(t,e){return n(this,null,t,e),this},stopListening:function(t,e,r){return o(this,t,e,r),this},trigger:function(e,r){return this._mittyOn&&t(this._mittyOn,function(t){t.eventName===e&&t.callback.call(t.listener,r)}),this}};return function(e){return t(s,function(t,r){e[t]=r}),e}})}]);