Comparing version 1.0.1 to 1.0.3
{ | ||
"name": "fakerest", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"homepage": "https://github.com/marmelab/FakeRest", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -1,2 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):"object"==typeof exports?exports.FakeRest=n():t.FakeRest=n()}(this,function(){return function(t){function n(r){if(e[r])return e[r].exports;var i=e[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){"use strict";var r=function(t){return t&&t.__esModule?t["default"]:t};e(3);var i=r(e(1)),o=r(e(2));t.exports={Server:i,Collection:o}},function(t,n,e){"use strict";function r(t){if(!t)return{};var n={},e=t.split("&");return e.map(function(t){if(-1===t.indexOf("="))n[t]=!0;else{var e=t.split("="),r=o(e,2),i=r[0],u=r[1];(0===u.indexOf("[")||0===u.indexOf("{"))&&(u=JSON.parse(u)),n[i.trim()]=u}}),n}var i=function(t){return t&&t.__esModule?t["default"]:t},o=function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t)){for(var e,r=[],i=t[Symbol.iterator]();!(e=i.next()).done&&(r.push(e.value),!n||r.length!==n););return r}throw new TypeError("Invalid attempt to destructure non-iterable instance")},u=function(){function t(t,n){for(var e in n){var r=n[e];r.configurable=!0,r.value&&(r.writable=!0)}Object.defineProperties(t,n)}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}(),c=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")};e(3);var a=i(e(2)),s=function(){function t(){var n=void 0===arguments[0]?"":arguments[0];c(this,t),this.baseUrl=n,this.collections={},this.loggingEnabled=!1,this.requestInterceptors=[],this.responseInterceptors=[]}return u(t,{init:{value:function(t){for(var n in t)this.addCollection(n,new a(t[n]))}},toggleLogging:{value:function(){this.loggingEnabled=!this.loggingEnabled}},addCollection:{value:function(t,n){this.collections[t]=n}},getCollection:{value:function(t){return this.collections[t]}},getCollectionNames:{value:function(){return Object.keys(this.collections)}},addRequestInterceptor:{value:function(t){this.requestInterceptors.push(t)}},addResponseInterceptor:{value:function(t){this.responseInterceptors.push(t)}},getCount:{value:function(t,n){return this.collections[t].getCount(n)}},getAll:{value:function(t,n){return this.collections[t].getAll(n)}},getOne:{value:function(t,n){return this.collections[t].getOne(n)}},addOne:{value:function(t,n){return this.collections[t].addOne(n)}},updateOne:{value:function(t,n,e){return this.collections[t].updateOne(n,e)}},removeOne:{value:function(t,n){return this.collections[t].removeOne(n)}},decode:{value:function(t){if(t.queryString=decodeURIComponent(t.url.slice(t.url.indexOf("?")+1)),t.params=r(t.queryString),t.requestBody)try{t.json=JSON.parse(t.requestBody)}catch(n){}return this.requestInterceptors.reduce(function(t,n){return n(t)},t)}},respond:{value:function(t,n,e){var r=void 0===arguments[3]?200:arguments[3];n||(n={}),n["Content-Type"]||(n["Content-Type"]="application/json");var i={status:r,headers:n,body:t};return i=this.responseInterceptors.reduce(function(t,n){return n(t)},i),this.log(e,i),e.respond(i.status,i.headers,JSON.stringify(i.body))}},log:{value:function(t,n){this.loggingEnabled&&(console.group?(console.groupCollapsed(t.method,t.url,"(FakeRest)"),console.group("request"),console.log(t.method,t.url),console.log("headers",t.requestHeaders),console.log("body ",t.requestBody),console.groupEnd(),console.group("response",n.status),console.log("headers",n.headers),console.log("body ",n.body),console.groupEnd(),console.groupEnd()):(console.log("FakeRest request ",t.method,t.url,"headers",t.requestHeaders,"body",t.requestBody),console.log("FakeRest response",n.status,"headers",n.headers,"body",n.body)))}},handle:{value:function(t){t=this.decode(t);var n=!0,e=!1,r=void 0;try{for(var i,o=this.getCollectionNames()[Symbol.iterator]();!(n=(i=o.next()).done);n=!0){var u=i.value,c=t.url.match(new RegExp("^"+this.baseUrl+"\\/("+u+")(\\/(\\d+))?(\\?.*)?$"));if(c)if(c[2]){var a=c[3];if("GET"==t.method)try{var s=this.getOne(u,a);return this.respond(s,null,t)}catch(f){return t.respond(404)}if("PUT"==t.method)try{var s=this.updateOne(u,a,t.json);return this.respond(s,null,t)}catch(f){return t.respond(404)}if("DELETE"==t.method)try{var s=this.removeOne(u,a);return this.respond(s,null,t)}catch(f){return t.respond(404)}}else{if("GET"==t.method){var l=t.params,h={};for(var p in l)"range"!==p&&(h[p]=l[p]);var d=this.getCount(u,h),v=void 0,g=void 0,y=void 0;if(d>0){v=this.getAll(u,l);var m=l.range?l.range[0]:0,w=l.range?Math.min(v.length-1+m,l.range[1]):v.length-1;g="items "+m+"-"+w+"/"+d,y=v.length==d?200:206}else v=[],g="items */0",y=200;return this.respond(v,{"Content-Range":g},t,y)}if("POST"==t.method){var b=this.addOne(u,t.json),x=this.baseUrl+"/"+u+"/"+b[this.getCollection(u).identifierName];return this.respond(b,{Location:x},t,201)}}}}catch(E){e=!0,r=E}finally{try{!n&&o["return"]&&o["return"]()}finally{if(e)throw r}}}},getHandler:{value:function(){return this.handle.bind(this)}}}),t}();t.exports=s},function(t,n,e){"use strict";function r(t,n){if("function"==typeof n)return t.filter(n);if(n instanceof Object)return t.filter(function(t){for(var e in n)if(t[e]!=n[e])return!1;return!0});throw new Error("Unsupported filter type")}function i(t,n){if("function"==typeof n)return t.sort(n);if("string"==typeof n)return t.sort(function(t,e){return t[n]>e[n]?1:t[n]<e[n]?-1:0});if(Array.isArray(n)){var e=function(){var e=n[0],r="asc"==n[1].toLowerCase()?1:-1;return{v:t.sort(function(t,n){return t[e]>n[e]?r:t[e]<n[e]?-1*r:0})}}();if("object"==typeof e)return e.v}throw new Error("Unsupported sort type")}function o(t,n){if(Array.isArray(n))return t.slice(n[0],void 0!==n[1]?n[1]+1:void 0);throw new Error("Unsupported range type")}var u=function(){function t(t,n){for(var e in n){var r=n[e];r.configurable=!0,r.value&&(r.writable=!0)}Object.defineProperties(t,n)}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}(),c=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")};e(3);var a=function(){function t(){var n=void 0===arguments[0]?[]:arguments[0],e=void 0===arguments[1]?"id":arguments[1];if(c(this,t),!Array.isArray(n))throw new Error("Can't initialize a Collection with anything else than an array of items");this.sequence=0,this.identifierName=e,this.items=[],n.map(this.addOne.bind(this))}return u(t,{getCount:{value:function(t){return this.getAll(t).length}},getAll:{value:function(t){var n=this.items.map(function(t){return t});return t&&(t.filter&&(n=r(n,t.filter)),t.sort&&(n=i(n,t.sort)),t.range&&(n=o(n,t.range))),n}},getIndex:{value:function(t){var n=this;return this.items.findIndex(function(e){return e[n.identifierName]==t})}},getOne:{value:function(t){var n=this.getIndex(t);if(-1===n)throw new Error("No item with identifier "+t);return this.items[n]}},addOne:{value:function(t){var n=t[this.identifierName];if(void 0!==n){if(-1!==this.getIndex(n))throw new Error("An item with the identifier "+n+" already exists");this.sequence=Math.max(this.sequence,n)+1}else t[this.identifierName]=this.sequence++;return this.items.push(t),t}},updateOne:{value:function(t,n){var e=this.getIndex(t);if(-1===e)throw new Error("No item with identifier "+t);for(var r in n)this.items[e][r]=n[r];return this.items[e]}},removeOne:{value:function(t){var n=this.getIndex(t);if(-1===n)throw new Error("No item with identifier "+t);var e=this.items[n];return this.items.splice(n,1),t==this.sequence-1&&this.sequence--,e}}}),t}();t.exports=a},function(t,n,e){t.exports=e(4)},function(t,n,e){(function(t){"use strict";if(t._babelPolyfill)throw new Error("only one instance of babel/polyfill is allowed");t._babelPolyfill=!0,e(6),e(5)}).call(n,function(){return this}())},function(t,n){(function(n){!function(n){"use strict";function e(t,n,e,r){return new u(t,n,e||null,r||[])}function r(t,n,e){try{return{type:"normal",arg:t.call(n,e)}}catch(r){return{type:"throw",arg:r}}}function i(){}function o(){}function u(t,n,e,i){function o(n,i){if(a===w)throw new Error("Generator is already running");if(a===b)return l();for(;;){var o=c.delegate;if(o){var u=r(o.iterator[n],o.iterator,i);if("throw"===u.type){c.delegate=null,n="throw",i=u.arg;continue}n="next",i=h;var s=u.arg;if(!s.done)return a=m,s;c[o.resultName]=s.value,c.next=o.nextLoc,c.delegate=null}if("next"===n){if(a===y&&"undefined"!=typeof i)throw new TypeError("attempt to send "+JSON.stringify(i)+" to newborn generator");a===m?c.sent=i:delete c.sent}else if("throw"===n){if(a===y)throw a=b,i;c.dispatchException(i)&&(n="next",i=h)}else"return"===n&&c.abrupt("return",i);a=w;var u=r(t,e,c);if("normal"===u.type){a=c.done?b:m;var s={value:u.arg,done:c.done};if(u.arg!==x)return s;c.delegate&&"next"===n&&(i=h)}else"throw"===u.type&&(a=b,"next"===n?c.dispatchException(u.arg):i=u.arg)}}var u=n?Object.create(n.prototype):this,c=new s(i),a=y;return u.next=o.bind(u,"next"),u["throw"]=o.bind(u,"throw"),u["return"]=o.bind(u,"return"),u}function c(t){var n={tryLoc:t[0]};1 in t&&(n.catchLoc=t[1]),2 in t&&(n.finallyLoc=t[2],n.afterLoc=t[3]),this.tryEntries.push(n)}function a(t){var n=t.completion||{};n.type="normal",delete n.arg,t.completion=n}function s(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(c,this),this.reset()}function f(t){if(t){var n=t[d];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,r=function i(){for(;++e<t.length;)if(p.call(t,e))return i.value=t[e],i.done=!1,i;return i.value=h,i.done=!0,i};return r.next=r}}return{next:l}}function l(){return{value:h,done:!0}}var h,p=Object.prototype.hasOwnProperty,d="function"==typeof Symbol&&Symbol.iterator||"@@iterator",v="object"==typeof t,g=n.regeneratorRuntime;if(g)return void(v&&(t.exports=g));g=n.regeneratorRuntime=v?t.exports:{},g.wrap=e;var y="suspendedStart",m="suspendedYield",w="executing",b="completed",x={},E=o.prototype=u.prototype;i.prototype=E.constructor=o,o.constructor=i,i.displayName="GeneratorFunction",g.isGeneratorFunction=function(t){var n="function"==typeof t&&t.constructor;return n?n===i||"GeneratorFunction"===(n.displayName||n.name):!1},g.mark=function(t){return t.__proto__=o,t.prototype=Object.create(E),t},g.async=function(t,n,i,o){return new Promise(function(u,c){function a(t){var n=r(this,null,t);if("throw"===n.type)return void c(n.arg);var e=n.arg;e.done?u(e.value):Promise.resolve(e.value).then(f,l)}var s=e(t,n,i,o),f=a.bind(s.next),l=a.bind(s["throw"]);f()})},E[d]=function(){return this},E.toString=function(){return"[object Generator]"},g.keys=function(t){var n=[];for(var e in t)n.push(e);return n.reverse(),function r(){for(;n.length;){var e=n.pop();if(e in t)return r.value=e,r.done=!1,r}return r.done=!0,r}},g.values=f,s.prototype={constructor:s,reset:function(){this.prev=0,this.next=0,this.sent=h,this.done=!1,this.delegate=null,this.tryEntries.forEach(a);for(var t,n=0;p.call(this,t="t"+n)||20>n;++n)this[t]=null},stop:function(){this.done=!0;var t=this.tryEntries[0],n=t.completion;if("throw"===n.type)throw n.arg;return this.rval},dispatchException:function(t){function n(n,r){return o.type="throw",o.arg=t,e.next=n,!!r}if(this.done)throw t;for(var e=this,r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],o=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=p.call(i,"catchLoc"),c=p.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,n){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc<=this.prev&&p.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=n&&n<i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=t,o.arg=n,i?this.next=i.finallyLoc:this.complete(o),x},complete:function(t,n){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=t.arg,this.next="end"):"normal"===t.type&&n&&(this.next=n),x},finish:function(t){for(var n=this.tryEntries.length-1;n>=0;--n){var e=this.tryEntries[n];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc)}},"catch":function(t){for(var n=this.tryEntries.length-1;n>=0;--n){var e=this.tryEntries[n];if(e.tryLoc===t){var r=e.completion;if("throw"===r.type){var i=r.arg;a(e)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,e){return this.delegate={iterator:f(t),resultName:n,nextLoc:e},x}}}("object"==typeof n?n:"object"==typeof window?window:this)}).call(n,function(){return this}())},function(t){!function(n,e,r){"use strict";function i(t){return null!==t&&("object"==typeof t||"function"==typeof t)}function o(t){return"function"==typeof t}function u(t,n,e){t&&!ye(t=e?t:t[mn],Me)&&Ae(t,Me,n)}function c(t){return oe.call(t).slice(8,-1)}function a(t){var n,e;return t==r?t===r?"Undefined":"Null":"string"==typeof(e=(n=jn(t))[Me])?e:c(n)}function s(){for(var t=k(this),n=arguments.length,e=kn(n),r=0,i=De._,o=!1;n>r;)(e[r]=arguments[r++])===i&&(o=!0);return function(){var r,u=this,c=arguments.length,a=0,s=0;if(!o&&!c)return l(t,e,u);if(r=e.slice(),o)for(;n>a;a++)r[a]===i&&(r[a]=arguments[s++]);for(;c>s;)r.push(arguments[s++]);return l(t,r,u)}}function f(t,n,e){if(k(t),~e&&n===r)return t;switch(e){case 1:return function(e){return t.call(n,e)};case 2:return function(e,r){return t.call(n,e,r)};case 3:return function(e,r,i){return t.call(n,e,r,i)}}return function(){return t.apply(n,arguments)}}function l(t,n,e){var i=e===r;switch(0|n.length){case 0:return i?t():t.call(e);case 1:return i?t(n[0]):t.call(e,n[0]);case 2:return i?t(n[0],n[1]):t.call(e,n[0],n[1]);case 3:return i?t(n[0],n[1],n[2]):t.call(e,n[0],n[1],n[2]);case 4:return i?t(n[0],n[1],n[2],n[3]):t.call(e,n[0],n[1],n[2],n[3]);case 5:return i?t(n[0],n[1],n[2],n[3],n[4]):t.call(e,n[0],n[1],n[2],n[3],n[4])}return t.apply(e,n)}function h(t){return me(j(t))}function p(t){return t}function d(){return this}function v(t,n){return ye(t,n)?t[n]:void 0}function g(t){return C(t),ve?de(t).concat(ve(t)):de(t)}function y(t,n){for(var e,r=h(t),i=pe(r),o=i.length,u=0;o>u;)if(r[e=i[u++]]===n)return e}function m(t){return Cn(t).split(",")}function w(t){var n=1==t,e=2==t,i=3==t,o=4==t,u=6==t,c=5==t||u;return function(a){for(var s,l,h=jn(j(this)),p=arguments[1],d=me(h),v=f(a,p,3),g=I(d.length),y=0,m=n?kn(g):e?[]:r;g>y;y++)if((c||y in d)&&(s=d[y],l=v(s,y,h),t))if(n)m[y]=l;else if(l)switch(t){case 3:return!0;case 5:return s;case 6:return y;case 2:m.push(s)}else if(o)return!1;return u?-1:i||o?o:m}}function b(t){return function(n){var e=h(this),r=I(e.length),i=N(arguments[1],r);if(t&&n!=n){for(;r>i;i++)if(E(e[i]))return t||i}else for(;r>i;i++)if((t||i in e)&&e[i]===n)return t||i;return!t&&-1}}function x(t,n){return"function"==typeof t?t:n}function E(t){return t!=t}function O(t){return isNaN(t)?0:ke(t)}function I(t){return t>0?Se(O(t),Ee):0}function N(t,n){var t=O(t);return 0>t?Pe(t+n,0):Se(t,n)}function L(t,n,e){var r=i(n)?function(t){return n[t]}:n;return function(n){return Cn(e?n:this).replace(t,r)}}function P(t){return function(n){var e,i,o=Cn(j(this)),u=O(n),c=o.length;return 0>u||u>=c?t?"":r:(e=o.charCodeAt(u),55296>e||e>56319||u+1===c||(i=o.charCodeAt(u+1))<56320||i>57343?t?o.charAt(u):e:t?o.slice(u,u+2):(e-55296<<10)+(i-56320)+65536)}}function S(t,n,e){if(!t)throw Un(e?n+e:n)}function j(t){if(t==r)throw Un("Function called on null or undefined");return t}function k(t){return S(o(t),t," is not a function!"),t}function C(t){return S(i(t),t," is not an object!"),t}function _(t,n,e){S(t instanceof n,e,": use the 'new' operator!")}function A(t,n){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:n}}function F(t,n,e){return t[n]=e,t}function T(t){return Ce?function(n,e,r){return le(n,e,A(t,r))}:F}function q(t){return dn+"("+t+")_"+(++_e+je())[bn](36)}function R(t,n){return Mn&&Mn[t]||(n?Mn:Te)(dn+re+t)}function M(t,n){for(var e in n)Ae(t,e,n[e]);return t}function G(t){!Ce||!e&&ie(t)||le(t,Ge,{configurable:!0,get:d})}function U(t,r,i){var u,c,a,s,l=t&$e,h=l?n:t&Be?n[r]:(n[r]||te)[mn],p=l?ze:ze[r]||(ze[r]={});l&&(i=r);for(u in i)c=!(t&Je)&&h&&u in h&&(!o(h[u])||ie(h[u])),a=(c?h:i)[u],e||!l||o(h[u])?t&Ye&&c?s=f(a,n):t&He&&!e&&h[u]==a?(s=function(t){return this instanceof a?new a(t):a(t)},s[mn]=a[mn]):s=t&Ve&&o(a)?f(ue,a):a:s=i[u],e&&h&&!c&&(l?h[u]=a:delete h[u]&&Ae(h,u,a)),p[u]!=a&&Ae(p,u,s)}function z(t,n){Ae(t,tn,n),Nn in Zn&&Ae(t,Nn,n)}function D(t,n,e,r){t[mn]=ae(r||tr,{next:A(1,e)}),u(t,n+" Iterator")}function W(t,n,r,i){var o=t[mn],c=v(o,tn)||v(o,Nn)||i&&v(o,i)||r;if(e&&(z(o,c),c!==r)){var a=se(c.call(new t));u(a,n+" Iterator",!0),ye(o,Nn)&&z(a,d)}return Ze[n]=c,Ze[n+" Iterator"]=d,c}function J(t,n,e,r,i,o){function u(t){return function(){return new e(this,t)}}D(e,n,r);var c=u(Ke+Qe),a=u(Qe);i==Qe?a=W(t,n,a,"values"):c=W(t,n,c,"entries"),i&&U(Ve+Je*nr,n,{entries:c,keys:o?a:u(Ke),values:a})}function $(t,n){return{value:n,done:!!t}}function B(t){var e=jn(t),r=n[dn],i=(r&&r[In]||Nn)in e;return i||tn in e||ye(Ze,a(e))}function V(t){var e=n[dn],r=t[e&&e[In]||Nn],i=r||t[tn]||Ze[a(t)];return C(i.call(t))}function Y(t,n,e){return e?l(t,n):t(n)}function H(t){var n=!0,e={next:function(){throw 1},"return":function(){n=!1}};e[tn]=d;try{t(e)}catch(r){}return n}function X(t){var n=t["return"];n!==r&&n.call(t)}function K(t,n){try{t(n)}catch(e){throw X(n),e}}function Q(t,n,e,r){K(function(t){for(var i,o=f(e,r,n?2:1);!(i=t.next()).done;)if(Y(o,i.value,n)===!1)return X(t)},V(t))}var Z,tn,nn,en="Object",rn="Function",on="Array",un="String",cn="Number",an="RegExp",sn="Date",fn="Map",ln="Set",hn="WeakMap",pn="WeakSet",dn="Symbol",vn="Promise",gn="Math",yn="Arguments",mn="prototype",wn="constructor",bn="toString",xn=bn+"Tag",En="hasOwnProperty",On="forEach",In="iterator",Nn="@@"+In,Ln="process",Pn="createElement",Sn=n[rn],jn=n[en],kn=n[on],Cn=n[un],_n=n[cn],An=n[an],Fn=(n[sn],n[fn]),Tn=n[ln],qn=n[hn],Rn=n[pn],Mn=n[dn],Gn=n[gn],Un=n.TypeError,zn=n.RangeError,Dn=n.setTimeout,Wn=n.setImmediate,Jn=n.clearImmediate,$n=n.parseInt,Bn=n.isFinite,Vn=n[Ln],Yn=Vn&&Vn.nextTick,Hn=n.document,Xn=Hn&&Hn.documentElement,Kn=(n.navigator,n.define),Qn=n.console||{},Zn=kn[mn],te=jn[mn],ne=Sn[mn],ee=1/0,re=".",ie=f(/./.test,/\[native code\]\s*\}\s*$/,1),oe=te[bn],ue=ne.call,ce=ne.apply,ae=jn.create,se=jn.getPrototypeOf,fe=jn.setPrototypeOf,le=jn.defineProperty,he=(jn.defineProperties,jn.getOwnPropertyDescriptor),pe=jn.keys,de=jn.getOwnPropertyNames,ve=jn.getOwnPropertySymbols,ge=jn.isFrozen,ye=f(ue,te[En],2),me=jn,we=jn.assign||function(t){for(var n=jn(j(t)),e=arguments.length,r=1;e>r;)for(var i,o=me(arguments[r++]),u=pe(o),c=u.length,a=0;c>a;)n[i=u[a++]]=o[i];return n},be=Zn.push,xe=(Zn.unshift,Zn.slice,Zn.splice,Zn.indexOf,Zn[On]),Ee=9007199254740991,Oe=Gn.pow,Ie=Gn.abs,Ne=Gn.ceil,Le=Gn.floor,Pe=Gn.max,Se=Gn.min,je=Gn.random,ke=Gn.trunc||function(t){return(t>0?Le:Ne)(t)},Ce=!!function(){try{return 2==le({},"a",{get:function(){return 2}}).a}catch(t){}}(),_e=0,Ae=T(1),Fe=Mn?F:Ae,Te=Mn||q,qe=R("unscopables"),Re=Zn[qe]||{},Me=R(xn),Ge=R("species"),Ue=c(Vn)==Ln,ze={},De=e?n:ze,We=n.core,Je=1,$e=2,Be=4,Ve=8,Ye=16,He=32;"undefined"!=typeof t&&t.exports?t.exports=ze:o(Kn)&&Kn.amd?Kn(function(){return ze}):nn=!0,(nn||e)&&(ze.noConflict=function(){return n.core=We,ze},n.core=ze),tn=R(In);var Xe=Te("iter"),Ke=1,Qe=2,Ze={},tr={},nr="keys"in Zn&&!("next"in[].keys());z(tr,d),!function(t,e,r,i){ie(Mn)||(Mn=function(n){S(!(this instanceof Mn),dn+" is not a "+wn);var e=q(n),o=Fe(ae(Mn[mn]),t,e);return r[e]=o,Ce&&i&&le(te,e,{configurable:!0,set:function(t){Ae(this,e,t)}}),o},Ae(Mn[mn],bn,function(){return this[t]})),U($e+He,{Symbol:Mn});var o={"for":function(t){return ye(e,t+="")?e[t]:e[t]=Mn(t)},iterator:tn||R(In),keyFor:s.call(y,e),species:Ge,toStringTag:Me=R(xn,!0),unscopables:qe,pure:Te,set:Fe,useSetter:function(){i=!0},useSimple:function(){i=!1}};xe.call(m("hasInstance,isConcatSpreadable,match,replace,search,split,toPrimitive"),function(t){o[t]=R(t)}),U(Be,dn,o),u(Mn,dn),U(Be+Je*!ie(Mn),en,{getOwnPropertyNames:function(t){for(var n,e=de(h(t)),i=[],o=0;e.length>o;)ye(r,n=e[o++])||i.push(n);return i},getOwnPropertySymbols:function(t){for(var n,e=de(h(t)),i=[],o=0;e.length>o;)ye(r,n=e[o++])&&i.push(r[n]);return i}}),u(Gn,gn,!0),u(n.JSON,"JSON",!0)}(Te("tag"),{},{},!0),!function(){var t={assign:we,is:function(t,n){return t===n?0!==t||1/t===1/n:t!=t&&n!=n}};"__proto__"in te&&function(n,e){try{e=f(ue,he(te,"__proto__").set,2),e({},Zn)}catch(r){n=!0}t.setPrototypeOf=fe=fe||function(t,r){return C(t),S(null===r||i(r),r,": can't set as prototype!"),n?t.__proto__=r:e(t,r),t}}(),U(Be,en,t)}(),!function(t){t[Me]=re,c(t)!=re&&Ae(te,bn,function(){return"[object "+a(this)+"]"})}({}),!function(){function t(t,n){var e=jn[t],r=ze[en][t],o=0,u={};if(!r||ie(r)){u[t]=1==n?function(t){return i(t)?e(t):t}:2==n?function(t){return i(t)?e(t):!0}:3==n?function(t){return i(t)?e(t):!1}:4==n?function(t,n){return e(h(t),n)}:function(t){return e(h(t))};try{e(re)}catch(c){o=1}U(Be+Je*o,en,u)}}t("freeze",1),t("seal",1),t("preventExtensions",1),t("isFrozen",2),t("isSealed",2),t("isExtensible",3),t("getOwnPropertyDescriptor",4),t("getPrototypeOf"),t("keys"),t("getOwnPropertyNames")}(),!function(t){t in ne||Ce&&le(ne,t,{configurable:!0,get:function(){var n=Cn(this).match(/^\s*function ([^ (]*)/),e=n?n[1]:"";return ye(this,t)||le(this,t,A(5,e)),e},set:function(n){ye(this,t)||le(this,t,A(0,n))}})}("name"),_n("0o1")&&_n("0b1")||function(t,e){function r(t){if(i(t)&&(t=u(t)),"string"==typeof t&&t.length>2&&48==t.charCodeAt(0)){var n=!1;switch(t.charCodeAt(1)){case 66:case 98:n=!0;case 79:case 111:return $n(t.slice(2),n?2:8)}}return+t}function u(t){var n,e;if(o(n=t.valueOf)&&!i(e=n.call(t)))return e;if(o(n=t[bn])&&!i(e=n.call(t)))return e;throw Un("Can't convert object to number")}_n=function c(n){return this instanceof c?new t(r(n)):r(n)},xe.call(Ce?de(t):m("MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY"),function(n){n in _n||le(_n,n,he(t,n))}),_n[mn]=e,e[wn]=_n,Ae(n,cn,_n)}(_n,_n[mn]),!function(t){U(Be,cn,{EPSILON:Oe(2,-52),isFinite:function(t){return"number"==typeof t&&Bn(t)},isInteger:t,isNaN:E,isSafeInteger:function(n){return t(n)&&Ie(n)<=Ee},MAX_SAFE_INTEGER:Ee,MIN_SAFE_INTEGER:-Ee,parseFloat:parseFloat,parseInt:$n})}(_n.isInteger||function(t){return!i(t)&&Bn(t)&&Le(t)===t}),!function(){function t(n){return Bn(n=+n)&&0!=n?0>n?-t(-n):i(n+o(n*n+1)):n}function n(t){return 0==(t=+t)?t:t>-1e-6&&1e-6>t?t+t*t/2:r(t)-1}var e=Gn.E,r=Gn.exp,i=Gn.log,o=Gn.sqrt,u=Gn.sign||function(t){return 0==(t=+t)||t!=t?t:0>t?-1:1};U(Be,gn,{acosh:function(t){return(t=+t)<1?0/0:Bn(t)?i(t/e+o(t+1)*o(t-1)/e)+1:t},asinh:t,atanh:function(t){return 0==(t=+t)?t:i((1+t)/(1-t))/2},cbrt:function(t){return u(t=+t)*Oe(Ie(t),1/3)},clz32:function(t){return(t>>>=0)?32-t[bn](2).length:32},cosh:function(t){return(r(t=+t)+r(-t))/2},expm1:n,fround:function(t){return new Float32Array([t])[0]},hypot:function(){for(var t,n=0,e=arguments.length,r=e,i=kn(e),u=-ee;e--;){if(t=i[e]=+arguments[e],t==ee||t==-ee)return ee;t>u&&(u=t)}for(u=t||1;r--;)n+=Oe(i[r]/u,2);return u*o(n)},imul:function(t,n){var e=65535,r=+t,i=+n,o=e&r,u=e&i;return 0|o*u+((e&r>>>16)*u+o*(e&i>>>16)<<16>>>0)},log1p:function(t){return(t=+t)>-1e-8&&1e-8>t?t-t*t/2:i(1+t)},log10:function(t){return i(t)/Gn.LN10},log2:function(t){return i(t)/Gn.LN2},sign:u,sinh:function(t){return Ie(t=+t)<1?(n(t)-n(-t))/2:(r(t-1)-r(-t-1))*(e/2)},tanh:function(t){var e=n(t=+t),i=n(-t);return e==ee?1:i==ee?-1:(e-i)/(r(t)+r(-t))},trunc:ke})}(),!function(t){function n(t){if(c(t)==an)throw Un()}U(Be,un,{fromCodePoint:function(){for(var n,e=[],r=arguments.length,i=0;r>i;){if(n=+arguments[i++],N(n,1114111)!==n)throw zn(n+" is not a valid code point");e.push(65536>n?t(n):t(((n-=65536)>>10)+55296,n%1024+56320))}return e.join("")},raw:function(t){for(var n=h(t.raw),e=I(n.length),r=arguments.length,i=[],o=0;e>o;)i.push(Cn(n[o++])),r>o&&i.push(Cn(arguments[o]));return i.join("")}}),U(Ve,un,{codePointAt:P(!1),endsWith:function(t){n(t);var e=Cn(j(this)),i=arguments[1],o=I(e.length),u=i===r?o:Se(I(i),o);return t+="",e.slice(u-t.length,u)===t},includes:function(t){return n(t),!!~Cn(j(this)).indexOf(t,arguments[1])},repeat:function(t){var n=Cn(j(this)),e="",r=O(t);if(0>r||r==ee)throw zn("Count can't be negative");for(;r>0;(r>>>=1)&&(n+=n))1&r&&(e+=n);return e},startsWith:function(t){n(t);var e=Cn(j(this)),r=I(Se(arguments[1],e.length));return t+="",e.slice(r,r+t.length)===t}})}(Cn.fromCharCode),!function(){U(Be+Je*H(kn.from),on,{from:function(t){var n,e,i,o=jn(j(t)),u=arguments[1],c=u!==r,a=c?f(u,arguments[2],2):r,s=0;if(B(o))e=new(x(this,kn)),K(function(t){for(;!(i=t.next()).done;s++)e[s]=c?a(i.value,s):i.value},V(o));else for(e=new(x(this,kn))(n=I(o.length));n>s;s++)e[s]=c?a(o[s],s):o[s];return e.length=s,e}}),U(Be,on,{of:function(){for(var t=0,n=arguments.length,e=new(x(this,kn))(n);n>t;)e[t]=arguments[t++];return e.length=n,e}}),G(kn)}(),!function(){U(Ve,on,{copyWithin:function(t,n){var e=jn(j(this)),i=I(e.length),o=N(t,i),u=N(n,i),c=arguments[2],a=c===r?i:N(c,i),s=Se(a-u,i-o),f=1;for(o>u&&u+s>o&&(f=-1,u=u+s-1,o=o+s-1);s-->0;)u in e?e[o]=e[u]:delete e[o],o+=f,u+=f;return e},fill:function(t){for(var n=jn(j(this)),e=I(n.length),i=N(arguments[1],e),o=arguments[2],u=o===r?e:N(o,e);u>i;)n[i++]=t;return n},find:w(5),findIndex:w(6)}),e&&(xe.call(m("find,findIndex,fill,copyWithin,entries,keys,values"),function(t){Re[t]=!0}),qe in Zn||Ae(Zn,qe,Re))}(),!function(t){J(kn,on,function(t,n){Fe(this,Xe,{o:h(t),i:0,k:n})},function(){var t=this[Xe],n=t.o,e=t.k,i=t.i++;return!n||i>=n.length?(t.o=r,$(1)):e==Ke?$(0,i):e==Qe?$(0,n[i]):$(0,[i,n[i]])},Qe),Ze[yn]=Ze[on],J(Cn,un,function(t){Fe(this,Xe,{o:Cn(t),i:0})},function(){var n,e=this[Xe],r=e.o,i=e.i;return i>=r.length?$(1):(n=t.call(r,i),e.i+=n.length,$(0,n))})}(P(!0)),Ce&&!function(t,e){(function(){try{return"/a/i"==An(/a/g,"i")}catch(t){}})()||(An=function(t,n){return new e(c(t)==an&&n!==r?t.source:t,n)},xe.call(de(e),function(t){t in An||le(An,t,{configurable:!0,get:function(){return e[t]},set:function(n){e[t]=n}})}),t[wn]=An,An[mn]=t,Ae(n,an,An)),"g"!=/./g.flags&&le(t,"flags",{configurable:!0,get:L(/^.*\/(\w*)$/,"$1")}),G(An)}(An[mn],An),o(Wn)&&o(Jn)||function(t){function e(t){if(ye(v,t)){var n=v[t];delete v[t],n()}}function r(t){e(t.data)}var i,u,c,a=n.postMessage,h=n.addEventListener,p=n.MessageChannel,d=0,v={};Wn=function(t){for(var n=[],e=1;arguments.length>e;)n.push(arguments[e++]);return v[++d]=function(){l(o(t)?t:Sn(t),n)},i(d),d},Jn=function(t){delete v[t]},Ue?i=function(t){Yn(s.call(e,t))}:h&&o(a)&&!n.importScripts?(i=function(t){a(t,"*")},h("message",r,!1)):o(p)?(u=new p,c=u.port2,u.port1.onmessage=r,i=f(c.postMessage,c,1)):i=Hn&&t in Hn[Pn]("script")?function(n){Xn.appendChild(Hn[Pn]("script"))[t]=function(){Xn.removeChild(this),e(n)}}:function(t){Dn(e,0,t)}}("onreadystatechange"),U($e+Ye,{setImmediate:Wn,clearImmediate:Jn}),!function(t,n){o(t)&&o(t.resolve)&&t.resolve(n=new t(function(){}))==n||function(n,e){function u(t){var n;return i(t)&&(n=t.then),o(n)?n:!1}function c(t){var n,r=t[e],i=r.c,o=0;if(r.h)return!0;for(;i.length>o;)if(n=i[o++],n.fail||c(n.P))return!0}function a(t,e){var r=t.c;(e||r.length)&&n(function(){var n=t.p,i=t.v,a=1==t.s,s=0;if(e&&!c(n))Dn(function(){c(n)||(Ue?!Vn.emit("unhandledRejection",i,n):o(Qn.error)&&Qn.error("Unhandled promise rejection",i))},1e3);else for(;r.length>s;)!function(n){var e,r,o=a?n.ok:n.fail;try{o?(a||(t.h=!0),e=o===!0?i:o(i),e===n.P?n.rej(Un(vn+"-chain cycle")):(r=u(e))?r.call(e,n.res,n.rej):n.res(e)):n.rej(i)}catch(c){n.rej(c)}}(r[s++]);r.length=0})}function s(t){var n,e,r=this;if(!r.d){r.d=!0,r=r.r||r;try{(n=u(t))?(e={r:r,d:!1},n.call(t,f(s,e,1),f(l,e,1))):(r.v=t,r.s=1,a(r))}catch(i){l.call(e||{r:r,d:!1},i)}}}function l(t){var n=this;n.d||(n.d=!0,n=n.r||n,n.v=t,n.s=2,a(n,!0))}function h(t){var n=C(t)[Ge];return n!=r?n:t}t=function(n){k(n),_(this,t,vn);var i={p:this,c:[],s:0,d:!1,v:r,h:!1};Ae(this,e,i);try{n(f(s,i,1),f(l,i,1))}catch(o){l.call(i,o)}},M(t[mn],{then:function(n,i){var u=C(C(this)[wn])[Ge],c={ok:o(n)?n:!0,fail:o(i)?i:!1},s=c.P=new(u!=r?u:t)(function(t,n){c.res=k(t),c.rej=k(n)}),f=this[e];return f.c.push(c),f.s&&a(f),s},"catch":function(t){return this.then(r,t)}}),M(t,{all:function(t){var n=h(this),e=[];return new n(function(r,i){Q(t,!1,be,e);var o=e.length,u=kn(o);o?xe.call(e,function(t,e){n.resolve(t).then(function(t){u[e]=t,--o||r(u)},i)}):r(u)})},race:function(t){var n=h(this);return new n(function(e,r){Q(t,!1,function(t){n.resolve(t).then(e,r)})})},reject:function(t){return new(h(this))(function(n,e){e(t)})},resolve:function(t){return i(t)&&e in t&&se(t)===this[mn]?t:new(h(this))(function(n){n(t)})}})}(Yn||Wn,Te("record")),u(t,vn),G(t),U($e+Je*!ie(t),{Promise:t})}(n[vn]),!function(){function t(t,n,i,o,c,a){function s(t,n){return n!=r&&Q(n,c,t[p],t),t}function f(t,n){var r=d[t];e&&(d[t]=function(t,e){var i=r.call(this,0===t?0:t,e);return n?this:i})}var p=c?"set":"add",d=t&&t[mn],m={};if(ie(t)&&(a||!nr&&ye(d,On)&&ye(d,"entries"))){var b,x=t,E=new t,O=E[p](a?{}:-0,1);H(function(n){new t(n)})&&(t=function(e){return _(this,t,n),s(new x,e)},t[mn]=d,e&&(d[wn]=t)),a||E[On](function(t,n){b=1/n===-ee}),b&&(f("delete"),f("has"),c&&f("get")),(b||O!==E)&&f(p,!0)}else t=a?function(e){_(this,t,n),Fe(this,l,w++),s(this,e)}:function(e){var i=this;_(i,t,n),Fe(i,h,ae(null)),Fe(i,y,0),Fe(i,v,r),Fe(i,g,r),s(i,e)},M(M(t[mn],i),o),a||!Ce||le(t[mn],"size",{get:function(){return j(this[y])}});return u(t,n),G(t),m[n]=t,U($e+He+Je*!ie(t),m),a||J(t,n,function(t,n){Fe(this,Xe,{o:t,k:n})},function(){for(var t=this[Xe],n=t.k,e=t.l;e&&e.r;)e=e.p;return t.o&&(t.l=e=e?e.n:t.o[g])?n==Ke?$(0,e.k):n==Qe?$(0,e.v):$(0,[e.k,e.v]):(t.o=r,$(1))},c?Ke+Qe:Qe,!c),t}function n(t,n){if(!i(t))return("string"==typeof t?"S":"P")+t;if(ge(t))return"F";if(!ye(t,l)){if(!n)return"E";Ae(t,l,++w)}return"O"+t[l]}function o(t,e){var r,i=n(e);if("F"!=i)return t[h][i];for(r=t[g];r;r=r.n)if(r.k==e)return r}function c(t,e,i){var u,c,a=o(t,e);return a?a.v=i:(t[v]=a={i:c=n(e,!0),k:e,v:i,p:u=t[v],n:r,r:!1},t[g]||(t[g]=a),u&&(u.n=a),t[y]++,"F"!=c&&(t[h][c]=a)),t}function a(t,n,e){return ge(C(n))?s(t).set(n,e):(ye(n,p)||Ae(n,p,{}),n[p][t[l]]=e),t}function s(t){return t[d]||Ae(t,d,new Fn)[d]}var l=Te("uid"),h=Te("O1"),p=Te("weak"),d=Te("leak"),v=Te("last"),g=Te("first"),y=Ce?Te("size"):"size",w=0,b={},x={clear:function(){for(var t=this,n=t[h],e=t[g];e;e=e.n)e.r=!0,e.p&&(e.p=e.p.n=r),delete n[e.i];t[g]=t[v]=r,t[y]=0},"delete":function(t){var n=this,e=o(n,t);if(e){var r=e.n,i=e.p;delete n[h][e.i],e.r=!0,i&&(i.n=r),r&&(r.p=i),n[g]==e&&(n[g]=r),n[v]==e&&(n[v]=i),n[y]--}return!!e},forEach:function(t){for(var n,e=f(t,arguments[1],3);n=n?n.n:this[g];)for(e(n.v,n.k,this);n&&n.r;)n=n.p},has:function(t){return!!o(this,t)}};Fn=t(Fn,fn,{get:function(t){var n=o(this,t);return n&&n.v},set:function(t,n){return c(this,0===t?0:t,n)}},x,!0),Tn=t(Tn,ln,{add:function(t){return c(this,t=0===t?0:t,t)}},x);var E={"delete":function(t){return i(t)?ge(t)?s(this)["delete"](t):ye(t,p)&&ye(t[p],this[l])&&delete t[p][this[l]]:!1},has:function(t){return i(t)?ge(t)?s(this).has(t):ye(t,p)&&ye(t[p],this[l]):!1}};qn=t(qn,hn,{get:function(t){if(i(t)){if(ge(t))return s(this).get(t);if(ye(t,p))return t[p][this[l]]}},set:function(t,n){return a(this,t,n)}},E,!0,!0),e&&7!=(new qn).set(jn.freeze(b),7).get(b)&&xe.call(m("delete,has,get,set"),function(t){var n=qn[mn][t];qn[mn][t]=function(e,r){if(i(e)&&ge(e)){var o=s(this)[t](e,r);return"set"==t?this:o}return n.call(this,e,r)}}),Rn=t(Rn,pn,{add:function(t){return a(this,t,!0)}},E,!1,!0)}(),!function(){function t(t){var n,e=[];for(n in t)e.push(n);Fe(this,Xe,{o:t,a:e,i:0})}function n(t){return function(n){C(n);try{return t.apply(r,arguments),!0}catch(e){return!1}}}function e(t,n){var o,u=arguments.length<3?t:arguments[2],c=he(C(t),n);return c?ye(c,"value")?c.value:c.get===r?r:c.get.call(u):i(o=se(t))?e(o,n,u):r | ||
}function o(t,n,e){var u,c,a=arguments.length<4?t:arguments[3],s=he(C(t),n);if(!s){if(i(c=se(t)))return o(c,n,e,a);s=A(0)}return ye(s,"value")?s.writable!==!1&&i(a)?(u=he(a,n)||A(0),u.value=e,le(a,n,u),!0):!1:s.set===r?!1:(s.set.call(a,e),!0)}D(t,en,function(){var t,n=this[Xe],e=n.a;do if(n.i>=e.length)return $(1);while(!((t=e[n.i++])in n.o));return $(0,t)});var u=jn.isExtensible||p,c={apply:f(ue,ce,3),construct:function(t,n){var e=k(arguments.length<3?t:arguments[2])[mn],r=ae(i(e)?e:te),o=ce.call(t,r,n);return i(o)?o:r},defineProperty:n(le),deleteProperty:function(t,n){var e=he(C(t),n);return e&&!e.configurable?!1:delete t[n]},enumerate:function(n){return new t(C(n))},get:e,getOwnPropertyDescriptor:function(t,n){return he(C(t),n)},getPrototypeOf:function(t){return se(C(t))},has:function(t,n){return n in t},isExtensible:function(t){return!!u(C(t))},ownKeys:g,preventExtensions:n(jn.preventExtensions||p),set:o};fe&&(c.setPrototypeOf=function(t,n){return fe(C(t),n),!0}),U($e,{Reflect:{}}),U(Be,"Reflect",c)}(),!function(){function t(t){return function(n){var e,r=h(n),i=pe(n),o=i.length,u=0,c=kn(o);if(t)for(;o>u;)c[u]=[e=i[u++],r[e]];else for(;o>u;)c[u]=r[i[u++]];return c}}U(Ve,on,{includes:b(!0)}),U(Ve,un,{at:P(!0)}),U(Be,en,{getOwnPropertyDescriptors:function(t){var n=h(t),e={};return xe.call(g(n),function(t){le(e,t,A(0,he(n,t)))}),e},values:t(!1),entries:t(!0)}),U(Be,an,{escape:L(/([\\\-[\]{}()*+?.,^$|])/g,"\\$1",!0)})}(),!function(t){function n(t){if(t){var n=t[mn];Ae(n,Z,n.get),Ae(n,e,n.set),Ae(n,r,n["delete"])}}Z=R(t+"Get",!0);var e=R(t+ln,!0),r=R(t+"Delete",!0);U(Be,dn,{referenceGet:Z,referenceSet:e,referenceDelete:r}),Ae(ne,Z,d),n(Fn),n(qn)}("reference"),!function(t){function n(n,e){xe.call(m(n),function(n){n in Zn&&(t[n]=f(ue,Zn[n],e))})}n("pop,reverse,shift,keys,values,entries",1),n("indexOf,every,some,forEach,map,filter,find,findIndex,includes",3),n("join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill,turn"),U(Be,on,t)}({}),!function(t){!e||!t||tn in t[mn]||Ae(t[mn],tn,Ze[on]),Ze.NodeList=Ze[on]}(n.NodeList)}("undefined"!=typeof self&&self.Math===Math?self:Function("return this")(),!0)}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):"object"==typeof exports?exports.FakeRest=t():e.FakeRest=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";var r=n(4)["default"],o=n(3)["default"];r(t,"__esModule",{value:!0});var i=n(16),u=o(i),s=n(2),a=o(s);t["default"]={Server:u["default"],Collection:a["default"]},e.exports=t["default"]},function(e,t,n){n(26);var r=n(19),o=n(23).Iterators,i=n(27)("iterator"),u=o.Array,s=r.g.NodeList;!r.FW||!s||i in s.prototype||r.hide(s.prototype,i,u),o.NodeList=u},function(e,t,n){"use strict";function r(e,t){if("function"==typeof t)return e.filter(t);if(t instanceof Object)return e.filter(function(e){for(var n in t)if(e[n]!=t[n])return!1;return!0});throw new Error("Unsupported filter type")}function o(e,t){if("function"==typeof t)return e.sort(t);if("string"==typeof t)return e.sort(function(e,n){return e[t]>n[t]?1:e[t]<n[t]?-1:0});if(Array.isArray(t)){var n=function(){var n=t[0],r="asc"==t[1].toLowerCase()?1:-1;return{v:e.sort(function(e,t){return e[n]>t[n]?r:e[n]<t[n]?-1*r:0})}}();if("object"==typeof n)return n.v}throw new Error("Unsupported sort type")}function i(e,t){if(Array.isArray(t))return e.slice(t[0],void 0!==t[1]?t[1]+1:void 0);throw new Error("Unsupported range type")}var u=n(6)["default"],s=n(7)["default"],a=n(4)["default"];a(t,"__esModule",{value:!0}),n(10);var c=function(){function e(){var t=void 0===arguments[0]?[]:arguments[0],n=void 0===arguments[1]?"id":arguments[1];if(s(this,e),!Array.isArray(t))throw new Error("Can't initialize a Collection with anything else than an array of items");this.sequence=0,this.identifierName=n,this.items=[],t.map(this.addOne.bind(this))}return u(e,[{key:"getCount",value:function(e){return this.getAll(e).length}},{key:"getAll",value:function(e){var t=this.items.map(function(e){return e});return e&&(e.filter&&(t=r(t,e.filter)),e.sort&&(t=o(t,e.sort)),e.range&&(t=i(t,e.range))),t}},{key:"getIndex",value:function(e){var t=this;return this.items.findIndex(function(n){return n[t.identifierName]==e})}},{key:"getOne",value:function(e){var t=this.getIndex(e);if(-1===t)throw new Error("No item with identifier "+e);return this.items[t]}},{key:"addOne",value:function(e){var t=e[this.identifierName];if(void 0!==t){if(-1!==this.getIndex(t))throw new Error("An item with the identifier "+t+" already exists");this.sequence=Math.max(this.sequence,t)+1}else e[this.identifierName]=this.sequence++;return this.items.push(e),e}},{key:"updateOne",value:function(e,t){var n=this.getIndex(e);if(-1===n)throw new Error("No item with identifier "+e);for(var r in t)this.items[n][r]=t[r];return this.items[n]}},{key:"removeOne",value:function(e){var t=this.getIndex(e);if(-1===t)throw new Error("No item with identifier "+e);var n=this.items[t];return this.items.splice(t,1),e==this.sequence-1&&this.sequence--,n}}]),e}();t["default"]=c,e.exports=t["default"]},function(e,t,n){"use strict";t["default"]=function(e){return e&&e.__esModule?e:{"default":e}},t.__esModule=!0},function(e,t,n){e.exports={"default":n(13),__esModule:!0}},function(e,t,n){e.exports={"default":n(14),__esModule:!0}},function(e,t,n){"use strict";var r=n(4)["default"];t["default"]=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),r(e,o.key,o)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),t.__esModule=!0},function(e,t,n){"use strict";t["default"]=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},t.__esModule=!0},function(e,t,n){"use strict";var r=n(11)["default"],o=n(9)["default"];t["default"]=function(e,t){if(Array.isArray(e))return e;if(r(Object(e))){var n=[],i=!0,u=!1,s=void 0;try{for(var a,c=o(e);!(i=(a=c.next()).done)&&(n.push(a.value),!t||n.length!==t);i=!0);}catch(f){u=!0,s=f}finally{try{!i&&c["return"]&&c["return"]()}finally{if(u)throw s}}return n}throw new TypeError("Invalid attempt to destructure non-iterable instance")},t.__esModule=!0},function(e,t,n){e.exports={"default":n(12),__esModule:!0}},function(e,t,n){!function(e){if(!Array.prototype.findIndex){var t=function(e){var t=Object(this),n=Math.max(0,t.length)>>>0;if(0===n)return-1;if("function"!=typeof e||"[object Function]"!==Object.prototype.toString.call(e))throw new TypeError("Array#findIndex: predicate must be a function");for(var r=arguments.length>1?arguments[1]:void 0,o=0;n>o;o++)if(e.call(r,t[o],o,t))return o;return-1};if(Object.defineProperty)try{Object.defineProperty(Array.prototype,"findIndex",{value:t,configurable:!0,writable:!0})}catch(n){}Array.prototype.findIndex||(Array.prototype.findIndex=t)}}(this)},function(e,t,n){e.exports={"default":n(15),__esModule:!0}},function(e,t,n){n(1),n(17),n(18),e.exports=n(19).core.getIterator},function(e,t,n){var r=n(19);e.exports=function(e,t,n){return r.setDesc(e,t,n)}},function(e,t,n){n(20),e.exports=n(19).core.Object.keys},function(e,t,n){n(1),n(17),n(18),e.exports=n(19).core.isIterable},function(e,t,n){"use strict";function r(e){if(!e)return{};var t={},n=e.split("&");return n.map(function(e){if(-1===e.indexOf("="))t[e]=!0;else{var n=e.split("="),r=u(n,2),o=r[0],i=r[1];(0===i.indexOf("[")||0===i.indexOf("{"))&&(i=JSON.parse(i)),t[o.trim()]=i}}),t}var o=n(6)["default"],i=n(7)["default"],u=n(8)["default"],s=n(4)["default"],a=n(5)["default"],c=n(9)["default"],f=n(3)["default"];s(t,"__esModule",{value:!0});var l=n(2),d=f(l),h=function(){function e(){var t=void 0===arguments[0]?"":arguments[0];i(this,e),this.baseUrl=t,this.collections={},this.loggingEnabled=!1,this.requestInterceptors=[],this.responseInterceptors=[]}return o(e,[{key:"init",value:function(e){for(var t in e)this.addCollection(t,new d["default"](e[t]))}},{key:"toggleLogging",value:function(){this.loggingEnabled=!this.loggingEnabled}},{key:"addCollection",value:function(e,t){this.collections[e]=t}},{key:"getCollection",value:function(e){return this.collections[e]}},{key:"getCollectionNames",value:function(){return a(this.collections)}},{key:"addRequestInterceptor",value:function(e){this.requestInterceptors.push(e)}},{key:"addResponseInterceptor",value:function(e){this.responseInterceptors.push(e)}},{key:"getCount",value:function(e,t){return this.collections[e].getCount(t)}},{key:"getAll",value:function(e,t){return this.collections[e].getAll(t)}},{key:"getOne",value:function(e,t){return this.collections[e].getOne(t)}},{key:"addOne",value:function(e,t){return this.collections[e].addOne(t)}},{key:"updateOne",value:function(e,t,n){return this.collections[e].updateOne(t,n)}},{key:"removeOne",value:function(e,t){return this.collections[e].removeOne(t)}},{key:"decode",value:function(e){if(e.queryString=decodeURIComponent(e.url.slice(e.url.indexOf("?")+1)),e.params=r(e.queryString),e.requestBody)try{e.json=JSON.parse(e.requestBody)}catch(t){}return this.requestInterceptors.reduce(function(e,t){return t(e)},e)}},{key:"respond",value:function(e,t,n){var r=void 0===arguments[3]?200:arguments[3];t||(t={}),t["Content-Type"]||(t["Content-Type"]="application/json");var o={status:r,headers:t,body:e};return o=this.responseInterceptors.reduce(function(e,t){return t(e,n)},o),this.log(n,o),n.respond(o.status,o.headers,JSON.stringify(o.body))}},{key:"log",value:function(e,t){this.loggingEnabled&&(console.group?(console.groupCollapsed(e.method,e.url,"(FakeRest)"),console.group("request"),console.log(e.method,e.url),console.log("headers",e.requestHeaders),console.log("body ",e.requestBody),console.groupEnd(),console.group("response",t.status),console.log("headers",t.headers),console.log("body ",t.body),console.groupEnd(),console.groupEnd()):(console.log("FakeRest request ",e.method,e.url,"headers",e.requestHeaders,"body",e.requestBody),console.log("FakeRest response",t.status,"headers",t.headers,"body",t.body)))}},{key:"handle",value:function(e){e=this.decode(e);var t=!0,n=!1,r=void 0;try{for(var o,i=c(this.getCollectionNames());!(t=(o=i.next()).done);t=!0){var u=o.value,s=e.url.match(new RegExp("^"+this.baseUrl+"\\/("+u+")(\\/(\\d+))?(\\?.*)?$"));if(s)if(s[2]){var a=s[3];if("GET"==e.method)try{var f=this.getOne(u,a);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("PUT"==e.method)try{var f=this.updateOne(u,a,e.json);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("DELETE"==e.method)try{var f=this.removeOne(u,a);return this.respond(f,null,e)}catch(l){return e.respond(404)}}else{if("GET"==e.method){var d=e.params,h={};for(var p in d)"range"!==p&&(h[p]=d[p]);var y=this.getCount(u,h),v=void 0,g=void 0,m=void 0;if(y>0){v=this.getAll(u,d);var b=d.range?d.range[0]:0,O=d.range?Math.min(v.length-1+b,d.range[1]):v.length-1;g="items "+b+"-"+O+"/"+y,m=v.length==y?200:206}else v=[],g="items */0",m=200;return this.respond(v,{"Content-Range":g},e,m)}if("POST"==e.method){var x=this.addOne(u,e.json),w=this.baseUrl+"/"+u+"/"+x[this.getCollection(u).identifierName];return this.respond(x,{Location:w},e,201)}}}}catch(j){n=!0,r=j}finally{try{!t&&i["return"]&&i["return"]()}finally{if(n)throw r}}}},{key:"getHandler",value:function(){return this.handle.bind(this)}}]),e}();t["default"]=h,e.exports=t["default"]},function(e,t,n){var r=n(19).set,o=n(21)(!0),i=n(22).safe("iter"),u=n(23),s=u.step;n(24)(String,"String",function(e){r(this,i,{o:String(e),i:0})},function(){var e,t=this[i],n=t.o,r=t.i;return r>=n.length?s(1):(e=o(n,r),t.i+=e.length,s(0,e))})},function(e,t,n){var r=n(19).core,o=n(23);r.isIterable=o.is,r.getIterator=o.get},function(e,t,n){"use strict";function r(e){return isNaN(e=+e)?0:(e>0?y:p)(e)}function o(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}function i(e,t,n){return e[t]=n,e}function u(e){return m?function(t,n,r){return O.setDesc(t,n,o(e,r))}:i}function s(e){return null!==e&&("object"==typeof e||"function"==typeof e)}function a(e){return"function"==typeof e}function c(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}var f="undefined"!=typeof self?self:Function("return this")(),l={},d=Object.defineProperty,h={}.hasOwnProperty,p=Math.ceil,y=Math.floor,v=Math.max,g=Math.min,m=!!function(){try{return 2==d({},"a",{get:function(){return 2}}).a}catch(e){}}(),b=u(1),O=e.exports=n(25)({g:f,core:l,html:f.document&&document.documentElement,isObject:s,isFunction:a,it:function(e){return e},that:function(){return this},toInteger:r,toLength:function(e){return e>0?g(r(e),9007199254740991):0},toIndex:function(e,t){return e=r(e),0>e?v(e+t,0):g(e,t)},has:function(e,t){return h.call(e,t)},create:Object.create,getProto:Object.getPrototypeOf,DESC:m,desc:o,getDesc:Object.getOwnPropertyDescriptor,setDesc:d,setDescs:Object.defineProperties,getKeys:Object.keys,getNames:Object.getOwnPropertyNames,getSymbols:Object.getOwnPropertySymbols,assertDefined:c,ES5Object:Object,toObject:function(e){return O.ES5Object(c(e))},hide:b,def:u(0),set:f.Symbol?i:b,each:[].forEach});"undefined"!=typeof __e&&(__e=l),"undefined"!=typeof __g&&(__g=f)},function(e,t,n){var r=n(19),o=n(28),i=r.isObject,u=r.toObject;r.each.call("freeze,seal,preventExtensions,isFrozen,isSealed,isExtensible,getOwnPropertyDescriptor,getPrototypeOf,keys,getOwnPropertyNames".split(","),function(e,t){var n=(r.core.Object||{})[e]||Object[e],s=0,a={};a[e]=0==t?function(e){return i(e)?n(e):e}:1==t?function(e){return i(e)?n(e):e}:2==t?function(e){return i(e)?n(e):e}:3==t?function(e){return i(e)?n(e):!0}:4==t?function(e){return i(e)?n(e):!0}:5==t?function(e){return i(e)?n(e):!1}:6==t?function(e,t){return n(u(e),t)}:7==t?function(e){return n(Object(r.assertDefined(e)))}:8==t?function(e){return n(u(e))}:function(e){return n(u(e))};try{n("z")}catch(c){s=1}o(o.S+o.F*s,"Object",a)})},function(e,t,n){var r=n(19);e.exports=function(e){return function(t,n){var o,i,u=String(r.assertDefined(t)),s=r.toInteger(n),a=u.length;return 0>s||s>=a?e?"":void 0:(o=u.charCodeAt(s),55296>o||o>56319||s+1===a||(i=u.charCodeAt(s+1))<56320||i>57343?e?u.charAt(s):o:e?u.slice(s,s+2):(o-55296<<10)+(i-56320)+65536)}}},function(e,t,n){function r(e){return"Symbol(".concat(void 0===e?"":e,")_",(++o+Math.random()).toString(36))}var o=0;r.safe=n(19).g.Symbol||r,e.exports=r},function(e,t,n){"use strict";function r(e,t){o.hide(e,s,t),a in[]&&o.hide(e,a,t)}var o=n(19),i=n(29),u=n(30).obj,s=n(27)("iterator"),a="@@iterator",c={},f={};r(f,o.that),e.exports={BUGGY:"keys"in[]&&!("next"in[].keys()),Iterators:c,step:function(e,t){return{value:t,done:!!e}},is:function(e){var t=Object(e),n=o.g.Symbol,r=n&&n.iterator||a;return r in t||s in t||o.has(c,i.classof(t))},get:function(e){var t=o.g.Symbol,n=e[t&&t.iterator||a],r=n||e[s]||c[i.classof(e)];return u(r.call(e))},set:r,create:function(e,t,n,r){e.prototype=o.create(r||f,{next:o.desc(1,n)}),i.set(e,t+" Iterator")}}},function(e,t,n){var r=n(28),o=n(31),i=n(19),u=n(29),s=n(23),a=n(27)("iterator"),c="@@iterator",f="keys",l="values",d=s.Iterators;e.exports=function(e,t,n,h,p,y,v){function g(e){function t(t){return new n(t,e)}switch(e){case f:return function(){return t(this)};case l:return function(){return t(this)}}return function(){return t(this)}}s.create(n,t,h);var m,b,O=t+" Iterator",x=e.prototype,w=x[a]||x[c]||p&&x[p],j=w||g(p);if(w){var k=i.getProto(j.call(new e));u.set(k,O,!0),i.FW&&i.has(x,c)&&s.set(k,i.that)}if(i.FW&&s.set(x,j),d[t]=j,d[O]=i.that,p)if(m={keys:y?j:g(f),values:p==l?j:g(l),entries:p!=l?j:g("entries")},v)for(b in m)b in x||o(x,b,m[b]);else r(r.P+r.F*s.BUGGY,t,m)}},function(e,t,n){e.exports=function(e){return e.FW=!1,e.path=e.core,e}},function(e,t,n){var r=n(19),o=n(32),i=n(22).safe("iter"),u=n(23),s=u.step,a=u.Iterators;n(24)(Array,"Array",function(e,t){r.set(this,i,{o:r.toObject(e),i:0,k:t})},function(){var e=this[i],t=e.o,n=e.k,r=e.i++;return!t||r>=t.length?(e.o=void 0,s(1)):"keys"==n?s(0,r):"values"==n?s(0,t[r]):s(0,[r,t[r]])},"values"),a.Arguments=a.Array,o("keys"),o("values"),o("entries")},function(e,t,n){var r=n(19).g,o={};e.exports=function(e){return o[e]||(o[e]=r.Symbol&&r.Symbol[e]||n(22).safe("Symbol."+e))}},function(e,t,n){function r(e,t){return function(){return e.apply(t,arguments)}}function o(e,t,n){var i,c,f,l,d=e&o.G,h=e&o.P,p=d?u:e&o.S?u[t]:(u[t]||{}).prototype,y=d?s:s[t]||(s[t]={});d&&(n=t);for(i in n)c=!(e&o.F)&&p&&i in p,c&&i in y||(f=c?p[i]:n[i],d&&!a(p[i])?l=n[i]:e&o.B&&c?l=r(f,u):e&o.W&&p[i]==f?!function(e){l=function(t){return this instanceof e?new e(t):e(t)},l.prototype=e.prototype}(f):l=h&&a(f)?r(Function.call,f):f,y[i]=l,h&&((y.prototype||(y.prototype={}))[i]=f))}var i=n(19),u=i.g,s=i.core,a=i.isFunction;o.F=1,o.G=2,o.S=4,o.P=8,o.B=16,o.W=32,e.exports=o},function(e,t,n){function r(e){return u.call(e).slice(8,-1)}var o=n(19),i=n(27)("toStringTag"),u={}.toString;r.classof=function(e){var t,n;return void 0==e?void 0===e?"Undefined":"Null":"string"==typeof(n=(t=Object(e))[i])?n:r(t)},r.set=function(e,t,n){e&&!o.has(e=n?e:e.prototype,i)&&o.hide(e,i,t)},e.exports=r},function(e,t,n){function r(e,t,n){if(!e)throw TypeError(n?t+n:t)}var o=n(19);r.def=o.assertDefined,r.fn=function(e){if(!o.isFunction(e))throw TypeError(e+" is not a function!");return e},r.obj=function(e){if(!o.isObject(e))throw TypeError(e+" is not an object!");return e},r.inst=function(e,t,n){if(!(e instanceof t))throw TypeError(n+": use the 'new' operator!");return e},e.exports=r},function(e,t,n){e.exports=n(19).hide},function(e,t,n){var r=n(19),o=n(27)("unscopables");!r.FW||o in[]||r.hide(Array.prototype,o,{}),e.exports=function(e){r.FW&&([][o][e]=!0)}}])}); |
{ | ||
"name": "fakerest", | ||
"version": "1.0.1", | ||
"version": "1.0.3", | ||
"repository": "https://github.com/marmelab/FakeRest", | ||
@@ -13,4 +13,6 @@ "description": "Patch XMLHttpRequest to fake a REST server based on JSON data. ", | ||
"devDependencies": { | ||
"babel-core": "^4.7.16", | ||
"babel-loader": "^4.0.0", | ||
"array.prototype.findindex": "^1.0.0", | ||
"babel-core": "^5.4.3", | ||
"babel-loader": "^5.1.2", | ||
"babel-runtime": "^5.4.3", | ||
"karma": "0.12.14", | ||
@@ -17,0 +19,0 @@ "karma-chrome-launcher": "0.1.3", |
@@ -91,2 +91,14 @@ # FakeRest [![Build Status](https://travis-ci.org/marmelab/FakeRest.svg?branch=master)](https://travis-ci.org/marmelab/FakeRest) | ||
] | ||
// the special "q" filter makes a full-text search on all text fields | ||
GET /books?filter={q:'and'} | ||
HTTP 1.1 200 OK | ||
Content-Range: items 0-2/3 | ||
Content-Type: application/json | ||
[ | ||
{ id: 1, author_id: 0, title: 'War and Peace' }, | ||
{ id: 2, author_id: 1, title: 'Pride and Prejudice' }, | ||
{ id: 3, author_id: 1, title: 'Sense and Sensibility' } | ||
] | ||
``` | ||
@@ -125,3 +137,3 @@ | ||
// initialize a rest server with a custom base URL | ||
var restServer = new FakeRest.Server('http://my.custom.domain'); | ||
var restServer = new FakeRest.Server('http://my.custom.domain'); | ||
restServer.toggleLogging(); // logging is off by default, enable it | ||
@@ -155,2 +167,5 @@ // Set all JSON data at once - only if identifier name is 'id' | ||
}); | ||
// enable batch request handler, i.e. allow API clients to query several resourecs into a single request | ||
// see [Facebook's Batch Requests philosophy](https://developers.facebook.com/docs/graph-api/making-multiple-requests) for more details. | ||
restServer.batchUrl('/batch'); | ||
@@ -157,0 +172,0 @@ // you can create more than one fake server to listen to several domains |
@@ -1,2 +0,2 @@ | ||
import 'babel-core/polyfill'; | ||
import 'array.prototype.findindex'; | ||
@@ -10,2 +10,10 @@ function filterItems(items, filter) { | ||
for (let key in filter) { | ||
if (key === 'q') { | ||
// full-text filter | ||
for (let itemKey in item) { | ||
if (item[itemKey].indexOf && item[itemKey].indexOf(filter.q) !== -1) return true; | ||
} | ||
return false; | ||
} | ||
// simple filter | ||
if (item[key] != filter[key]) return false; | ||
@@ -12,0 +20,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import 'babel-core/polyfill'; | ||
import Server from 'Server'; | ||
@@ -3,0 +2,0 @@ import Collection from 'Collection'; |
@@ -1,2 +0,1 @@ | ||
import 'babel-core/polyfill'; | ||
import Collection from 'Collection'; | ||
@@ -21,3 +20,4 @@ | ||
} | ||
}) | ||
}); | ||
return queryObject; | ||
@@ -33,2 +33,3 @@ } | ||
this.responseInterceptors = []; | ||
this.batchUrl = null; | ||
} | ||
@@ -49,2 +50,6 @@ | ||
setBatch(url) { | ||
this.batchUrl = url; | ||
} | ||
addCollection(name, collection) { | ||
@@ -107,3 +112,3 @@ this.collections[name] = collection; | ||
try { | ||
request.json = JSON.parse(request.requestBody); | ||
request.json = JSON.parse(request.requestBody); | ||
} catch(error) { | ||
@@ -127,6 +132,7 @@ // body isn't JSON, skipping | ||
response = this.responseInterceptors.reduce(function(previous, current) { | ||
return current(previous); | ||
return current(previous, request); | ||
}, response); | ||
this.log(request, response); | ||
return request.respond(response.status, response.headers, JSON.stringify(response.body)) | ||
return request.respond(response.status, response.headers, JSON.stringify(response.body)); | ||
} | ||
@@ -141,10 +147,10 @@ | ||
console.log(request.method, request.url); | ||
console.log('headers', request.requestHeaders) | ||
console.log('headers', request.requestHeaders); | ||
console.log('body ', request.requestBody); | ||
console.groupEnd() | ||
console.groupEnd(); | ||
console.group('response', response.status); | ||
console.log('headers', response.headers) | ||
console.log('headers', response.headers); | ||
console.log('body ', response.body); | ||
console.groupEnd() | ||
console.groupEnd(); | ||
console.groupEnd(); | ||
} else { | ||
@@ -156,2 +162,40 @@ console.log('FakeRest request ', request.method, request.url, 'headers', request.requestHeaders, 'body', request.requestBody); | ||
batch(request) { | ||
var json = request.json; | ||
var handle = this.handle.bind(this); | ||
var jsonResponse = Object.keys(json).reduce(function (jsonResponse, requestName) { | ||
var subResponse; | ||
var sub = { | ||
url: json[requestName], | ||
method: 'GET', | ||
params: {}, | ||
respond: function (code, headers, body) { | ||
subResponse = { | ||
code: code, | ||
headers: Object.keys(headers || {}).map(function (headerName) { | ||
return { | ||
'name': headerName, | ||
'value': headers[headerName] | ||
}; | ||
}), | ||
body: body || {} | ||
}; | ||
} | ||
}; | ||
handle(sub); | ||
jsonResponse[requestName] = subResponse || { | ||
code: 404, | ||
headers: [], | ||
body: {} | ||
}; | ||
return jsonResponse; | ||
}, {}); | ||
return this.respond(jsonResponse, {}, request, 200); | ||
} | ||
/** | ||
@@ -173,2 +217,7 @@ * @param {FakeXMLHttpRequest} request | ||
request = this.decode(request); | ||
if (this.batchUrl && this.batchUrl === request.url && request.method === 'POST') { | ||
return this.batch(request); | ||
} | ||
for (let name of this.getCollectionNames()) { | ||
@@ -197,6 +246,6 @@ let matches = request.url.match(new RegExp('^' + this.baseUrl + '\\/(' + name + ')(\\/(\\d+))?(\\?.*)?$' )); | ||
contentRange = 'items */0'; | ||
status = 200 | ||
status = 200; | ||
} | ||
return this.respond(items, { 'Content-Range': contentRange }, request, status); | ||
} | ||
} | ||
if (request.method == 'POST') { | ||
@@ -216,3 +265,3 @@ let newResource = this.addOne(name, request.json); | ||
} | ||
} | ||
@@ -222,3 +271,3 @@ if (request.method == 'PUT') { | ||
let item = this.updateOne(name, id, request.json); | ||
return this.respond(item, null, request); | ||
return this.respond(item, null, request); | ||
} catch (error) { | ||
@@ -225,0 +274,0 @@ return request.respond(404); |
@@ -13,8 +13,8 @@ module.exports = function (config) { | ||
// test files | ||
{pattern: 'test/src/**/*.js', included: true}, | ||
{pattern: 'test/src/**/*.js', included: true} | ||
], | ||
frameworks: ['jasmine'], | ||
reporters: ["spec"], | ||
reporters: ['spec'], | ||
plugins: ['karma-spec-reporter', 'karma-jasmine', 'karma-chrome-launcher', 'karma-phantomjs-launcher'] | ||
}); | ||
}; |
@@ -127,2 +127,14 @@ /*global describe,it,expect,beforeEach,jasmine*/ | ||
it('should filter by the special q full-text filter', function() { | ||
var collection = new Collection([ | ||
{ a: 'hello', b: 'world' }, | ||
{ a: 'helloworld', b: 'bunny'}, | ||
{ a: 'foo', b: 'bar'}, | ||
{ a: '', b: '' }, | ||
{} | ||
]); | ||
expect(collection.getAll({filter: { q: 'hello'} })).toEqual([ { id: 0, a: 'hello', b: 'world' }, { id: 1, a: 'helloworld', b: 'bunny'} ]) | ||
expect(collection.getAll({filter: { q: 'bar'} })).toEqual([{ id: 2, a: 'foo', b: 'bar'}]) | ||
}) | ||
it('should not affect further requests', function() { | ||
@@ -129,0 +141,0 @@ var collection = new Collection([{name: 'c'}, {name: 'a'}, {name: 'b'}]); |
@@ -40,8 +40,8 @@ /*global describe,it,expect,beforeEach,jasmine*/ | ||
var server = new Server(); | ||
var collection = new Collection([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]) | ||
var collection = new Collection([{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]); | ||
server.addCollection('foo', collection); | ||
var collection = server.getCollection('foo'); | ||
collection = server.getCollection('foo'); | ||
expect(collection).toEqual(collection); | ||
}); | ||
}) | ||
}); | ||
}); | ||
@@ -140,2 +140,18 @@ describe('getAll', function() { | ||
}); | ||
it('should pass request in response interceptor', function() { | ||
var server = new Server(); | ||
var requestUrl; | ||
server.addResponseInterceptor(function(response, request) { | ||
requestUrl = request.url; | ||
return response; | ||
}); | ||
server.addCollection('foo', new Collection()); | ||
var request; | ||
request = getFakeXMLHTTPRequest('GET', '/foo'); | ||
server.handle(request); | ||
expect(requestUrl).toEqual('/foo'); | ||
}); | ||
}); | ||
@@ -148,3 +164,3 @@ | ||
var request = getFakeXMLHTTPRequest('GET', '/foo'); | ||
server.handle(request) | ||
server.handle(request); | ||
expect(request.status).toEqual(0); // not responded | ||
@@ -205,3 +221,3 @@ }); | ||
var request = getFakeXMLHTTPRequest('GET', '/foo'); | ||
server.handle(request) | ||
server.handle(request); | ||
expect(request.status).toEqual(200); | ||
@@ -238,3 +254,3 @@ expect(request.responseText).toEqual('[]'); | ||
var request = getFakeXMLHTTPRequest('GET', '/foo/3'); | ||
server.handle(request) | ||
server.handle(request); | ||
expect(request.status).toEqual(404); | ||
@@ -258,3 +274,3 @@ }); | ||
var request = getFakeXMLHTTPRequest('PUT', '/foo/3', JSON.stringify({name: 'baz'})); | ||
server.handle(request) | ||
server.handle(request); | ||
expect(request.status).toEqual(404); | ||
@@ -278,9 +294,47 @@ }); | ||
var request = getFakeXMLHTTPRequest('DELETE', '/foo/3'); | ||
server.handle(request) | ||
server.handle(request); | ||
expect(request.status).toEqual(404); | ||
}); | ||
}) | ||
}); | ||
describe('batch', function() { | ||
it('should return batch response', function() { | ||
var server = new Server(); | ||
server.init({ | ||
foo: [{a:1}, {a:2}, {a:3}], | ||
bar: [{b: true}, {b: false}] | ||
}); | ||
server.setBatch('/batch'); | ||
var request = getFakeXMLHTTPRequest('POST', '/batch', JSON.stringify({foo0: '/foo/0', allbar: '/bar', baz0: '/baz/0'})); | ||
server.handle(request); | ||
expect(request.response).toEqual(JSON.stringify({ | ||
foo0: { | ||
code: 200, | ||
headers: [ | ||
{ | ||
name: 'Content-Type', | ||
value: 'application/json' | ||
} | ||
], | ||
body: '{\"a\":1,\"id\":0}' | ||
}, | ||
allbar: { | ||
code: 200, | ||
headers: [ | ||
{ name: 'Content-Range', value: 'items 0-1/2' }, | ||
{ name: 'Content-Type', value: 'application/json' } | ||
], | ||
body: '[{\"b\":true,\"id\":0},{\"b\":false,\"id\":1}]' | ||
}, | ||
baz0: { | ||
code: 404, | ||
headers: [], | ||
body: {} | ||
} | ||
})); | ||
}); | ||
}); | ||
}); | ||
})(); |
module.exports = { | ||
entry: { | ||
FakeRest: './src/FakeRest.js', | ||
FakeRest: './src/FakeRest.js' | ||
}, | ||
@@ -15,4 +15,4 @@ resolve:{ | ||
exclude: /node_modules/, | ||
loader: 'babel-loader', | ||
}], | ||
loader: 'babel?optional[]=runtime&stage=0' | ||
}] | ||
}, | ||
@@ -25,2 +25,2 @@ output: { | ||
} | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
204
139821
12
1701