diff --git a/dist/FakeRest.min.js b/dist/FakeRest.min.js index 9818820..c542bd0 100644 --- a/dist/FakeRest.min.js +++ b/dist/FakeRest.min.js @@ -1 +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(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){"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(28)({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){"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]t[n]?r:e[n]>>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(17),n(18),n(19),e.exports=n(1).core.getIterator},function(e,t,n){var r=n(1);e.exports=function(e,t,n){return r.setDesc(e,t,n)}},function(e,t,n){n(20),e.exports=n(1).core.Object.keys},function(e,t,n){n(17),n(18),n(19),e.exports=n(1).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)},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){n(21);var r=n(1),o=n(22).Iterators,i=n(23)("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){var r=n(1).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(1).core,o=n(22);r.isIterable=o.is,r.getIterator=o.get},function(e,t,n){var r=n(1),o=n(27),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(1),o=n(29),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,s,t),a in[]&&o.hide(e,a,t)}var o=n(1),i=n(30),u=n(31).obj,s=n(23)("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(1).g,o={};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(1);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(1).g.Symbol||r,e.exports=r},function(e,t,n){var r=n(27),o=n(32),i=n(1),u=n(30),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,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){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(1),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){e.exports=function(e){return e.FW=!1,e.path=e.core,e}},function(e,t,n){var r=n(1),o=n(23)("unscopables");!r.FW||o in[]||r.hide(Array.prototype,o,{}),e.exports=function(e){r.FW&&([][o][e]=!0)}},function(e,t,n){function r(e){return u.call(e).slice(8,-1)}var o=n(1),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(1);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(1).hide}])}); \ No newline at end of file +!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";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),i=r(o),s=n(2),u=r(s);t["default"]={Server:i["default"],Collection:u["default"]},e.exports=t["default"]},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e)){var n=[],r=!0,o=!1,i=void 0;try{for(var s,u=e[Symbol.iterator]();!(r=(s=u.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(a){o=!0,i=a}finally{try{!r&&u["return"]&&u["return"]()}finally{if(o)throw i}}return n}throw new TypeError("Invalid attempt to destructure non-iterable instance")}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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=o(n,2),i=r[0],s=r[1];(0===s.indexOf("[")||0===s.indexOf("{"))&&(s=JSON.parse(s)),t[i.trim()]=s}}),t}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n0){y=this.getAll(s,f);var m=f.range?f.range[0]:0,b=f.range?Math.min(y.length-1+m,f.range[1]):y.length-1;v="items "+m+"-"+b+"/"+p,g=y.length==p?200:206}else y=[],v="items */0",g=200;return this.respond(y,{"Content-Range":v},e,g)}if("POST"==e.method){var w=this.addOne(s,e.json),O=this.baseUrl+"/"+s+"/"+w[this.getCollection(s).identifierName];return this.respond(w,{Location:O},e,201)}}}}catch(k){n=!0,r=k}finally{try{!t&&i["return"]&&i["return"]()}finally{if(n)throw r}}}},{key:"getHandler",value:function(){return this.handle.bind(this)}}]),e}();t["default"]=c,e.exports=t["default"]},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(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 i(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]t[n]?r:e[n]>>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)}])}); \ No newline at end of file diff --git a/package.json b/package.json index 263e3e2..1f1d605 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "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", "karma-chrome-launcher": "0.1.3", "karma-jasmine": "0.1.5", diff --git a/webpack.config.js b/webpack.config.js index e4e5246..35e810f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,7 +12,7 @@ module.exports = { loaders: [{ test: /\.js$/, exclude: /node_modules/, - loader: 'babel-loader?stage=1&optional[]=runtime' + loader: 'babel-loader' }] }, output: {