Comparing version 1.0.5 to 1.0.6
@@ -1,1 +0,1 @@ | ||
!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(3)["default"];Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),i=r(o),u=n(2),s=r(u);t["default"]={Server:i["default"],Collection:s["default"]},e.exports=t["default"]},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(4)["default"],i=n(5)["default"],u=n(6)["default"],s=n(7)["default"],a=n(8)["default"],c=n(3)["default"];Object.defineProperty(t,"__esModule",{value:!0});var f=n(2),l=c(f),d=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?"":arguments[0];i(this,e),this.baseUrl=t,this.collections={},this.loggingEnabled=!1,this.requestInterceptors=[],this.responseInterceptors=[],this.batchUrl=null}return o(e,[{key:"init",value:function(e){for(var t in e)this.addCollection(t,new l["default"](e[t]))}},{key:"toggleLogging",value:function(){this.loggingEnabled=!this.loggingEnabled}},{key:"setBatch",value:function(e){this.batchUrl=e}},{key:"addCollection",value:function(e,t){this.collections[e]=t}},{key:"getCollection",value:function(e){return this.collections[e]}},{key:"getCollectionNames",value:function(){return s(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=arguments.length<=3||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:"batch",value:function(e){var t=e.json,n=this.handle.bind(this),r=s(t).reduce(function(e,r){var o,i={url:t[r],method:"GET",params:{},respond:function(e,t,n){o={code:e,headers:s(t||{}).map(function(e){return{name:e,value:t[e]}}),body:n||{}}}};return n(i),e[r]=o||{code:404,headers:[],body:{}},e},{});return this.respond(r,{},e,200)}},{key:"handle",value:function(e){if(e=this.decode(e),this.batchUrl&&this.batchUrl===e.url&&"POST"===e.method)return this.batch(e);var t=!0,n=!1,r=void 0;try{for(var o,i=a(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 c=s[3];if("GET"==e.method)try{var f=this.getOne(u,c);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("PUT"==e.method)try{var f=this.updateOne(u,c,e.json);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("DELETE"==e.method)try{var f=this.removeOne(u,c);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),g=void 0,v=void 0,m=void 0;if(y>0){g=this.getAll(u,d);var b=d.range?d.range[0]:0,O=d.range?Math.min(g.length-1+b,d.range[1]):g.length-1;v="items "+b+"-"+O+"/"+y,m=g.length==y?200:206}else g=[],v="items */0",m=200;return this.respond(g,{"Content-Range":v},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"]=d,e.exports=t["default"]},function(e,t,n){"use strict";function r(e,t){if("function"==typeof t)return e.filter(t);if(t instanceof Object){var n=function(){var n=t.q?new RegExp(t.q,"i"):null;return{v:e.filter(function(e){for(var r in t){if("q"===r){for(var o in e)if(e[o]&&e[o].match&&null!==e[o].match(n))return!0;return!1}if(e[r]!=t[r])return!1}return!0})}}();if("object"==typeof n)return n.v}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(4)["default"],s=n(5)["default"];Object.defineProperty(t,"__esModule",{value:!0}),n(9);var a=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],n=arguments.length<=1||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"]=a,e.exports=t["default"]},function(e,t){"use strict";t["default"]=function(e){return e&&e.__esModule?e:{"default":e}},t.__esModule=!0},function(e,t,n){"use strict";var r=n(10)["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){"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(8)["default"],o=n(11)["default"];t["default"]=function(){function e(e,t){var n=[],o=!0,i=!1,u=void 0;try{for(var s,a=r(e);!(o=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(c){i=!0,u=c}finally{try{!o&&a["return"]&&a["return"]()}finally{if(i)throw u}}return n}return function(t,n){if(Array.isArray(t))return t;if(o(Object(t)))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),t.__esModule=!0},function(e,t,n){e.exports={"default":n(13),__esModule:!0}},function(e,t,n){e.exports={"default":n(12),__esModule:!0}},function(){!function(){if(!Array.prototype.findIndex){var e=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:e,configurable:!0,writable:!0})}catch(t){}Array.prototype.findIndex||(Array.prototype.findIndex=e)}}(this)},function(e,t,n){e.exports={"default":n(15),__esModule:!0}},function(e,t,n){e.exports={"default":n(14),__esModule:!0}},function(e,t,n){n(16),n(17),n(18),e.exports=n(19).core.getIterator},function(e,t,n){n(20),e.exports=n(19).core.Object.keys},function(e,t,n){n(16),n(17),n(18),e.exports=n(19).core.isIterable},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(21);var r=n(19),o=n(22).Iterators,i=n(23)("iterator"),u=o.Array,s=r.g.NodeList,a=r.g.HTMLCollection,c=s&&s.prototype,f=a&&a.prototype;r.FW&&(!s||i in c||r.hide(c,i,u),!a||i in f||r.hide(f,i,u)),o.NodeList=o.HTMLCollection=u},function(e,t,n){var r=n(19).set,o=n(24)(!0),i=n(25).safe("iter"),u=n(22),s=u.step;n(26)(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(22);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,g=Math.max,v=Math.min,m=!!function(){try{return 2==d({},"a",{get:function(){return 2}}).a}catch(e){}}(),b=u(1),O=e.exports=n(27)({g:f,core:l,html:f.document&&document.documentElement,isObject:s,isFunction:a,that:function(){return this},toInteger:r,toLength:function(e){return e>0?v(r(e),9007199254740991):0},toIndex:function(e,t){return e=r(e),0>e?g(e+t,0):v(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 s=(r.core.Object||{})[e]||Object[e],a=0,c={};c[e]=0==t?function(e){return i(e)?s(e):e}:1==t?function(e){return i(e)?s(e):e}:2==t?function(e){return i(e)?s(e):e}:3==t?function(e){return i(e)?s(e):!0}:4==t?function(e){return i(e)?s(e):!0}:5==t?function(e){return i(e)?s(e):!1}:6==t?function(e,t){return s(u(e),t)}:7==t?function(e){return s(Object(r.assertDefined(e)))}:8==t?function(e){return s(u(e))}:n(29).get;try{s("z")}catch(f){a=1}o(o.S+o.F*a,"Object",c)})},function(e,t,n){var r=n(19),o=n(30),i=n(25).safe("iter"),u=n(22),s=u.step,a=u.Iterators;n(26)(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){"use strict";function r(e,t){o.hide(e,c,t),f in[]&&o.hide(e,f,t)}var o=n(19),i=n(31),u=i.classof,s=n(32),a=s.obj,c=n(23)("iterator"),f="@@iterator",l=n(33)("iterators"),d={};r(d,o.that),e.exports={BUGGY:"keys"in[]&&!("next"in[].keys()),Iterators:l,step:function(e,t){return{value:t,done:!!e}},is:function(e){var t=Object(e),n=o.g.Symbol;return(n&&n.iterator||f)in t||c in t||o.has(l,u(t))},get:function(e){var t,n=o.g.Symbol;return void 0!=e&&(t=e[n&&n.iterator||f]||e[c]||l[u(e)]),s(o.isFunction(t),e," is not iterable!"),a(t.call(e))},set:r,create:function(e,t,n,r){e.prototype=o.create(r||d,{next:o.desc(1,n)}),i.set(e,t+" Iterator")}}},function(e,t,n){var r=n(19).g,o=n(33)("wks");e.exports=function(e){return o[e]||(o[e]=r.Symbol&&r.Symbol[e]||n(25).safe("Symbol."+e))}},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){var r=n(28),o=n(34),i=n(19),u=n(31),s=n(22),a=n(23)("iterator"),c="@@iterator",f="keys",l="values",d=s.Iterators;e.exports=function(e,t,n,h,p,y,g){function v(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||v(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||g)&&s.set(x,j),d[t]=j,d[O]=i.that,p)if(m={keys:y?j:v(f),values:p==l?j:v(l),entries:p!=l?j:v("entries")},g)for(b in m)b in x||o(x,b,m[b]);else r(r.P+r.F*s.BUGGY,t,m)}},function(e){e.exports=function(e){return e.FW=!1,e.path=e.core,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){try{return u(e)}catch(t){return s.slice()}}var o=n(19),i={}.toString,u=o.getNames,s="object"==typeof window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.get=function(e){return s&&"[object Window]"==i.call(e)?r(e):u(o.toObject(e))}},function(e){e.exports=function(){}},function(e,t,n){function r(e){return u.call(e).slice(8,-1)}var o=n(19),i=n(23)("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){var r=n(19),o="__core-js_shared__",i=r.g[o]||(r.g[o]={});e.exports=function(e){return i[e]||(i[e]={})}},function(e,t,n){e.exports=n(19).hide}])}); | ||
!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(3)["default"];Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),i=r(o),u=n(2),s=r(u);t["default"]={Server:i["default"],Collection:s["default"]},e.exports=t["default"]},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(4)["default"],i=n(5)["default"],u=n(6)["default"],s=n(7)["default"],a=n(8)["default"],c=n(3)["default"];Object.defineProperty(t,"__esModule",{value:!0});var f=n(2),l=c(f),d=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?"":arguments[0];i(this,e),this.baseUrl=t,this.collections={},this.loggingEnabled=!1,this.requestInterceptors=[],this.responseInterceptors=[],this.batchUrl=null}return o(e,[{key:"init",value:function(e){for(var t in e)this.addCollection(t,new l["default"](e[t]))}},{key:"toggleLogging",value:function(){this.loggingEnabled=!this.loggingEnabled}},{key:"setBatch",value:function(e){this.batchUrl=e}},{key:"addCollection",value:function(e,t){this.collections[e]=t}},{key:"getCollection",value:function(e){return this.collections[e]}},{key:"getCollectionNames",value:function(){return s(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=arguments.length<=3||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:"batch",value:function(e){var t=e.json,n=this.handle.bind(this),r=s(t).reduce(function(e,r){var o,i={url:t[r],method:"GET",params:{},respond:function(e,t,n){o={code:e,headers:s(t||{}).map(function(e){return{name:e,value:t[e]}}),body:n||{}}}};return n(i),e[r]=o||{code:404,headers:[],body:{}},e},{});return this.respond(r,{},e,200)}},{key:"handle",value:function(e){if(e=this.decode(e),this.batchUrl&&this.batchUrl===e.url&&"POST"===e.method)return this.batch(e);var t=!0,n=!1,r=void 0;try{for(var o,i=a(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 c=s[3];if("GET"==e.method)try{var f=this.getOne(u,c);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("PUT"==e.method)try{var f=this.updateOne(u,c,e.json);return this.respond(f,null,e)}catch(l){return e.respond(404)}if("DELETE"==e.method)try{var f=this.removeOne(u,c);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),g=void 0,v=void 0,m=void 0;if(y>0){g=this.getAll(u,d);var b=d.range?d.range[0]:0,O=d.range?Math.min(g.length-1+b,d.range[1]):g.length-1;v="items "+b+"-"+O+"/"+y,m=g.length==y?200:206}else g=[],v="items */0",m=200;return this.respond(g,{"Content-Range":v},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"]=d,e.exports=t["default"]},function(e,t,n){"use strict";function r(e,t){if("function"==typeof t)return e.filter(t);if(t instanceof Object){var n=function(){var n=t.q?new RegExp(t.q,"i"):null;return{v:e.filter(function(e){for(var r in t){if("q"===r){for(var o in e)if(e[o]&&e[o].match&&null!==e[o].match(n))return!0;return!1}var i=t[r];if("boolean"==typeof e[r]&&"string"==typeof t[r]&&(i="true"===t[r]?!0:!1),e[r]!=i)return!1}return!0})}}();if("object"==typeof n)return n.v}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(4)["default"],s=n(5)["default"];Object.defineProperty(t,"__esModule",{value:!0}),n(9);var a=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],n=arguments.length<=1||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"]=a,e.exports=t["default"]},function(e,t){"use strict";t["default"]=function(e){return e&&e.__esModule?e:{"default":e}},t.__esModule=!0},function(e,t,n){"use strict";var r=n(10)["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){"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(8)["default"],o=n(11)["default"];t["default"]=function(){function e(e,t){var n=[],o=!0,i=!1,u=void 0;try{for(var s,a=r(e);!(o=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(c){i=!0,u=c}finally{try{!o&&a["return"]&&a["return"]()}finally{if(i)throw u}}return n}return function(t,n){if(Array.isArray(t))return t;if(o(Object(t)))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),t.__esModule=!0},function(e,t,n){e.exports={"default":n(13),__esModule:!0}},function(e,t,n){e.exports={"default":n(12),__esModule:!0}},function(){!function(){if(!Array.prototype.findIndex){var e=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:e,configurable:!0,writable:!0})}catch(t){}Array.prototype.findIndex||(Array.prototype.findIndex=e)}}(this)},function(e,t,n){e.exports={"default":n(14),__esModule:!0}},function(e,t,n){e.exports={"default":n(15),__esModule:!0}},function(e,t,n){n(16),n(17),n(18),e.exports=n(19).core.getIterator},function(e,t,n){n(20),e.exports=n(19).core.Object.keys},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(16),n(17),n(18),e.exports=n(19).core.isIterable},function(e,t,n){n(21);var r=n(19),o=n(22).Iterators,i=n(23)("iterator"),u=o.Array,s=r.g.NodeList,a=r.g.HTMLCollection,c=s&&s.prototype,f=a&&a.prototype;r.FW&&(!s||i in c||r.hide(c,i,u),!a||i in f||r.hide(f,i,u)),o.NodeList=o.HTMLCollection=u},function(e,t,n){var r=n(19).set,o=n(24)(!0),i=n(25).safe("iter"),u=n(22),s=u.step;n(26)(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(22);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,g=Math.max,v=Math.min,m=!!function(){try{return 2==d({},"a",{get:function(){return 2}}).a}catch(e){}}(),b=u(1),O=e.exports=n(27)({g:f,core:l,html:f.document&&document.documentElement,isObject:s,isFunction:a,that:function(){return this},toInteger:r,toLength:function(e){return e>0?v(r(e),9007199254740991):0},toIndex:function(e,t){return e=r(e),0>e?g(e+t,0):v(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 s=(r.core.Object||{})[e]||Object[e],a=0,c={};c[e]=0==t?function(e){return i(e)?s(e):e}:1==t?function(e){return i(e)?s(e):e}:2==t?function(e){return i(e)?s(e):e}:3==t?function(e){return i(e)?s(e):!0}:4==t?function(e){return i(e)?s(e):!0}:5==t?function(e){return i(e)?s(e):!1}:6==t?function(e,t){return s(u(e),t)}:7==t?function(e){return s(Object(r.assertDefined(e)))}:8==t?function(e){return s(u(e))}:n(29).get;try{s("z")}catch(f){a=1}o(o.S+o.F*a,"Object",c)})},function(e,t,n){var r=n(19),o=n(30),i=n(25).safe("iter"),u=n(22),s=u.step,a=u.Iterators;n(26)(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){"use strict";function r(e,t){o.hide(e,c,t),f in[]&&o.hide(e,f,t)}var o=n(19),i=n(31),u=i.classof,s=n(32),a=s.obj,c=n(23)("iterator"),f="@@iterator",l=n(33)("iterators"),d={};r(d,o.that),e.exports={BUGGY:"keys"in[]&&!("next"in[].keys()),Iterators:l,step:function(e,t){return{value:t,done:!!e}},is:function(e){var t=Object(e),n=o.g.Symbol;return(n&&n.iterator||f)in t||c in t||o.has(l,u(t))},get:function(e){var t,n=o.g.Symbol;return void 0!=e&&(t=e[n&&n.iterator||f]||e[c]||l[u(e)]),s(o.isFunction(t),e," is not iterable!"),a(t.call(e))},set:r,create:function(e,t,n,r){e.prototype=o.create(r||d,{next:o.desc(1,n)}),i.set(e,t+" Iterator")}}},function(e,t,n){var r=n(19).g,o=n(33)("wks");e.exports=function(e){return o[e]||(o[e]=r.Symbol&&r.Symbol[e]||n(25).safe("Symbol."+e))}},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){var r=n(28),o=n(34),i=n(19),u=n(31),s=n(22),a=n(23)("iterator"),c="@@iterator",f="keys",l="values",d=s.Iterators;e.exports=function(e,t,n,h,p,y,g){function v(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||v(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||g)&&s.set(x,j),d[t]=j,d[O]=i.that,p)if(m={keys:y?j:v(f),values:p==l?j:v(l),entries:p!=l?j:v("entries")},g)for(b in m)b in x||o(x,b,m[b]);else r(r.P+r.F*s.BUGGY,t,m)}},function(e){e.exports=function(e){return e.FW=!1,e.path=e.core,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){try{return u(e)}catch(t){return s.slice()}}var o=n(19),i={}.toString,u=o.getNames,s="object"==typeof window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.get=function(e){return s&&"[object Window]"==i.call(e)?r(e):u(o.toObject(e))}},function(e){e.exports=function(){}},function(e,t,n){function r(e){return u.call(e).slice(8,-1)}var o=n(19),i=n(23)("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){var r=n(19),o="__core-js_shared__",i=r.g[o]||(r.g[o]={});e.exports=function(e){return i[e]||(i[e]={})}},function(e,t,n){e.exports=n(19).hide}])}); |
{ | ||
"name": "fakerest", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"repository": "https://github.com/marmelab/FakeRest", | ||
@@ -5,0 +5,0 @@ "description": "Patch XMLHttpRequest to fake a REST server based on JSON data. ", |
@@ -19,3 +19,7 @@ import 'array.prototype.findindex'; | ||
// simple filter | ||
if (item[key] != filter[key]) return false; | ||
let value = filter[key]; | ||
if (typeof item[key] == 'boolean' && typeof filter[key] == 'string') { | ||
value = filter[key] === 'true' ? true : false; | ||
} | ||
if (item[key] != value) return false; | ||
} | ||
@@ -22,0 +26,0 @@ return true; |
@@ -127,2 +127,16 @@ /*global describe,it,expect,beforeEach,jasmine*/ | ||
it('should filter boolean values properly', function() { | ||
var collection = new Collection([ | ||
{ name: 'a', is: true }, | ||
{ name: 'b', is: false }, | ||
{ name: 'c', is: true } | ||
]); | ||
var expectedFalse = [{ name: 'b', id: 1, is: false }]; | ||
var expectedTrue = [{ name: 'a', id: 0, is: true }, { name: 'c', id: 2, is: true }]; | ||
expect(collection.getAll({filter: { is: 'false' } })).toEqual(expectedFalse) | ||
expect(collection.getAll({filter: { is: false } })).toEqual(expectedFalse) | ||
expect(collection.getAll({filter: { is: 'true' } })).toEqual(expectedTrue) | ||
expect(collection.getAll({filter: { is: true } })).toEqual(expectedTrue) | ||
}) | ||
it('should filter by the special q full-text filter', function() { | ||
@@ -129,0 +143,0 @@ var collection = new Collection([ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
142355
1720
1