Socket
Socket
Sign inDemoInstall

json-server

Package Overview
Dependencies
Maintainers
1
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-server - npm Package Compare versions

Comparing version 0.14.0 to 0.14.1

5

CHANGELOG.md
# Change Log
## 0.14.1 - 2018-12-25
* Show error message if port is already used
* Upgrade to [lowdb](https://github.com/typicode/lowdb) `1.0`
## 0.14.0 - 2018-06-09

@@ -4,0 +9,0 @@

2

dist/main.js

@@ -1,1 +0,1 @@

!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=12)}([function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";(function(e){var n=setTimeout;function r(){}function o(e){if(!(this instanceof o))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],l(e,this)}function i(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,o._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var r;try{r=n(e._value)}catch(e){return void s(t.promise,e)}a(t.promise,r)}else(1===e._state?a:s)(t.promise,e._value)})):e._deferreds.push(t)}function a(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof o)return e._state=3,e._value=t,void u(e);if("function"==typeof n)return void l((r=n,i=t,function(){r.apply(i,arguments)}),e)}e._state=1,e._value=t,u(e)}catch(t){s(e,t)}var r,i}function s(e,t){e._state=2,e._value=t,u(e)}function u(e){2===e._state&&0===e._deferreds.length&&o._immediateFn(function(){e._handled||o._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;t<n;t++)i(e,e._deferreds[t]);e._deferreds=null}function l(e,t){var n=!1;try{e(function(e){n||(n=!0,a(t,e))},function(e){n||(n=!0,s(t,e))})}catch(e){if(n)return;n=!0,s(t,e)}}o.prototype.catch=function(e){return this.then(null,e)},o.prototype.then=function(e,t){var n=new this.constructor(r);return i(this,new function(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}(e,t,n)),n},o.prototype.finally=function(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})},o.all=function(e){return new o(function(t,n){if(!e||void 0===e.length)throw new TypeError("Promise.all accepts an array");var r=Array.prototype.slice.call(e);if(0===r.length)return t([]);var o=r.length;function i(e,a){try{if(a&&("object"==typeof a||"function"==typeof a)){var s=a.then;if("function"==typeof s)return void s.call(a,function(t){i(e,t)},n)}r[e]=a,0==--o&&t(r)}catch(e){n(e)}}for(var a=0;a<r.length;a++)i(a,r[a])})},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o(function(t){t(e)})},o.reject=function(e){return new o(function(t,n){n(e)})},o.race=function(e){return new o(function(t,n){for(var r=0,o=e.length;r<o;r++)e[r].then(t,n)})},o._immediateFn="function"==typeof e&&function(t){e(t)}||function(e){n(e,0)},o._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},t.a=o}).call(this,n(10).setImmediate)},,function(e,t,n){},,function(e,t,n){},function(e,t,n){"use strict";n.r(t),n.d(t,"h",function(){return a}),n.d(t,"createElement",function(){return a}),n.d(t,"cloneElement",function(){return l}),n.d(t,"Component",function(){return N}),n.d(t,"render",function(){return O}),n.d(t,"rerender",function(){return p}),n.d(t,"options",function(){return r});var r={},o=[],i=[];function a(e,t){var n,a,s,u,l=i;for(u=arguments.length;u-- >2;)o.push(arguments[u]);for(t&&null!=t.children&&(o.length||o.push(t.children),delete t.children);o.length;)if((a=o.pop())&&void 0!==a.pop)for(u=a.length;u--;)o.push(a[u]);else"boolean"==typeof a&&(a=null),(s="function"!=typeof e)&&(null==a?a="":"number"==typeof a?a=String(a):"string"!=typeof a&&(s=!1)),s&&n?l[l.length-1]+=a:l===i?l=[a]:l.push(a),n=s;var c=new function(){};return c.nodeName=e,c.children=l,c.attributes=null==t?void 0:t,c.key=null==t?void 0:t.key,void 0!==r.vnode&&r.vnode(c),c}function s(e,t){for(var n in t)e[n]=t[n];return e}var u="function"==typeof Promise?Promise.resolve().then.bind(Promise.resolve()):setTimeout;function l(e,t){return a(e.nodeName,s(s({},e.attributes),t),arguments.length>2?[].slice.call(arguments,2):e.children)}var c=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,f=[];function d(e){!e._dirty&&(e._dirty=!0)&&1==f.push(e)&&(r.debounceRendering||u)(p)}function p(){var e,t=f;for(f=[];e=t.pop();)e._dirty&&S(e)}function h(e,t){return e.normalizedNodeName===t||e.nodeName.toLowerCase()===t.toLowerCase()}function y(e){var t=s({},e.attributes);t.children=e.children;var n=e.nodeName.defaultProps;if(void 0!==n)for(var r in n)void 0===t[r]&&(t[r]=n[r]);return t}function m(e){var t=e.parentNode;t&&t.removeChild(e)}function v(e,t,n,r,o){if("className"===t&&(t="class"),"key"===t);else if("ref"===t)n&&n(null),r&&r(e);else if("class"!==t||o)if("style"===t){if(r&&"string"!=typeof r&&"string"!=typeof n||(e.style.cssText=r||""),r&&"object"==typeof r){if("string"!=typeof n)for(var i in n)i in r||(e.style[i]="");for(var i in r)e.style[i]="number"==typeof r[i]&&!1===c.test(i)?r[i]+"px":r[i]}}else if("dangerouslySetInnerHTML"===t)r&&(e.innerHTML=r.__html||"");else if("o"==t[0]&&"n"==t[1]){var a=t!==(t=t.replace(/Capture$/,""));t=t.toLowerCase().substring(2),r?n||e.addEventListener(t,b,a):e.removeEventListener(t,b,a),(e._listeners||(e._listeners={}))[t]=r}else if("list"!==t&&"type"!==t&&!o&&t in e)!function(e,t,n){try{e[t]=n}catch(e){}}(e,t,null==r?"":r),null!=r&&!1!==r||e.removeAttribute(t);else{var s=o&&t!==(t=t.replace(/^xlink:?/,""));null==r||!1===r?s?e.removeAttributeNS("http://www.w3.org/1999/xlink",t.toLowerCase()):e.removeAttribute(t):"function"!=typeof r&&(s?e.setAttributeNS("http://www.w3.org/1999/xlink",t.toLowerCase(),r):e.setAttribute(t,r))}else e.className=r||""}function b(e){return this._listeners[e.type](r.event&&r.event(e)||e)}var _=[],w=0,g=!1,T=!1;function x(){for(var e;e=_.pop();)r.afterMount&&r.afterMount(e),e.componentDidMount&&e.componentDidMount()}function C(e,t,n,r,o,i){w++||(g=null!=o&&void 0!==o.ownerSVGElement,T=null!=e&&!("__preactattr_"in e));var a=E(e,t,n,r,i);return o&&a.parentNode!==o&&o.appendChild(a),--w||(T=!1,i||x()),a}function E(e,t,n,r,o){var i=e,a=g;if(null!=t&&"boolean"!=typeof t||(t=""),"string"==typeof t||"number"==typeof t)return e&&void 0!==e.splitText&&e.parentNode&&(!e._component||o)?e.nodeValue!=t&&(e.nodeValue=t):(i=document.createTextNode(t),e&&(e.parentNode&&e.parentNode.replaceChild(i,e),P(e,!0))),i.__preactattr_=!0,i;var s,u,l=t.nodeName;if("function"==typeof l)return function(e,t,n,r){var o=e&&e._component,i=o,a=e,s=o&&e._componentConstructor===t.nodeName,u=s,l=y(t);for(;o&&!u&&(o=o._parentComponent);)u=o.constructor===t.nodeName;o&&u&&(!r||o._component)?(k(o,l,3,n,r),e=o.base):(i&&!s&&(U(i),e=a=null),o=j(t.nodeName,l,n),e&&!o.nextBase&&(o.nextBase=e,a=null),k(o,l,1,n,r),e=o.base,a&&e!==a&&(a._component=null,P(a,!1)));return e}(e,t,n,r);if(g="svg"===l||"foreignObject"!==l&&g,l=String(l),(!e||!h(e,l))&&(s=l,(u=g?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)).normalizedNodeName=s,i=u,e)){for(;e.firstChild;)i.appendChild(e.firstChild);e.parentNode&&e.parentNode.replaceChild(i,e),P(e,!0)}var c=i.firstChild,f=i.__preactattr_,d=t.children;if(null==f){f=i.__preactattr_={};for(var p=i.attributes,b=p.length;b--;)f[p[b].name]=p[b].value}return!T&&d&&1===d.length&&"string"==typeof d[0]&&null!=c&&void 0!==c.splitText&&null==c.nextSibling?c.nodeValue!=d[0]&&(c.nodeValue=d[0]):(d&&d.length||null!=c)&&function(e,t,n,r,o){var i,a,s,u,l,c=e.childNodes,f=[],d={},p=0,y=0,v=c.length,b=0,_=t?t.length:0;if(0!==v)for(var w=0;w<v;w++){var g=c[w],T=g.__preactattr_,x=_&&T?g._component?g._component.__key:T.key:null;null!=x?(p++,d[x]=g):(T||(void 0!==g.splitText?!o||g.nodeValue.trim():o))&&(f[b++]=g)}if(0!==_)for(var w=0;w<_;w++){u=t[w],l=null;var x=u.key;if(null!=x)p&&void 0!==d[x]&&(l=d[x],d[x]=void 0,p--);else if(!l&&y<b)for(i=y;i<b;i++)if(void 0!==f[i]&&(C=a=f[i],B=o,"string"==typeof(A=u)||"number"==typeof A?void 0!==C.splitText:"string"==typeof A.nodeName?!C._componentConstructor&&h(C,A.nodeName):B||C._componentConstructor===A.nodeName)){l=a,f[i]=void 0,i===b-1&&b--,i===y&&y++;break}l=E(l,u,n,r),s=c[w],l&&l!==e&&l!==s&&(null==s?e.appendChild(l):l===s.nextSibling?m(s):e.insertBefore(l,s))}var C,A,B;if(p)for(var w in d)void 0!==d[w]&&P(d[w],!1);for(;y<=b;)void 0!==(l=f[b--])&&P(l,!1)}(i,d,n,r,T||null!=f.dangerouslySetInnerHTML),function(e,t,n){var r;for(r in n)t&&null!=t[r]||null==n[r]||v(e,r,n[r],n[r]=void 0,g);for(r in t)"children"===r||"innerHTML"===r||r in n&&t[r]===("value"===r||"checked"===r?e[r]:n[r])||v(e,r,n[r],n[r]=t[r],g)}(i,t.attributes,f),g=a,i}function P(e,t){var n=e._component;n?U(n):(null!=e.__preactattr_&&e.__preactattr_.ref&&e.__preactattr_.ref(null),!1!==t&&null!=e.__preactattr_||m(e),A(e))}function A(e){for(e=e.lastChild;e;){var t=e.previousSibling;P(e,!0),e=t}}var B={};function j(e,t,n){var r,o=B[e.name];if(e.prototype&&e.prototype.render?(r=new e(t,n),N.call(r,t,n)):((r=new N(t,n)).constructor=e,r.render=I),o)for(var i=o.length;i--;)if(o[i].constructor===e){r.nextBase=o[i].nextBase,o.splice(i,1);break}return r}function I(e,t,n){return this.constructor(e,n)}function k(e,t,n,o,i){e._disable||(e._disable=!0,(e.__ref=t.ref)&&delete t.ref,(e.__key=t.key)&&delete t.key,!e.base||i?e.componentWillMount&&e.componentWillMount():e.componentWillReceiveProps&&e.componentWillReceiveProps(t,o),o&&o!==e.context&&(e.prevContext||(e.prevContext=e.context),e.context=o),e.prevProps||(e.prevProps=e.props),e.props=t,e._disable=!1,0!==n&&(1!==n&&!1===r.syncComponentUpdates&&e.base?d(e):S(e,1,i)),e.__ref&&e.__ref(e))}function S(e,t,n,o){if(!e._disable){var i,a,u,l=e.props,c=e.state,f=e.context,d=e.prevProps||l,p=e.prevState||c,h=e.prevContext||f,m=e.base,v=e.nextBase,b=m||v,g=e._component,T=!1;if(m&&(e.props=d,e.state=p,e.context=h,2!==t&&e.shouldComponentUpdate&&!1===e.shouldComponentUpdate(l,c,f)?T=!0:e.componentWillUpdate&&e.componentWillUpdate(l,c,f),e.props=l,e.state=c,e.context=f),e.prevProps=e.prevState=e.prevContext=e.nextBase=null,e._dirty=!1,!T){i=e.render(l,c,f),e.getChildContext&&(f=s(s({},f),e.getChildContext()));var E,A,B=i&&i.nodeName;if("function"==typeof B){var I=y(i);(a=g)&&a.constructor===B&&I.key==a.__key?k(a,I,1,f,!1):(E=a,e._component=a=j(B,I,f),a.nextBase=a.nextBase||v,a._parentComponent=e,k(a,I,0,f,!1),S(a,1,n,!0)),A=a.base}else u=b,(E=g)&&(u=e._component=null),(b||1===t)&&(u&&(u._component=null),A=C(u,i,f,n||!m,b&&b.parentNode,!0));if(b&&A!==b&&a!==g){var N=b.parentNode;N&&A!==N&&(N.replaceChild(A,b),E||(b._component=null,P(b,!1)))}if(E&&U(E),e.base=A,A&&!o){for(var O=e,R=e;R=R._parentComponent;)(O=R).base=A;A._component=O,A._componentConstructor=O.constructor}}if(!m||n?_.unshift(e):T||(e.componentDidUpdate&&e.componentDidUpdate(d,p,h),r.afterUpdate&&r.afterUpdate(e)),null!=e._renderCallbacks)for(;e._renderCallbacks.length;)e._renderCallbacks.pop().call(e);w||o||x()}}function U(e){r.beforeUnmount&&r.beforeUnmount(e);var t=e.base;e._disable=!0,e.componentWillUnmount&&e.componentWillUnmount(),e.base=null;var n=e._component;n?U(n):t&&(t.__preactattr_&&t.__preactattr_.ref&&t.__preactattr_.ref(null),e.nextBase=t,m(t),function(e){var t=e.constructor.name;(B[t]||(B[t]=[])).push(e)}(e),A(t)),e.__ref&&e.__ref(null)}function N(e,t){this._dirty=!0,this.context=t,this.props=e,this.state=this.state||{}}function O(e,t,n){return C(n,e,{},!1,t,!1)}s(N.prototype,{setState:function(e,t){var n=this.state;this.prevState||(this.prevState=s({},n)),s(n,"function"==typeof e?e(n,this.props):e),t&&(this._renderCallbacks=this._renderCallbacks||[]).push(t),d(this)},forceUpdate:function(e){e&&(this._renderCallbacks=this._renderCallbacks||[]).push(e),S(this,2)},render:function(){}});var R={h:a,createElement:a,cloneElement:l,Component:N,render:O,rerender:p,options:r};t.default=R},function(e,t){!function(e){"use strict";if(!e.fetch){var t={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};if(t.arrayBuffer)var n=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],r=function(e){return e&&DataView.prototype.isPrototypeOf(e)},o=ArrayBuffer.isView||function(e){return e&&n.indexOf(Object.prototype.toString.call(e))>-1};c.prototype.append=function(e,t){e=s(e),t=u(t);var n=this.map[e];this.map[e]=n?n+","+t:t},c.prototype.delete=function(e){delete this.map[s(e)]},c.prototype.get=function(e){return e=s(e),this.has(e)?this.map[e]:null},c.prototype.has=function(e){return this.map.hasOwnProperty(s(e))},c.prototype.set=function(e,t){this.map[s(e)]=u(t)},c.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},c.prototype.keys=function(){var e=[];return this.forEach(function(t,n){e.push(n)}),l(e)},c.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),l(e)},c.prototype.entries=function(){var e=[];return this.forEach(function(t,n){e.push([n,t])}),l(e)},t.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var i=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];m.prototype.clone=function(){return new m(this,{body:this._bodyInit})},y.call(m.prototype),y.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},b.error=function(){var e=new b(null,{status:0,statusText:""});return e.type="error",e};var a=[301,302,303,307,308];b.redirect=function(e,t){if(-1===a.indexOf(t))throw new RangeError("Invalid status code");return new b(null,{status:t,headers:{location:e}})},e.Headers=c,e.Request=m,e.Response=b,e.fetch=function(e,n){return new Promise(function(r,o){var i=new m(e,n),a=new XMLHttpRequest;a.onload=function(){var e,t,n={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new c,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(e){var n=e.split(":"),r=n.shift().trim();if(r){var o=n.join(":").trim();t.append(r,o)}}),t)};n.url="responseURL"in a?a.responseURL:n.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;r(new b(o,n))},a.onerror=function(){o(new TypeError("Network request failed"))},a.ontimeout=function(){o(new TypeError("Network request failed"))},a.open(i.method,i.url,!0),"include"===i.credentials?a.withCredentials=!0:"omit"===i.credentials&&(a.withCredentials=!1),"responseType"in a&&t.blob&&(a.responseType="blob"),i.headers.forEach(function(e,t){a.setRequestHeader(t,e)}),a.send(void 0===i._bodyInit?null:i._bodyInit)})},e.fetch.polyfill=!0}function s(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function u(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var n={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return t.iterable&&(n[Symbol.iterator]=function(){return n}),n}function c(e){this.map={},e instanceof c?e.forEach(function(e,t){this.append(t,e)},this):Array.isArray(e)?e.forEach(function(e){this.append(e[0],e[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function f(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function d(e){return new Promise(function(t,n){e.onload=function(){t(e.result)},e.onerror=function(){n(e.error)}})}function p(e){var t=new FileReader,n=d(t);return t.readAsArrayBuffer(e),n}function h(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function y(){return this.bodyUsed=!1,this._initBody=function(e){if(this._bodyInit=e,e)if("string"==typeof e)this._bodyText=e;else if(t.blob&&Blob.prototype.isPrototypeOf(e))this._bodyBlob=e;else if(t.formData&&FormData.prototype.isPrototypeOf(e))this._bodyFormData=e;else if(t.searchParams&&URLSearchParams.prototype.isPrototypeOf(e))this._bodyText=e.toString();else if(t.arrayBuffer&&t.blob&&r(e))this._bodyArrayBuffer=h(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!t.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(e)&&!o(e))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=h(e)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):t.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},t.blob&&(this.blob=function(){var e=f(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(p)}),this.text=function(){var e,t,n,r=f(this);if(r)return r;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,n=d(t),t.readAsText(e),n;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),r=0;r<t.length;r++)n[r]=String.fromCharCode(t[r]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},t.formData&&(this.formData=function(){return this.text().then(v)}),this.json=function(){return this.text().then(JSON.parse)},this}function m(e,t){var n,r,o=(t=t||{}).body;if(e instanceof m){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new c(e.headers)),this.method=e.method,this.mode=e.mode,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"omit",!t.headers&&this.headers||(this.headers=new c(t.headers)),this.method=(n=t.method||this.method||"GET",r=n.toUpperCase(),i.indexOf(r)>-1?r:n),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function v(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var n=e.split("="),r=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(r),decodeURIComponent(o))}}),t}function b(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new c(t.headers),this.url=t.url||"",this._initBody(e)}}("undefined"!=typeof self?self:this)},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function s(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var u,l=[],c=!1,f=-1;function d(){c&&u&&(c=!1,u.length?l=u.concat(l):f=-1,l.length&&p())}function p(){if(!c){var e=s(d);c=!0;for(var t=l.length;t;){for(u=l,l=[];++f<t;)u&&u[f].run();f=-1,t=l.length}u=null,c=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===a||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function h(e,t){this.fun=e,this.array=t}function y(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];l.push(new h(e,t)),1!==l.length||c||s(p)},h.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=y,o.addListener=y,o.once=y,o.off=y,o.removeListener=y,o.removeAllListeners=y,o.emit=y,o.prependListener=y,o.prependOnceListener=y,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t,n){(function(e,t){!function(e,n){"use strict";if(!e.setImmediate){var r,o,i,a,s,u=1,l={},c=!1,f=e.document,d=Object.getPrototypeOf&&Object.getPrototypeOf(e);d=d&&d.setTimeout?d:e,"[object process]"==={}.toString.call(e.process)?r=function(e){t.nextTick(function(){h(e)})}:!function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?e.MessageChannel?((i=new MessageChannel).port1.onmessage=function(e){h(e.data)},r=function(e){i.port2.postMessage(e)}):f&&"onreadystatechange"in f.createElement("script")?(o=f.documentElement,r=function(e){var t=f.createElement("script");t.onreadystatechange=function(){h(e),t.onreadystatechange=null,o.removeChild(t),t=null},o.appendChild(t)}):r=function(e){setTimeout(h,0,e)}:(a="setImmediate$"+Math.random()+"$",s=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(a)&&h(+t.data.slice(a.length))},e.addEventListener?e.addEventListener("message",s,!1):e.attachEvent("onmessage",s),r=function(t){e.postMessage(a+t,"*")}),d.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var o={callback:e,args:t};return l[u]=o,r(u),u++},d.clearImmediate=p}function p(e){delete l[e]}function h(e){if(c)setTimeout(h,0,e);else{var t=l[e];if(t){c=!0;try{!function(e){var t=e.callback,r=e.args;switch(r.length){case 0:t();break;case 1:t(r[0]);break;case 2:t(r[0],r[1]);break;case 3:t(r[0],r[1],r[2]);break;default:t.apply(n,r)}}(t)}finally{p(e),c=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(this,n(0),n(8))},function(e,t,n){(function(e){var r=void 0!==e&&e||"undefined"!=typeof self&&self||window,o=Function.prototype.apply;function i(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new i(o.call(setTimeout,r,arguments),clearTimeout)},t.setInterval=function(){return new i(o.call(setInterval,r,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(r,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},n(9),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,n(0))},function(e,t,n){"use strict";n.r(t),function(e){var t=n(1),r=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==e)return e;throw new Error("unable to locate global object")}();r.Promise||(r.Promise=t.a)}.call(this,n(0))},function(e,t,n){"use strict";n(11),n(7);var r=n(6);function o(e){var t=e.name,n=e.length;return(0,r.h)("li",null,(0,r.h)("a",{href:t},"/",t)," ",(0,r.h)("sup",null,n?n+"x":"object"))}function i(e){var t=e.db;return(0,r.h)("ul",null,Object.keys(t).map(function(e){return(0,r.h)(o,{name:e,length:Array.isArray(t[e])&&t[e].length})}))}function a(){return(0,r.h)("p",null,"No resources found")}function s(e){var t=e.db;return(0,r.h)("div",null,(0,r.h)("h4",null,"Resources"),Object.keys(t).length?(0,r.h)(i,{db:t}):(0,r.h)(a,null))}function u(e){var t=e.customRoutes,n=Object.keys(t);if(n.length)return(0,r.h)("div",null,(0,r.h)("h4",null,"Custom Routes"),(0,r.h)("table",null,n.map(function(e){return(0,r.h)("tr",null,(0,r.h)("td",null,e),(0,r.h)("td",null,"β‡’ ",t[e]))})))}n(5),n(3),window.fetch("db").then(function(e){return e.json()}).then(function(e){return(0,r.render)((0,r.h)(s,{db:e}),document.getElementById("resources"))}),window.fetch("__rules").then(function(e){return e.json()}).then(function(e){(0,r.render)((0,r.h)(u,{customRoutes:e}),document.getElementById("custom-routes"))})}]);
!function(t){var r={};function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var o in t)e.d(n,o,function(r){return t[r]}.bind(null,o));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=9)}([function(t,r,e){"use strict";r.a=function(t){var r=this.constructor;return this.then(function(e){return r.resolve(t()).then(function(){return e})},function(e){return r.resolve(t()).then(function(){return r.reject(e)})})}},function(t,r){var e;e=function(){return this}();try{e=e||new Function("return this")()}catch(t){"object"==typeof window&&(e=window)}t.exports=e},function(t,r,e){"use strict";(function(t){var n=e(0),o=setTimeout;function i(){}function s(t){if(!(this instanceof s))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],h(t,this)}function c(t,r){for(;3===t._state;)t=t._value;0!==t._state?(t._handled=!0,s._immediateFn(function(){var e=1===t._state?r.onFulfilled:r.onRejected;if(null!==e){var n;try{n=e(t._value)}catch(t){return void a(r.promise,t)}f(r.promise,n)}else(1===t._state?f:a)(r.promise,t._value)})):t._deferreds.push(r)}function f(t,r){try{if(r===t)throw new TypeError("A promise cannot be resolved with itself.");if(r&&("object"==typeof r||"function"==typeof r)){var e=r.then;if(r instanceof s)return t._state=3,t._value=r,void u(t);if("function"==typeof e)return void h((n=e,o=r,function(){n.apply(o,arguments)}),t)}t._state=1,t._value=r,u(t)}catch(r){a(t,r)}var n,o}function a(t,r){t._state=2,t._value=r,u(t)}function u(t){2===t._state&&0===t._deferreds.length&&s._immediateFn(function(){t._handled||s._unhandledRejectionFn(t._value)});for(var r=0,e=t._deferreds.length;r<e;r++)c(t,t._deferreds[r]);t._deferreds=null}function l(t,r,e){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof r?r:null,this.promise=e}function h(t,r){var e=!1;try{t(function(t){e||(e=!0,f(r,t))},function(t){e||(e=!0,a(r,t))})}catch(t){if(e)return;e=!0,a(r,t)}}s.prototype.catch=function(t){return this.then(null,t)},s.prototype.then=function(t,r){var e=new this.constructor(i);return c(this,new l(t,r,e)),e},s.prototype.finally=n.a,s.all=function(t){return new s(function(r,e){if(!t||void 0===t.length)throw new TypeError("Promise.all accepts an array");var n=Array.prototype.slice.call(t);if(0===n.length)return r([]);var o=n.length;function i(t,s){try{if(s&&("object"==typeof s||"function"==typeof s)){var c=s.then;if("function"==typeof c)return void c.call(s,function(r){i(t,r)},e)}n[t]=s,0==--o&&r(n)}catch(t){e(t)}}for(var s=0;s<n.length;s++)i(s,n[s])})},s.resolve=function(t){return t&&"object"==typeof t&&t.constructor===s?t:new s(function(r){r(t)})},s.reject=function(t){return new s(function(r,e){e(t)})},s.race=function(t){return new s(function(r,e){for(var n=0,o=t.length;n<o;n++)t[n].then(r,e)})},s._immediateFn="function"==typeof t&&function(r){t(r)}||function(t){o(t,0)},s._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)},r.a=s}).call(this,e(4).setImmediate)},function(t,r,e){"use strict";(function(t){var r=e(2),n=e(0),o=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==t)return t;throw new Error("unable to locate global object")}();"Promise"in o?o.Promise.prototype.finally||(o.Promise.prototype.finally=n.a):o.Promise=r.a}).call(this,e(1))},function(t,r,e){(function(t){var n=void 0!==t&&t||"undefined"!=typeof self&&self||window,o=Function.prototype.apply;function i(t,r){this._id=t,this._clearFn=r}r.setTimeout=function(){return new i(o.call(setTimeout,n,arguments),clearTimeout)},r.setInterval=function(){return new i(o.call(setInterval,n,arguments),clearInterval)},r.clearTimeout=r.clearInterval=function(t){t&&t.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(n,this._id)},r.enroll=function(t,r){clearTimeout(t._idleTimeoutId),t._idleTimeout=r},r.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},r._unrefActive=r.active=function(t){clearTimeout(t._idleTimeoutId);var r=t._idleTimeout;r>=0&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},r))},e(5),r.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,r.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(this,e(1))},function(t,r,e){(function(t,r){!function(t,e){"use strict";if(!t.setImmediate){var n,o,i,s,c,f=1,a={},u=!1,l=t.document,h=Object.getPrototypeOf&&Object.getPrototypeOf(t);h=h&&h.setTimeout?h:t,"[object process]"==={}.toString.call(t.process)?n=function(t){r.nextTick(function(){d(t)})}:!function(){if(t.postMessage&&!t.importScripts){var r=!0,e=t.onmessage;return t.onmessage=function(){r=!1},t.postMessage("","*"),t.onmessage=e,r}}()?t.MessageChannel?((i=new MessageChannel).port1.onmessage=function(t){d(t.data)},n=function(t){i.port2.postMessage(t)}):l&&"onreadystatechange"in l.createElement("script")?(o=l.documentElement,n=function(t){var r=l.createElement("script");r.onreadystatechange=function(){d(t),r.onreadystatechange=null,o.removeChild(r),r=null},o.appendChild(r)}):n=function(t){setTimeout(d,0,t)}:(s="setImmediate$"+Math.random()+"$",c=function(r){r.source===t&&"string"==typeof r.data&&0===r.data.indexOf(s)&&d(+r.data.slice(s.length))},t.addEventListener?t.addEventListener("message",c,!1):t.attachEvent("onmessage",c),n=function(r){t.postMessage(s+r,"*")}),h.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var r=new Array(arguments.length-1),e=0;e<r.length;e++)r[e]=arguments[e+1];var o={callback:t,args:r};return a[f]=o,n(f),f++},h.clearImmediate=p}function p(t){delete a[t]}function d(t){if(u)setTimeout(d,0,t);else{var r=a[t];if(r){u=!0;try{!function(t){var r=t.callback,n=t.args;switch(n.length){case 0:r();break;case 1:r(n[0]);break;case 2:r(n[0],n[1]);break;case 3:r(n[0],n[1],n[2]);break;default:r.apply(e,n)}}(r)}finally{p(t),u=!1}}}}}("undefined"==typeof self?void 0===t?this:t:self)}).call(this,e(1),e(6))},function(t,r){var e,n,o=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function c(t){if(e===setTimeout)return setTimeout(t,0);if((e===i||!e)&&setTimeout)return e=setTimeout,setTimeout(t,0);try{return e(t,0)}catch(r){try{return e.call(null,t,0)}catch(r){return e.call(this,t,0)}}}!function(){try{e="function"==typeof setTimeout?setTimeout:i}catch(t){e=i}try{n="function"==typeof clearTimeout?clearTimeout:s}catch(t){n=s}}();var f,a=[],u=!1,l=-1;function h(){u&&f&&(u=!1,f.length?a=f.concat(a):l=-1,a.length&&p())}function p(){if(!u){var t=c(h);u=!0;for(var r=a.length;r;){for(f=a,a=[];++l<r;)f&&f[l].run();l=-1,r=a.length}f=null,u=!1,function(t){if(n===clearTimeout)return clearTimeout(t);if((n===s||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(t);try{n(t)}catch(r){try{return n.call(null,t)}catch(r){return n.call(this,t)}}}(t)}}function d(t,r){this.fun=t,this.array=r}function y(){}o.nextTick=function(t){var r=new Array(arguments.length-1);if(arguments.length>1)for(var e=1;e<arguments.length;e++)r[e-1]=arguments[e];a.push(new d(t,r)),1!==a.length||u||c(p)},d.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=y,o.addListener=y,o.once=y,o.off=y,o.removeListener=y,o.removeAllListeners=y,o.emit=y,o.prependListener=y,o.prependOnceListener=y,o.listeners=function(t){return[]},o.binding=function(t){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(t){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(t,r,e){},function(t,r,e){},function(t,r,e){"use strict";e.r(r);e(3);var n={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(n.arrayBuffer)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],i=ArrayBuffer.isView||function(t){return t&&o.indexOf(Object.prototype.toString.call(t))>-1};function s(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function c(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var r={next:function(){var r=t.shift();return{done:void 0===r,value:r}}};return n.iterable&&(r[Symbol.iterator]=function(){return r}),r}function a(t){this.map={},t instanceof a?t.forEach(function(t,r){this.append(r,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(r){this.append(r,t[r])},this)}function u(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise(function(r,e){t.onload=function(){r(t.result)},t.onerror=function(){e(t.error)}})}function h(t){var r=new FileReader,e=l(r);return r.readAsArrayBuffer(t),e}function p(t){if(t.slice)return t.slice(0);var r=new Uint8Array(t.byteLength);return r.set(new Uint8Array(t)),r.buffer}function d(){return this.bodyUsed=!1,this._initBody=function(t){var r;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:n.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:n.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:n.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():n.arrayBuffer&&n.blob&&((r=t)&&DataView.prototype.isPrototypeOf(r))?(this._bodyArrayBuffer=p(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):n.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||i(t))?this._bodyArrayBuffer=p(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):n.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n.blob&&(this.blob=function(){var t=u(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(h)}),this.text=function(){var t,r,e,n=u(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=new FileReader,e=l(r),r.readAsText(t),e;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var r=new Uint8Array(t),e=new Array(r.length),n=0;n<r.length;n++)e[n]=String.fromCharCode(r[n]);return e.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n.formData&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}a.prototype.append=function(t,r){t=s(t),r=c(r);var e=this.map[t];this.map[t]=e?e+", "+r:r},a.prototype.delete=function(t){delete this.map[s(t)]},a.prototype.get=function(t){return t=s(t),this.has(t)?this.map[t]:null},a.prototype.has=function(t){return this.map.hasOwnProperty(s(t))},a.prototype.set=function(t,r){this.map[s(t)]=c(r)},a.prototype.forEach=function(t,r){for(var e in this.map)this.map.hasOwnProperty(e)&&t.call(r,this.map[e],e,this)},a.prototype.keys=function(){var t=[];return this.forEach(function(r,e){t.push(e)}),f(t)},a.prototype.values=function(){var t=[];return this.forEach(function(r){t.push(r)}),f(t)},a.prototype.entries=function(){var t=[];return this.forEach(function(r,e){t.push([e,r])}),f(t)},n.iterable&&(a.prototype[Symbol.iterator]=a.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(t,r){var e,n,o=(r=r||{}).body;if(t instanceof b){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,r.headers||(this.headers=new a(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=r.credentials||this.credentials||"same-origin",!r.headers&&this.headers||(this.headers=new a(r.headers)),this.method=(e=r.method||this.method||"GET",n=e.toUpperCase(),y.indexOf(n)>-1?n:e),this.mode=r.mode||this.mode||null,this.signal=r.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function _(t){var r=new FormData;return t.trim().split("&").forEach(function(t){if(t){var e=t.split("="),n=e.shift().replace(/\+/g," "),o=e.join("=").replace(/\+/g," ");r.append(decodeURIComponent(n),decodeURIComponent(o))}}),r}function w(t,r){r||(r={}),this.type="default",this.status=void 0===r.status?200:r.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in r?r.statusText:"OK",this.headers=new a(r.headers),this.url=r.url||"",this._initBody(t)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},d.call(b.prototype),d.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new a(this.headers),url:this.url})},w.error=function(){var t=new w(null,{status:0,statusText:""});return t.type="error",t};var m=[301,302,303,307,308];w.redirect=function(t,r){if(-1===m.indexOf(r))throw new RangeError("Invalid status code");return new w(null,{status:r,headers:{location:t}})};var g=self.DOMException;try{new g}catch(t){(g=function(t,r){this.message=t,this.name=r;var e=Error(t);this.stack=e.stack}).prototype=Object.create(Error.prototype),g.prototype.constructor=g}function T(t,r){return new Promise(function(e,o){var i=new b(t,r);if(i.signal&&i.signal.aborted)return o(new g("Aborted","AbortError"));var s=new XMLHttpRequest;function c(){s.abort()}s.onload=function(){var t,r,n={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",r=new a,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var e=t.split(":"),n=e.shift().trim();if(n){var o=e.join(":").trim();r.append(n,o)}}),r)};n.url="responseURL"in s?s.responseURL:n.headers.get("X-Request-URL");var o="response"in s?s.response:s.responseText;e(new w(o,n))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.onabort=function(){o(new g("Aborted","AbortError"))},s.open(i.method,i.url,!0),"include"===i.credentials?s.withCredentials=!0:"omit"===i.credentials&&(s.withCredentials=!1),"responseType"in s&&n.blob&&(s.responseType="blob"),i.headers.forEach(function(t,r){s.setRequestHeader(r,t)}),i.signal&&(i.signal.addEventListener("abort",c),s.onreadystatechange=function(){4===s.readyState&&i.signal.removeEventListener("abort",c)}),s.send(void 0===i._bodyInit?null:i._bodyInit)})}T.polyfill=!0,self.fetch||(self.fetch=T,self.Headers=a,self.Request=b,self.Response=w);var E=function(){},x={},v=[],B=[];function j(t,r){var e,n,o,i,s=B;for(i=arguments.length;i-- >2;)v.push(arguments[i]);for(r&&null!=r.children&&(v.length||v.push(r.children),delete r.children);v.length;)if((n=v.pop())&&void 0!==n.pop)for(i=n.length;i--;)v.push(n[i]);else"boolean"==typeof n&&(n=null),(o="function"!=typeof t)&&(null==n?n="":"number"==typeof n?n=String(n):"string"!=typeof n&&(o=!1)),o&&e?s[s.length-1]+=n:s===B?s=[n]:s.push(n),e=o;var c=new E;return c.nodeName=t,c.children=s,c.attributes=null==r?void 0:r,c.key=null==r?void 0:r.key,void 0!==x.vnode&&x.vnode(c),c}function A(t,r){for(var e in r)t[e]=r[e];return t}function U(t,r){null!=t&&("function"==typeof t?t(r):t.current=r)}var F="function"==typeof Promise?Promise.resolve().then.bind(Promise.resolve()):setTimeout;var R=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,S=[];function O(t){!t._dirty&&(t._dirty=!0)&&1==S.push(t)&&(x.debounceRendering||F)(k)}function k(){for(var t;t=S.pop();)t._dirty&&Y(t)}function P(t,r){return t.normalizedNodeName===r||t.nodeName.toLowerCase()===r.toLowerCase()}function L(t){var r=A({},t.attributes);r.children=t.children;var e=t.nodeName.defaultProps;if(void 0!==e)for(var n in e)void 0===r[n]&&(r[n]=e[n]);return r}function D(t){var r=t.parentNode;r&&r.removeChild(t)}function I(t,r,e,n,o){if("className"===r&&(r="class"),"key"===r) ;else if("ref"===r)U(e,null),U(n,t);else if("class"!==r||o)if("style"===r){if(n&&"string"!=typeof n&&"string"!=typeof e||(t.style.cssText=n||""),n&&"object"==typeof n){if("string"!=typeof e)for(var i in e)i in n||(t.style[i]="");for(var i in n)t.style[i]="number"==typeof n[i]&&!1===R.test(i)?n[i]+"px":n[i]}}else if("dangerouslySetInnerHTML"===r)n&&(t.innerHTML=n.__html||"");else if("o"==r[0]&&"n"==r[1]){var s=r!==(r=r.replace(/Capture$/,""));r=r.toLowerCase().substring(2),n?e||t.addEventListener(r,M,s):t.removeEventListener(r,M,s),(t._listeners||(t._listeners={}))[r]=n}else if("list"!==r&&"type"!==r&&!o&&r in t){try{t[r]=null==n?"":n}catch(t){}null!=n&&!1!==n||"spellcheck"==r||t.removeAttribute(r)}else{var c=o&&r!==(r=r.replace(/^xlink:?/,""));null==n||!1===n?c?t.removeAttributeNS("http://www.w3.org/1999/xlink",r.toLowerCase()):t.removeAttribute(r):"function"!=typeof n&&(c?t.setAttributeNS("http://www.w3.org/1999/xlink",r.toLowerCase(),n):t.setAttribute(r,n))}else t.className=n||""}function M(t){return this._listeners[t.type](x.event&&x.event(t)||t)}var C=[],H=0,V=!1,W=!1;function q(){for(var t;t=C.shift();)x.afterMount&&x.afterMount(t),t.componentDidMount&&t.componentDidMount()}function G(t,r,e,n,o,i){H++||(V=null!=o&&void 0!==o.ownerSVGElement,W=null!=t&&!("__preactattr_"in t));var s=$(t,r,e,n,i);return o&&s.parentNode!==o&&o.appendChild(s),--H||(W=!1,i||q()),s}function $(t,r,e,n,o){var i=t,s=V;if(null!=r&&"boolean"!=typeof r||(r=""),"string"==typeof r||"number"==typeof r)return t&&void 0!==t.splitText&&t.parentNode&&(!t._component||o)?t.nodeValue!=r&&(t.nodeValue=r):(i=document.createTextNode(r),t&&(t.parentNode&&t.parentNode.replaceChild(i,t),z(t,!0))),i.__preactattr_=!0,i;var c,f,a=r.nodeName;if("function"==typeof a)return function(t,r,e,n){var o=t&&t._component,i=o,s=t,c=o&&t._componentConstructor===r.nodeName,f=c,a=L(r);for(;o&&!f&&(o=o._parentComponent);)f=o.constructor===r.nodeName;o&&f&&(!n||o._component)?(Q(o,a,3,e,n),t=o.base):(i&&!c&&(Z(i),t=s=null),o=J(r.nodeName,a,e),t&&!o.nextBase&&(o.nextBase=t,s=null),Q(o,a,1,e,n),t=o.base,s&&t!==s&&(s._component=null,z(s,!1)));return t}(t,r,e,n);if(V="svg"===a||"foreignObject"!==a&&V,a=String(a),(!t||!P(t,a))&&(c=a,(f=V?document.createElementNS("http://www.w3.org/2000/svg",c):document.createElement(c)).normalizedNodeName=c,i=f,t)){for(;t.firstChild;)i.appendChild(t.firstChild);t.parentNode&&t.parentNode.replaceChild(i,t),z(t,!0)}var u=i.firstChild,l=i.__preactattr_,h=r.children;if(null==l){l=i.__preactattr_={};for(var p=i.attributes,d=p.length;d--;)l[p[d].name]=p[d].value}return!W&&h&&1===h.length&&"string"==typeof h[0]&&null!=u&&void 0!==u.splitText&&null==u.nextSibling?u.nodeValue!=h[0]&&(u.nodeValue=h[0]):(h&&h.length||null!=u)&&function(t,r,e,n,o){var i,s,c,f,a,u=t.childNodes,l=[],h={},p=0,d=0,y=u.length,b=0,_=r?r.length:0;if(0!==y)for(var w=0;w<y;w++){var m=u[w],g=m.__preactattr_,T=_&&g?m._component?m._component.__key:g.key:null;null!=T?(p++,h[T]=m):(g||(void 0!==m.splitText?!o||m.nodeValue.trim():o))&&(l[b++]=m)}if(0!==_)for(var w=0;w<_;w++){f=r[w],a=null;var T=f.key;if(null!=T)p&&void 0!==h[T]&&(a=h[T],h[T]=void 0,p--);else if(d<b)for(i=d;i<b;i++)if(void 0!==l[i]&&(E=s=l[i],v=o,"string"==typeof(x=f)||"number"==typeof x?void 0!==E.splitText:"string"==typeof x.nodeName?!E._componentConstructor&&P(E,x.nodeName):v||E._componentConstructor===x.nodeName)){a=s,l[i]=void 0,i===b-1&&b--,i===d&&d++;break}a=$(a,f,e,n),c=u[w],a&&a!==t&&a!==c&&(null==c?t.appendChild(a):a===c.nextSibling?D(c):t.insertBefore(a,c))}var E,x,v;if(p)for(var w in h)void 0!==h[w]&&z(h[w],!1);for(;d<=b;)void 0!==(a=l[b--])&&z(a,!1)}(i,h,e,n,W||null!=l.dangerouslySetInnerHTML),function(t,r,e){var n;for(n in e)r&&null!=r[n]||null==e[n]||I(t,n,e[n],e[n]=void 0,V);for(n in r)"children"===n||"innerHTML"===n||n in e&&r[n]===("value"===n||"checked"===n?t[n]:e[n])||I(t,n,e[n],e[n]=r[n],V)}(i,r.attributes,l),V=s,i}function z(t,r){var e=t._component;e?Z(e):(null!=t.__preactattr_&&U(t.__preactattr_.ref,null),!1!==r&&null!=t.__preactattr_||D(t),N(t))}function N(t){for(t=t.lastChild;t;){var r=t.previousSibling;z(t,!0),t=r}}var X=[];function J(t,r,e){var n,o=X.length;for(t.prototype&&t.prototype.render?(n=new t(r,e),tt.call(n,r,e)):((n=new tt(r,e)).constructor=t,n.render=K);o--;)if(X[o].constructor===t)return n.nextBase=X[o].nextBase,X.splice(o,1),n;return n}function K(t,r,e){return this.constructor(t,e)}function Q(t,r,e,n,o){t._disable||(t._disable=!0,t.__ref=r.ref,t.__key=r.key,delete r.ref,delete r.key,void 0===t.constructor.getDerivedStateFromProps&&(!t.base||o?t.componentWillMount&&t.componentWillMount():t.componentWillReceiveProps&&t.componentWillReceiveProps(r,n)),n&&n!==t.context&&(t.prevContext||(t.prevContext=t.context),t.context=n),t.prevProps||(t.prevProps=t.props),t.props=r,t._disable=!1,0!==e&&(1!==e&&!1===x.syncComponentUpdates&&t.base?O(t):Y(t,1,o)),U(t.__ref,t))}function Y(t,r,e,n){if(!t._disable){var o,i,s,c=t.props,f=t.state,a=t.context,u=t.prevProps||c,l=t.prevState||f,h=t.prevContext||a,p=t.base,d=t.nextBase,y=p||d,b=t._component,_=!1,w=h;if(t.constructor.getDerivedStateFromProps&&(f=A(A({},f),t.constructor.getDerivedStateFromProps(c,f)),t.state=f),p&&(t.props=u,t.state=l,t.context=h,2!==r&&t.shouldComponentUpdate&&!1===t.shouldComponentUpdate(c,f,a)?_=!0:t.componentWillUpdate&&t.componentWillUpdate(c,f,a),t.props=c,t.state=f,t.context=a),t.prevProps=t.prevState=t.prevContext=t.nextBase=null,t._dirty=!1,!_){o=t.render(c,f,a),t.getChildContext&&(a=A(A({},a),t.getChildContext())),p&&t.getSnapshotBeforeUpdate&&(w=t.getSnapshotBeforeUpdate(u,l));var m,g,T=o&&o.nodeName;if("function"==typeof T){var E=L(o);(i=b)&&i.constructor===T&&E.key==i.__key?Q(i,E,1,a,!1):(m=i,t._component=i=J(T,E,a),i.nextBase=i.nextBase||d,i._parentComponent=t,Q(i,E,0,a,!1),Y(i,1,e,!0)),g=i.base}else s=y,(m=b)&&(s=t._component=null),(y||1===r)&&(s&&(s._component=null),g=G(s,o,a,e||!p,y&&y.parentNode,!0));if(y&&g!==y&&i!==b){var v=y.parentNode;v&&g!==v&&(v.replaceChild(g,y),m||(y._component=null,z(y,!1)))}if(m&&Z(m),t.base=g,g&&!n){for(var B=t,j=t;j=j._parentComponent;)(B=j).base=g;g._component=B,g._componentConstructor=B.constructor}}for(!p||e?C.push(t):_||(t.componentDidUpdate&&t.componentDidUpdate(u,l,w),x.afterUpdate&&x.afterUpdate(t));t._renderCallbacks.length;)t._renderCallbacks.pop().call(t);H||n||q()}}function Z(t){x.beforeUnmount&&x.beforeUnmount(t);var r=t.base;t._disable=!0,t.componentWillUnmount&&t.componentWillUnmount(),t.base=null;var e=t._component;e?Z(e):r&&(null!=r.__preactattr_&&U(r.__preactattr_.ref,null),t.nextBase=r,D(r),X.push(t),N(r)),U(t.__ref,null)}function tt(t,r){this._dirty=!0,this.context=r,this.props=t,this.state=this.state||{},this._renderCallbacks=[]}function rt(t,r,e){return G(e,t,{},!1,r,!1)}A(tt.prototype,{setState:function(t,r){this.prevState||(this.prevState=this.state),this.state=A(A({},this.state),"function"==typeof t?t(this.state,this.props):t),r&&this._renderCallbacks.push(r),O(this)},forceUpdate:function(t){t&&this._renderCallbacks.push(t),Y(this,2)},render:function(){}});e(7),e(8);function et(t){var r=t.name,e=t.length;return j("li",null,j("a",{href:r},"/",r)," ",j("sup",null,e?"".concat(e,"x"):"object"))}function nt(t){var r=t.db;return j("ul",null,Object.keys(r).map(function(t){return j(et,{name:t,length:Array.isArray(r[t])&&r[t].length})}))}function ot(){return j("p",null,"No resources found")}function it(t){var r=t.db;return j("div",null,j("h4",null,"Resources"),Object.keys(r).length?j(nt,{db:r}):j(ot,null))}function st(t){var r=t.customRoutes,e=Object.keys(r);if(e.length)return j("div",null,j("h4",null,"Custom Routes"),j("table",null,e.map(function(t){return j("tr",null,j("td",null,t),j("td",null,"β‡’ ",r[t]))})))}window.fetch("db").then(function(t){return t.json()}).then(function(t){return rt(j(it,{db:t}),document.getElementById("resources"))}),window.fetch("__rules").then(function(t){return t.json()}).then(function(t){rt(j(st,{customRoutes:t}),document.getElementById("custom-routes"))})}]);

@@ -1,3 +0,6 @@

'use strict';
#!/usr/bin/env node
"use strict";
require('please-upgrade-node')(require('../../package.json'));
require('./')();

@@ -1,10 +0,15 @@

'use strict';
"use strict";
const updateNotifier = require('update-notifier');
const yargs = require('yargs');
const run = require('./run');
const pkg = require('../../package.json');
module.exports = function () {
updateNotifier({ pkg }).notify();
updateNotifier({
pkg
}).notify();

@@ -11,0 +16,0 @@ const argv = yargs.config('config').usage('$0 [options] <source>').options({

@@ -1,25 +0,28 @@

'use strict';
"use strict";
const fs = require('fs');
const path = require('path');
const jph = require('json-parse-helpfulerror');
const _ = require('lodash');
const chalk = require('chalk');
const enableDestroy = require('server-destroy');
const pause = require('connect-pause');
const is = require('./utils/is');
const load = require('./utils/load');
const jsonServer = require('../server');
const example = {
posts: [{ id: 1, title: 'json-server', author: 'typicode' }],
comments: [{ id: 1, body: 'some comment', postId: 1 }],
profile: { name: 'typicode' }
};
function prettyPrint(argv, object, rules) {
const root = `http://${argv.host}:${argv.port}`;
console.log();
console.log(chalk.bold(' Resources'));
for (let prop in object) {

@@ -32,2 +35,3 @@ console.log(` ${root}/${prop}`);

console.log(chalk.bold(' Other routes'));
for (var rule in rules) {

@@ -44,17 +48,8 @@ console.log(` ${rule} -> ${rules[rule]}`);

function createApp(source, object, routes, middlewares, argv) {
function createApp(db, routes, middlewares, argv) {
const app = jsonServer.create();
let router;
const foreignKeySuffix = argv.foreignKeySuffix;
try {
router = jsonServer.router(is.JSON(source) ? source : object, foreignKeySuffix ? { foreignKeySuffix } : undefined);
} catch (e) {
console.log();
console.error(chalk.red(e.message.replace(/^/gm, ' ')));
process.exit(1);
}
let router = jsonServer.router(db, foreignKeySuffix ? {
foreignKeySuffix
} : undefined);
const defaultsOpts = {

@@ -91,3 +86,2 @@ logger: !argv.quiet,

app.use(router);
return app;

@@ -104,5 +98,5 @@ }

process.exit(1);
}
} // noop log fn
// noop log fn
if (argv.quiet) {

@@ -117,26 +111,17 @@ console.log = () => {};

console.log();
// Be nice and create a default db.json if it doesn't exist
if (is.JSON(source) && !fs.existsSync(source)) {
console.log(chalk.yellow(` Oops, ${source} doesn't seem to exist`));
console.log(chalk.yellow(` Creating ${source} with some default data`));
console.log();
fs.writeFileSync(source, JSON.stringify(example, null, 2));
}
console.log(chalk.gray(' Loading', source));
server = undefined; // create db and load object, JSON file, JS or HTTP database
// Load JSON, JS or HTTP database
load(source, (err, data) => {
if (err) throw err;
return load(source).then(db => {
// Load additional routes
let routes;
if (argv.routes) {
console.log(chalk.gray(' Loading', argv.routes));
routes = JSON.parse(fs.readFileSync(argv.routes));
}
} // Load middlewares
// Load middlewares
let middlewares;
if (argv.middlewares) {

@@ -147,28 +132,27 @@ middlewares = argv.middlewares.map(function (m) {

});
}
} // Done
// Done
console.log(chalk.gray(' Done'));
// Create app and server
app = createApp(source, data, routes, middlewares, argv);
server = app.listen(argv.port, argv.host);
console.log(chalk.gray(' Done')); // Create app and server
// Enhance with a destroy function
enableDestroy(server);
app = createApp(db, routes, middlewares, argv);
server = app.listen(argv.port, argv.host); // Enhance with a destroy function
// Display server informations
prettyPrint(argv, data, routes);
enableDestroy(server); // Display server informations
cb && cb();
prettyPrint(argv, db.getState(), routes); // Catch and handle any error occurring in the server process
process.on('uncaughtException', error => {
if (error.errno === 'EADDRINUSE') console.log(chalk.red(`Cannot bind to the port ${error.port}. Please specify another port number either through --port argument or through the json-server.json configuration file`));else console.log('Some error occurred', error);
process.exit(1);
});
});
}
} // Start server
// Start server
start(() => {
start().then(() => {
// Snapshot
console.log(chalk.gray(' Type s + enter at any time to create a snapshot of the database'));
console.log(chalk.gray(' Type s + enter at any time to create a snapshot of the database')); // Support nohup
// https://github.com/typicode/json-server/issues/221
// Support nohup
// https://github.com/typicode/json-server/issues/221
process.stdin.on('error', () => {

@@ -187,15 +171,12 @@ console.log(` Error, can't read from stdin`);

}
});
}); // Watch files
// Watch files
if (argv.watch) {
console.log(chalk.gray(' Watching...'));
console.log();
const source = argv._[0];
const source = argv._[0]; // Can't watch URL
// Can't watch URL
if (is.URL(source)) throw new Error("Can't watch URL");
if (is.URL(source)) throw new Error("Can't watch URL"); // Watch .js or .json file
// Since lowdb uses atomic writing, directory is watched instead of file
// Watch .js or .json file
// Since lowdb uses atomic writing, directory is watched instead of file
const watchedDir = path.dirname(source);

@@ -208,7 +189,10 @@ let readError = false;

const watchedFile = path.resolve(watchedDir, file);
if (watchedFile === path.resolve(source)) {
if (is.JSON(watchedFile)) {
if (is.FILE(watchedFile)) {
let obj;
try {
obj = jph.parse(fs.readFileSync(watchedFile));
if (readError) {

@@ -223,10 +207,10 @@ console.log(chalk.green(` Read error has been fixed :)`));

return;
}
} // Compare .json file content with in memory database
// Compare .json file content with in memory database
const isDatabaseDifferent = !_.isEqual(obj, app.db.getState());
if (isDatabaseDifferent) {
console.log(chalk.gray(` ${source} has changed, reloading...`));
server && server.destroy();
start();
server && server.destroy(() => start());
}

@@ -236,5 +220,4 @@ }

}
});
}); // Watch routes
// Watch routes
if (argv.routes) {

@@ -245,6 +228,6 @@ const watchedDir = path.dirname(argv.routes);

const watchedFile = path.resolve(watchedDir, file);
if (watchedFile === path.resolve(argv.routes)) {
console.log(chalk.gray(` ${argv.routes} has changed, reloading...`));
server && server.destroy();
start();
server && server.destroy(() => start());
}

@@ -255,3 +238,6 @@ }

}
}).catch(err => {
console.log(err);
process.exit(1);
});
};
"use strict";
module.exports = {
JSON,
FILE,
JS,

@@ -9,3 +9,3 @@ URL

function JSON(s) {
function FILE(s) {
return !URL(s) && /\.json$/.test(s);

@@ -19,4 +19,3 @@ }

function URL(s) {
return (/^(http|https):/.test(s)
);
return /^(http|https):/.test(s);
}

@@ -1,41 +0,74 @@

'use strict';
"use strict";
const fs = require('fs');
const path = require('path');
const request = require('request');
const low = require('lowdb');
const fileAsync = require('lowdb/lib/storages/file-async');
const FileAsync = require('lowdb/adapters/FileAsync');
const Memory = require('lowdb/adapters/Memory');
const is = require('./is');
module.exports = function (source, cb) {
if (is.URL(source)) {
// Load remote data
const opts = {
url: source,
json: true
};
const chalk = require('chalk');
request(opts, (err, response) => {
if (err) return cb(err);
cb(null, response.body);
});
} else if (is.JS(source)) {
// Clear cache
const filename = path.resolve(source);
delete require.cache[filename];
const dataFn = require(filename);
const example = {
posts: [{
id: 1,
title: 'json-server',
author: 'typicode'
}],
comments: [{
id: 1,
body: 'some comment',
postId: 1
}],
profile: {
name: 'typicode'
}
};
if (typeof dataFn !== 'function') {
throw new Error('The database is a JavaScript file but the export is not a function.');
module.exports = function (source) {
return new Promise((resolve, reject) => {
if (is.FILE(source)) {
if (!fs.existsSync(source)) {
console.log(chalk.yellow(` Oops, ${source} doesn't seem to exist`));
console.log(chalk.yellow(` Creating ${source} with some default data`));
console.log();
fs.writeFileSync(source, JSON.stringify(example, null, 2));
}
resolve(low(new FileAsync(source)));
} else if (is.URL(source)) {
// Load remote data
const opts = {
url: source,
json: true
};
request(opts, (err, response) => {
if (err) return reject(err);
resolve(low(new Memory()).setState(response.body));
});
} else if (is.JS(source)) {
// Clear cache
const filename = path.resolve(source);
delete require.cache[filename];
const dataFn = require(filename);
if (typeof dataFn !== 'function') {
throw new Error('The database is a JavaScript file but the export is not a function.');
} // Run dataFn to generate data
const data = dataFn();
resolve(low(new Memory()).setState(data));
} else {
throw new Error(`Unsupported source ${source}`);
}
// Run dataFn to generate data
const data = dataFn();
cb(null, data);
} else if (is.JSON(source)) {
// Load JSON using lowdb
const data = low(source, { storage: fileAsync }).getState();
cb(null, data);
} else {
throw new Error(`Unsupported source ${source}`);
}
});
};

@@ -1,12 +0,12 @@

'use strict';
"use strict";
require('promise-polyfill/src/polyfill');
require("promise-polyfill/src/polyfill");
require('whatwg-fetch');
require("whatwg-fetch");
var _preact = require('preact');
var _preact = require("preact");
require('milligram/dist/milligram.css');
require("milligram/dist/milligram.css");
require('./style.css');
require("./style.css");

@@ -16,19 +16,5 @@ function ResourceItem(_ref) {

length = _ref.length;
return (0, _preact.h)(
'li',
null,
(0, _preact.h)(
'a',
{ href: name },
'/',
name
),
' ',
(0, _preact.h)(
'sup',
null,
length ? length + 'x' : 'object'
)
);
return (0, _preact.h)("li", null, (0, _preact.h)("a", {
href: name
}, "/", name), " ", (0, _preact.h)("sup", null, length ? "".concat(length, "x") : 'object'));
}

@@ -38,21 +24,12 @@

var db = _ref2.db;
return (0, _preact.h)(
'ul',
null,
Object.keys(db).map(function (name) {
return (0, _preact.h)(ResourceItem, {
name: name,
length: Array.isArray(db[name]) && db[name].length
});
})
);
return (0, _preact.h)("ul", null, Object.keys(db).map(function (name) {
return (0, _preact.h)(ResourceItem, {
name: name,
length: Array.isArray(db[name]) && db[name].length
});
}));
}
function NoResources() {
return (0, _preact.h)(
'p',
null,
'No resources found'
);
return (0, _preact.h)("p", null, "No resources found");
}

@@ -62,13 +39,5 @@

var db = _ref3.db;
return (0, _preact.h)(
'div',
null,
(0, _preact.h)(
'h4',
null,
'Resources'
),
Object.keys(db).length ? (0, _preact.h)(ResourceList, { db: db }) : (0, _preact.h)(NoResources, null)
);
return (0, _preact.h)("div", null, (0, _preact.h)("h4", null, "Resources"), Object.keys(db).length ? (0, _preact.h)(ResourceList, {
db: db
}) : (0, _preact.h)(NoResources, null));
}

@@ -79,3 +48,5 @@

}).then(function (db) {
return (0, _preact.render)((0, _preact.h)(ResourcesBlock, { db: db }), document.getElementById('resources'));
return (0, _preact.render)((0, _preact.h)(ResourcesBlock, {
db: db
}), document.getElementById('resources'));
});

@@ -85,35 +56,8 @@

var customRoutes = _ref4.customRoutes;
var rules = Object.keys(customRoutes);
var rules = Object.keys(customRoutes);
if (rules.length) {
return (0, _preact.h)(
'div',
null,
(0, _preact.h)(
'h4',
null,
'Custom Routes'
),
(0, _preact.h)(
'table',
null,
rules.map(function (rule) {
return (0, _preact.h)(
'tr',
null,
(0, _preact.h)(
'td',
null,
rule
),
(0, _preact.h)(
'td',
null,
'\u21E2 ',
customRoutes[rule]
)
);
})
)
);
return (0, _preact.h)("div", null, (0, _preact.h)("h4", null, "Custom Routes"), (0, _preact.h)("table", null, rules.map(function (rule) {
return (0, _preact.h)("tr", null, (0, _preact.h)("td", null, rule), (0, _preact.h)("td", null, "\u21E2 ", customRoutes[rule]));
})));
}

@@ -125,3 +69,5 @@ }

}).then(function (customRoutes) {
(0, _preact.render)((0, _preact.h)(CustomRoutesBlock, { customRoutes: customRoutes }), document.getElementById('custom-routes'));
(0, _preact.render)((0, _preact.h)(CustomRoutesBlock, {
customRoutes: customRoutes
}), document.getElementById('custom-routes'));
});

@@ -1,5 +0,10 @@

'use strict';
"use strict";
const bodyParser = require('body-parser');
module.exports = [bodyParser.json({ limit: '10mb', extended: false }), bodyParser.urlencoded({ extended: false })];
module.exports = [bodyParser.json({
limit: '10mb',
extended: false
}), bodyParser.urlencoded({
extended: false
})];

@@ -1,11 +0,19 @@

'use strict';
"use strict";
const fs = require('fs');
const path = require('path');
const express = require('express');
const logger = require('morgan');
const cors = require('cors');
const compression = require('compression');
const errorhandler = require('errorhandler');
const objectAssign = require('object-assign');
const bodyParser = require('./body-parser');

@@ -17,15 +25,18 @@

const staticDir = fs.existsSync(userDir) ? userDir : defaultDir;
opts = objectAssign({
logger: true,
static: staticDir
}, opts);
const arr = []; // Compress all requests
opts = objectAssign({ logger: true, static: staticDir }, opts);
const arr = [];
// Compress all requests
if (!opts.noGzip) {
arr.push(compression());
}
} // Enable CORS for all the requests, including static files
// Enable CORS for all the requests, including static files
if (!opts.noCors) {
arr.push(cors({ origin: true, credentials: true }));
arr.push(cors({
origin: true,
credentials: true
}));
}

@@ -36,8 +47,7 @@

arr.push(errorhandler());
}
} // Serve static files
// Serve static files
arr.push(express.static(opts.static));
// Logger
arr.push(express.static(opts.static)); // Logger
if (opts.logger) {

@@ -47,6 +57,6 @@ arr.push(logger('dev', {

}));
}
} // No cache for IE
// https://support.microsoft.com/en-us/kb/234067
// No cache for IE
// https://support.microsoft.com/en-us/kb/234067
arr.push((req, res, next) => {

@@ -57,5 +67,4 @@ res.header('Cache-Control', 'no-cache');

next();
});
}); // Read-only
// Read-only
if (opts.readOnly) {

@@ -69,5 +78,5 @@ arr.push((req, res, next) => {

});
}
} // Add middlewares
// Add middlewares
if (opts.bodyParser) {

@@ -74,0 +83,0 @@ arr.push(bodyParser);

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -3,0 +3,0 @@ const express = require('express');

@@ -1,4 +0,5 @@

'use strict';
"use strict";
const nanoid = require('nanoid');
const pluralize = require('pluralize');

@@ -9,9 +10,12 @@

createId,
deepQuery
deepQuery // Returns document ids that have unsatisfied relations
// Example: a comment that references a post that doesn't exist
// Returns document ids that have unsatisfied relations
// Example: a comment that references a post that doesn't exist
};function getRemovable(db, opts) {
};
function getRemovable(db, opts) {
const _ = this;
const removable = [];
_.each(db, (coll, collName) => {

@@ -23,9 +27,13 @@ _.each(coll, doc => {

// Example postId -> posts
const refName = pluralize.plural(key.replace(new RegExp(`${opts.foreignKeySuffix}$`), ''));
// Test if table exists
const refName = pluralize.plural(key.replace(new RegExp(`${opts.foreignKeySuffix}$`), '')); // Test if table exists
if (db[refName]) {
// Test if references is defined in table
const ref = _.getById(db[refName], value);
if (_.isUndefined(ref)) {
removable.push({ name: collName, id: doc.id });
removable.push({
name: collName,
id: doc.id
});
}

@@ -39,15 +47,17 @@ }

return removable;
}
} // Return incremented id or uuid
// Used to override lodash-id's createId with utils.createId
// Return incremented id or uuid
// Used to override lodash-id's createId with utils.createId
function createId(coll) {
const _ = this;
const idProperty = _.__id();
if (_.isEmpty(coll)) {
return 1;
} else {
let id = _(coll).maxBy(idProperty)[idProperty];
let id = _(coll).maxBy(idProperty)[idProperty]; // Increment integer id or generate string id
// Increment integer id or generate string id
return _.isFinite(id) ? ++id : nanoid(7);

@@ -59,2 +69,3 @@ }

const _ = this;
if (value && q) {

@@ -61,0 +72,0 @@ if (_.isArray(value)) {

@@ -1,4 +0,5 @@

'use strict';
"use strict";
const express = require('express');
const rewrite = require('express-urlrewrite');

@@ -8,12 +9,9 @@

const router = express.Router();
router.get('/__rules', (req, res) => {
res.json(routes);
});
Object.keys(routes).forEach(key => {
router.use(rewrite(key, routes[key]));
});
return router;
};

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -9,4 +9,5 @@ const pause = require('connect-pause');

const _delay = !isNaN(parseFloat(req.query._delay)) ? parseFloat(req.query._delay) : 1;
delete req.query._delay;
pause(_delay)(req, res, next);
};

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -10,4 +10,3 @@ const url = require('url');

});
return `${root}${req.originalUrl}`;
};

@@ -1,61 +0,68 @@

'use strict';
"use strict";
const express = require('express');
const methodOverride = require('method-override');
const _ = require('lodash');
const lodashId = require('lodash-id');
const low = require('lowdb');
const fileAsync = require('lowdb/lib/storages/file-async');
const Memory = require('lowdb/adapters/Memory');
const FileAsync = require('lowdb/adapters/FileAsync');
const bodyParser = require('../body-parser');
const validateData = require('./validate-data');
const plural = require('./plural');
const nested = require('./nested');
const singular = require('./singular');
const mixins = require('../mixins');
module.exports = (source, opts = { foreignKeySuffix: 'Id' }) => {
// Create router
const router = express.Router();
module.exports = (db, opts = {
foreignKeySuffix: 'Id',
_isFake: false
}) => {
if (typeof db === 'string') {
db = low(new FileAsync(db));
} else if (!_.has(db, '__chain__') || !_.has(db, '__wrapped__')) {
db = low(new Memory()).setState(db);
} // Create router
// Add middlewares
const router = express.Router(); // Add middlewares
router.use(methodOverride());
router.use(bodyParser);
validateData(db.getState()); // Add lodash-id methods to db
// Create database
let db;
if (_.isObject(source)) {
db = low();
db.setState(source);
} else {
db = low(source, { storage: fileAsync });
}
db._.mixin(lodashId); // Add specific mixins
validateData(db.getState());
// Add lodash-id methods to db
db._.mixin(lodashId);
db._.mixin(mixins); // Expose database
// Add specific mixins
db._.mixin(mixins);
// Expose database
router.db = db;
router.db = db; // Expose render
// Expose render
router.render = (req, res) => {
res.jsonp(res.locals.data);
};
}; // GET /db
// GET /db
router.get('/db', (req, res) => {
res.jsonp(db.getState());
});
}); // Handle /:parent/:parentId/:resource
// Handle /:parent/:parentId/:resource
router.use(nested(opts));
router.use(nested(opts)); // Create routes
// Create routes
db.forEach((value, key) => {
if (_.isPlainObject(value)) {
router.use(`/${key}`, singular(db, key));
router.use(`/${key}`, singular(db, key, opts));
return;

@@ -69,12 +76,9 @@ }

var sourceMessage = '';
if (!_.isObject(source)) {
sourceMessage = `in ${source}`;
}
var sourceMessage = ''; // if (!_.isObject(source)) {
// sourceMessage = `in ${source}`
// }
const msg = `Type of "${key}" (${typeof value}) ${sourceMessage} is not supported. ` + `Use objects or arrays of objects.`;
throw new Error(msg);
}).value();
router.use((req, res) => {

@@ -88,3 +92,2 @@ if (!res.locals.data) {

});
router.use((err, req, res, next) => {

@@ -94,4 +97,3 @@ console.error(err.stack);

});
return router;
};

@@ -1,5 +0,7 @@

'use strict';
"use strict";
const express = require('express');
const pluralize = require('pluralize');
const delay = require('./delay');

@@ -9,5 +11,4 @@

const router = express.Router();
router.use(delay);
router.use(delay); // Rewrite URL (/:resource/:id/:nested -> /:nested) and request query
// Rewrite URL (/:resource/:id/:nested -> /:nested) and request query
function get(req, res, next) {

@@ -18,5 +19,5 @@ const prop = pluralize.singular(req.params.resource);

next();
}
} // Rewrite URL (/:resource/:id/:nested -> /:nested) and request body
// Rewrite URL (/:resource/:id/:nested -> /:nested) and request body
function post(req, res, next) {

@@ -23,0 +24,0 @@ const prop = pluralize.singular(req.params.resource);

@@ -1,9 +0,19 @@

'use strict';
"use strict";
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const express = require('express');
const _ = require('lodash');
const pluralize = require('pluralize');
const write = require('./write');
const getFullURL = require('./get-full-url');
const utils = require('../utils');
const delay = require('./delay');

@@ -14,5 +24,4 @@

const router = express.Router();
router.use(delay);
router.use(delay); // Embed function used in GET /name and GET /name/id
// Embed function used in GET /name and GET /name/id
function embed(resource, e) {

@@ -27,8 +36,9 @@ e && [].concat(e).forEach(externalResource => {

});
}
} // Expand function used in GET /name and GET /name/id
// Expand function used in GET /name and GET /name/id
function expand(resource, e) {
e && [].concat(e).forEach(innerResource => {
const plural = pluralize(innerResource);
if (db.get(plural).value()) {

@@ -39,5 +49,3 @@ const prop = `${innerResource}${opts.foreignKeySuffix}`;

});
}
// GET /name
} // GET /name
// GET /name?q=

@@ -48,8 +56,9 @@ // GET /name?attr=&attr=

// GET /name?_embed=&_expand=
function list(req, res, next) {
// Resource chain
let chain = db.get(name);
let chain = db.get(name); // Remove q, _start, _end, ... from req.query to avoid filtering using those
// parameters
// Remove q, _start, _end, ... from req.query to avoid filtering using those
// parameters
let q = req.query.q;

@@ -71,11 +80,12 @@ let _start = req.query._start;

delete req.query._embed;
delete req.query._expand;
delete req.query._expand; // Automatically delete query parameters that can't be found
// in the database
// Automatically delete query parameters that can't be found
// in the database
Object.keys(req.query).forEach(query => {
const arr = db.get(name).value();
for (let i in arr) {
if (_.has(arr[i], query) || query === 'callback' || query === '_' || /_lte$/.test(query) || /_gte$/.test(query) || /_ne$/.test(query) || /_like$/.test(query)) return;
}
delete req.query[query];

@@ -91,6 +101,6 @@ });

q = q.toLowerCase();
chain = chain.filter(obj => {
for (let key in obj) {
const value = obj[key];
if (db._.deepQuery(value, q)) {

@@ -109,3 +119,2 @@ return true;

const arr = [].concat(req.query[key]);
chain = chain.filter(element => {

@@ -116,8 +125,8 @@ return arr.map(function (value) {

const isLike = /_like$/.test(key);
const path = key.replace(/(_lte|_gte|_ne|_like)$/, '');
// get item value based on path
const path = key.replace(/(_lte|_gte|_ne|_like)$/, ''); // get item value based on path
// i.e post.title -> 'foo'
const elementValue = _.get(element, path);
// Prevent toString() failing on undefined or null values
const elementValue = _.get(element, path); // Prevent toString() failing on undefined or null values
if (elementValue === undefined || elementValue === null) {

@@ -129,3 +138,2 @@ return;

const isLowerThan = /_gte$/.test(key);
return isLowerThan ? value <= elementValue : value >= elementValue;

@@ -142,12 +150,13 @@ } else if (isDifferent) {

}
});
}); // Sort
// Sort
if (_sort) {
const _sortSet = _sort.split(',');
const _orderSet = (_order || '').split(',').map(s => s.toLowerCase());
chain = chain.orderBy(_sortSet, _orderSet);
}
} // Slice result
// Slice result
if (_end || _limit || _page) {

@@ -192,5 +201,5 @@ res.setHeader('X-Total-Count', chain.size());

chain = chain.slice(_start, _start + _limit);
}
} // embed and expand
// embed and expand
chain = chain.cloneDeep().forEach(function (element) {

@@ -200,9 +209,8 @@ embed(element, _embed);

});
res.locals.data = chain.value();
next();
}
} // GET /name/:id
// GET /name/:id?_embed=&_expand
// GET /name/:id
// GET /name/:id?_embed=&_expand
function show(req, res, next) {

@@ -215,12 +223,10 @@ const _embed = req.query._embed;

// Clone resource to avoid making changes to the underlying object
const clone = _.cloneDeep(resource);
// Embed other resources based on resource id
const clone = _.cloneDeep(resource); // Embed other resources based on resource id
// /posts/1?_embed=comments
embed(clone, _embed);
// Expand inner resources based on id
embed(clone, _embed); // Expand inner resources based on id
// /posts/1?_expand=user
expand(clone, _expand);
res.locals.data = clone;

@@ -230,26 +236,45 @@ }

next();
}
} // POST /name
// POST /name
function create(req, res, next) {
const resource = db.get(name).insert(req.body).value();
let resource;
if (opts._isFake) {
const id = db.get(name).createId().value();
resource = _objectSpread({}, req.body, {
id
});
} else {
resource = db.get(name).insert(req.body).value();
}
res.setHeader('Access-Control-Expose-Headers', 'Location');
res.location(`${getFullURL(req)}/${resource.id}`);
res.status(201);
res.locals.data = resource;
next();
}
} // PUT /name/:id
// PATCH /name/:id
// PUT /name/:id
// PATCH /name/:id
function update(req, res, next) {
const id = req.params.id;
let chain = db.get(name);
let resource;
chain = req.method === 'PATCH' ? chain.updateById(id, req.body) : chain.replaceById(id, req.body);
if (opts._isFake) {
resource = db.get(name).getById(id).value();
const resource = chain.value();
if (req.method === 'PATCH') {
resource = _objectSpread({}, resource, req.body);
} else {
resource = _objectSpread({}, req.body, {
id: resource.id
});
}
} else {
let chain = db.get(name);
chain = req.method === 'PATCH' ? chain.updateById(id, req.body) : chain.replaceById(id, req.body);
resource = chain.value();
}

@@ -261,14 +286,20 @@ if (resource) {

next();
}
} // DELETE /name/:id
// DELETE /name/:id
function destroy(req, res, next) {
const resource = db.get(name).removeById(req.params.id).value();
let resource;
// Remove dependents documents
const removable = db._.getRemovable(db.getState(), opts);
removable.forEach(item => {
db.get(item.name).removeById(item.id).value();
});
if (opts._isFake) {
resource = db.get(name).value();
} else {
resource = db.get(name).removeById(req.params.id).value(); // Remove dependents documents
const removable = db._.getRemovable(db.getState(), opts);
removable.forEach(item => {
db.get(item.name).removeById(item.id).value();
});
}
if (resource) {

@@ -282,8 +313,5 @@ res.locals.data = {};

const w = write(db);
router.route('/').get(list).post(create, w);
router.route('/:id').get(show).put(update, w).patch(update, w).delete(destroy, w);
return router;
};

@@ -1,9 +0,16 @@

'use strict';
"use strict";
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const express = require('express');
const write = require('./write');
const getFullURL = require('./get-full-url');
const delay = require('./delay');
module.exports = (db, name) => {
module.exports = (db, name, opts) => {
const router = express.Router();

@@ -18,8 +25,11 @@ router.use(delay);

function create(req, res, next) {
db.set(name, req.body).value();
res.locals.data = db.get(name).value();
if (opts._isFake) {
res.locals.data = req.body;
} else {
db.set(name, req.body).value();
res.locals.data = db.get(name).value();
}
res.setHeader('Access-Control-Expose-Headers', 'Location');
res.location(`${getFullURL(req)}`);
res.status(201);

@@ -30,9 +40,19 @@ next();

function update(req, res, next) {
if (req.method === 'PUT') {
db.set(name, req.body).value();
if (opts._isFake) {
if (req.method === 'PUT') {
res.locals.data = req.body;
} else {
const resource = db.get(name).value();
res.locals.data = _objectSpread({}, resource, req.body);
}
} else {
db.get(name).assign(req.body).value();
if (req.method === 'PUT') {
db.set(name, req.body).value();
} else {
db.get(name).assign(req.body).value();
}
res.locals.data = db.get(name).value();
}
res.locals.data = db.get(name).value();
next();

@@ -42,6 +62,4 @@ }

const w = write(db);
router.route('/').get(show).post(create, w).put(update, w).patch(update, w);
return router;
};

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -3,0 +3,0 @@ const _ = require('lodash');

@@ -11,4 +11,4 @@ "use strict";

var end = page * perPage;
obj.items = array.slice(start, end);
obj.items = array.slice(start, end);
if (obj.items.length === 0) {

@@ -15,0 +15,0 @@ return obj;

{
"name": "json-server",
"version": "0.14.0",
"version": "0.14.1",
"description": "Serves JSON files through REST routes.",
"main": "./lib/server/index.js",
"bin": "./bin/index.js",
"bin": "./lib/cli/bin.js",
"directories": {

@@ -24,66 +24,70 @@ "test": "test"

"chalk": "^2.4.1",
"compression": "^1.7.2",
"compression": "^1.7.3",
"connect-pause": "^0.1.1",
"cors": "^2.8.4",
"cors": "^2.8.5",
"errorhandler": "^1.2.0",
"express": "^4.16.3",
"express": "^4.16.4",
"express-urlrewrite": "^1.2.0",
"json-parse-helpfulerror": "^1.0.3",
"lodash": "^4.17.10",
"lodash": "^4.17.11",
"lodash-id": "^0.14.0",
"lowdb": "^0.15.0",
"method-override": "^2.3.10",
"morgan": "^1.9.0",
"nanoid": "^1.0.2",
"lowdb": "^1.0.0",
"method-override": "^3.0.0",
"morgan": "^1.9.1",
"nanoid": "^2.0.0",
"object-assign": "^4.0.1",
"please-upgrade-node": "^3.0.2",
"please-upgrade-node": "^3.1.1",
"pluralize": "^7.0.0",
"request": "^2.87.0",
"request": "^2.88.0",
"server-destroy": "^1.0.1",
"update-notifier": "^2.5.0",
"yargs": "^10.1.2"
"yargs": "^12.0.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/node": "^7.2.2",
"@babel/plugin-syntax-jsx": "^7.2.0",
"@babel/plugin-transform-react-jsx": "^7.2.0",
"@babel/plugin-transform-regenerator": "^7.0.0",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.2.3",
"@babel/register": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-loader": "^8.0.4",
"babel-preset-preact": "^1.1.0",
"babel-register": "^6.26.0",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"cross-env": "^5.1.6",
"css-loader": "^0.28.11",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-config-standard": "^11.0.0",
"cross-env": "^5.2.0",
"css-loader": "^1.0.1",
"eslint": "^5.11.0",
"eslint-config-prettier": "^3.3.0",
"eslint-config-standard": "^12.0.0",
"eslint-config-standard-preact": "^1.1.6",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-react": "^7.8.2",
"eslint-plugin-standard": "^3.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-react": "^7.10.0",
"eslint-plugin-standard": "^4.0.0",
"html-webpack-plugin": "^3.2.0",
"husky": "^1.0.0-rc.8",
"jest": "^23.1.0",
"husky": "^1.2.1",
"jest": "^23.6.0",
"markdown-toc": "^1.2.0",
"milligram": "^1.3.0",
"mini-css-extract-plugin": "^0.4.0",
"mini-css-extract-plugin": "^0.4.5",
"mkdirp": "^0.5.1",
"npm-run-all": "^4.1.3",
"os-tmpdir": "^1.0.1",
"pkg-ok": "^2.2.0",
"preact": "^8.2.9",
"prettier": "^1.13.2",
"promise-polyfill": "^7.1.2",
"npm-run-all": "^4.1.5",
"os-tmpdir": "^2.0.0",
"pkg-ok": "^2.3.1",
"preact": "^8.4.2",
"prettier": "^1.15.3",
"promise-polyfill": "^8.1.0",
"rimraf": "^2.6.2",
"server-ready": "^0.3.1",
"standard": "^10.0.3",
"supertest": "^3.1.0",
"supertest": "^3.3.0",
"temp-write": "^3.4.0",
"webpack": "^4.10.2",
"webpack-cli": "^2.1.4",
"whatwg-fetch": "^2.0.4"
"webpack": "^4.28.2",
"webpack-cli": "^3.1.2",
"whatwg-fetch": "^3.0.0"
},

@@ -123,3 +127,6 @@ "repository": {

}
},
"jest": {
"testURL": "http://localhost/"
}
}

@@ -13,14 +13,18 @@ # JSON Server [![](https://travis-ci.org/typicode/json-server.svg?branch=master)](https://travis-ci.org/typicode/json-server) [![](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server)

* :hotel: [hotel - developer tool with local .localhost domain and https out of the box](https://github.com/typicode/hotel)
* :atom_symbol: [react-fake-props - generate fake props for your React tests (Jest, Enzyme, ...)](https://github.com/typicode/react-fake-props)
* :heartpulse: [Patreon page - if you want to support JSON Server or my other projects](https://www.patreon.com/typicode)
* βš›οΈ πŸ”§ [react-lodash - lodash as React components](https://github.com/typicode/react-lodash)
<a href="https://www.patreon.com/typicode">
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
</a>
## Sponsors
__[[Become a sponsor and have your company logo here]](https://patreon.com/typicode)__
## Table of contents
<details>
<!-- toc -->
- [Sponsorship](#sponsorship)
- [Example](#example)
- [Install](#install)
- [Getting started](#getting-started)
- [Routes](#routes)

@@ -65,8 +69,12 @@ * [Plural routes](#plural-routes)

</details>
## Getting started
## Example
Install JSON Server
Create a `db.json` file
```
npm install -g json-server
```
Create a `db.json` file with some data
```json

@@ -87,3 +95,3 @@ {

```bash
$ json-server --watch db.json
json-server --watch db.json
```

@@ -101,11 +109,5 @@

- Your request body JSON should be object enclosed, just like the GET output. (for example `{"name": "Foobar"}`)
- Id values are not mutable. Any `id` value in the body of your PUT or PATCH request wil be ignored. Only a value set in a POST request wil be respected, but only if not already taken.
- Id values are not mutable. Any `id` value in the body of your PUT or PATCH request will be ignored. Only a value set in a POST request will be respected, but only if not already taken.
- A POST, PUT or PATCH request should include a `Content-Type: application/json` header to use the JSON in the request body. Otherwise it will result in a 200 OK but without changes being made to the data.
## Install
```bash
$ npm install -g json-server
```
## Routes

@@ -582,2 +584,3 @@

* [No API? No Problem! Rapid Development via Mock APIs](https://medium.com/@housecor/rapid-development-via-mock-apis-e559087be066#.93d7w8oro)
* [Zero Code REST With json-server](https://dzone.com/articles/zero-code-rest-with-json-server)

@@ -594,2 +597,4 @@ ### Third-party tools

MIT - [Typicode](https://github.com/typicode) - [Patreon](https://www.patreon.com/typicode)
MIT
[Patreon](https://www.patreon.com/typicode) - [Supporters](https://thanks.typicode.com) ✨

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc