New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

laddare

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

laddare - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

src/index.js

465

dist/bundle.js

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

!function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e["default"]=t,e}function o(t){return t&&t.__esModule?t:{"default":t}}function i(){var t=u();Promise.resolve().then(s(t)).then(c(t)).then(a(t)).then(a(t)).then(f).then(s(t)).then(f)}function u(){var t=(0,p.createDatastore)(),e=(0,l.compose)((0,p.registerMiddleware)((0,h["default"])(E["default"])),(0,p.registerApi)("Github",g),(0,p.registerApi)("JsonPlaceholder",y));return(0,p.build)(e(t))}function a(t){return function(){return t.JsonPlaceholder.getAllPostsWithIdHigerThan(80)}}function s(t){return function(){return t.JsonPlaceholder.getAllPosts()}}function c(t){return function(){return t.JsonPlaceholder.savePosts([{id:31,body:"hej"},{id:1,body:"Fisk"}])}}function f(t){console.log(t)}var l=n(1),p=n(2),d=n(4),h=o(d),m=n(5),y=r(m),v=n(25),g=r(v),w=n(26),E=o(w);i()},function(t,e){"use strict";function n(){var t=arguments,e=[];return Object.keys(arguments).map(function(n){e.push(t[n])}),e.length>0?r(e):void 0}function r(t){return function(e){for(var n=t.length,r=n-1;r>=0;r--)e=t[r](e);return e}}Object.defineProperty(e,"__esModule",{value:!0}),e.compose=n},function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e["default"]=t,e}function o(t){return Array.isArray(t)?t:Array.from(t)}function i(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function u(){return{_middleware:[{name:"identity",middleware:w}],_apis:[],_built:!1}}function a(t,e){return function(n){if(n._built)throw new Error("Cannot register APIs after built");return v({},n,{_apis:[].concat(i(n._apis),[{name:t,api:e}])})}}function s(t){return function(e){if(e._built)throw new Error("Cannot register middleware after built");return v({},e,{_middleware:[].concat(i(e._middleware),[{middleware:t}])})}}function c(t){var e={_built:!0},n=t._apis.map(f(t._middleware));return n.forEach(function(t){return e[t._name]=t}),e}function f(t){return function(e){var n=Object.keys(e.api).filter(function(t){return"READ"===e.api[t].type});n=y(n,n.map(l(e,t)));var r=Object.keys(e.api).filter(function(t){return"WRITE"===e.api[t].type});return r=y(r,r.map(h(e,t))),v({_name:e.name},n,r)}}function l(t,e){return function(n){return function(){for(var r=arguments.length,o=Array(r),i=0;r>i;i++)o[i]=arguments[i];var u=p("preRead",t.name,t.api[n],n,e.filter(function(t){return t.middleware.preRead})),a=u(o),s=e.filter(function(t){return t.middleware.postRead}),c=m(t.api[n]);return s.forEach(function(e){return e.middleware.postRead(t.name,n,c,o,a)}),a.then(function(t){return t.data})}}}function p(t,e,n,r,u){var a=o(u),s=a[0],c=a.slice(1),f=m(n);return 0===c.length?s.middleware[t].bind(null,function(t){return n.apply(void 0,i(t))},e,r,f):s.middleware[t].bind(null,p(t,e,n,r,c),e,r,f)}function d(t,e,n,r,u){var a=o(u),s=a[0],c=a.slice(1),f=m(n);return 0===c.length?s.middleware[t].bind(null,function(t){return n.apply(void 0,i(t))},e,r,f):s.middleware[t].bind(null,d(t,e,n,r,c),e,r,f)}function h(t,e){return function(n){return function(){for(var r=arguments.length,o=Array(r),i=0;r>i;i++)o[i]=arguments[i];var u=d("preWrite",t.name,t.api[n],n,e.filter(function(t){return t.middleware.preWrite})),a=u(o),s=e.filter(function(t){return t.middleware.postWrite}),c=m(t.api[n]);return s.forEach(function(e){return e.middleware.postWrite(t.name,n,c,o,a)}),a.then(function(t){return t.data})}}}function m(t){return{multipleEntities:t.multipleEntities,entity:t.entity}}function y(t,e){var n={};return t.forEach(function(t,r){return n[t]=e[r]}),n}Object.defineProperty(e,"__esModule",{value:!0});var v=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t};e.createDatastore=u,e.registerApi=a,e.registerMiddleware=s,e.build=c;var g=n(3),w=r(g)},function(t,e){"use strict";function n(t,e,n,r,o){return t(o)}function r(t,e,n,r,o){return t(o)}function o(){}function i(t){return t}Object.defineProperty(e,"__esModule",{value:!0}),e.preRead=n,e.preWrite=r,e.postRead=o,e.postWrite=i},function(t,e){"use strict";function n(t){function e(t,e,n,r,o){var s=u(e,r.entity),c=i(e,n,r.multipleEntities,o,r.entity),f=void 0;return s&&(f=a(s,c))?new Promise(function(t){return t(f)}):t(o)}function n(t,e,n,r,o){var u=n.entity;o.then(function(o){l(i(t,e,n.multipleEntities,r,u),{data:o.data})})}function r(t,e,n,r,o){var u=r.entity,a=i(e,n,r.multipleEntities,o,u);return l(a,{data:o[0]},"WRITE"),t(o)}function o(t,e,n,r,o){return o}function i(t,e,n,r,o){return n?{type:"COLLECTION_KEY",value:[t,e,n,r].join("-"),entityType:o}:{type:"ENTITY_KEY",entityType:o,id:r[0].id}}function u(e,n){return t[n]?t[n]:{}}function a(t,e){var n=void 0;return n="COLLECTION_KEY"===e.type?s(e):c(e),n&&f(n,t,e)?n:!1}function s(t){return m[t.value]?{data:m[t.value].ids.map(function(e){return h[t.entityType][e].data})}:!1}function c(t){return h[t.entityType][t.id]?h[t.entityType][t.id]:!1}function f(t,e,n){return"COLLECTION_KEY"===n.type?m[n.value].timestamp+1e3*e.ttl>=Date.now():t.timestamp+1e3*e.ttl>=Date.now()}function l(t,e,n){var r=t.entityType;h[r]||(h[r]={}),"COLLECTION_KEY"===t.type?p(t,r,e.data,n):d(r,e.data)}function p(t,e,n,r){if(n.forEach(function(t){h[e][t.id]={data:t,timestamp:Date.now()}}),"WRITE"!==r){var o=n.map(function(t){return t.id});m[t.value]={timestamp:Date.now(),ids:o}}}function d(t,e){h[t][e.id]={data:e,timestamp:Date.now()}}var h={dummyItem:{timestamp:1212}},m={dummyItem:{timestamp:1212}};return{preRead:e,postRead:n,preWrite:r,postWrite:o}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=n},function(t,e,n){"use strict";function r(){return(0,c.get)("http://jsonplaceholder.typicode.com/posts")}function o(t){return(0,c.get)("http://jsonplaceholder.typicode.com/posts").then(function(e){return s({},e,{data:e.data.filter(function(e){return e.id>t})})})}function i(t){return(0,c.get)("http://jsonplaceholder.typicode.com/posts/"+t.id)}function u(t){return(0,c.post)("http://jsonplaceholder.typicode.com/posts/"+t.id,s({},t))}function a(t){return(0,c.post)("http://jsonplaceholder.typicode.com/posts/",s({},t))}Object.defineProperty(e,"__esModule",{value:!0});var s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t};e.getAllPosts=r,e.getAllPostsWithIdHigerThan=o,e.getSingle=i,e.savePost=u,e.savePosts=a;var c=n(6);r.type="READ",r.entity="JsonPlacerholderPost",r.multipleEntities=!0,o.type="READ",o.entity="JsonPlacerholderPost",o.multipleEntities=!0,i.type="READ",i.entity="JsonPlacerholderPost",i.multipleEntities=!1,u.type="WRITE",u.entity="JsonPlacerholderPost",u.multipleEntities=!1,a.type="WRITE",a.entity="JsonPlacerholderPost",a.multipleEntities=!0},function(t,e,n){t.exports=n(7)},function(t,e,n){"use strict";function r(t){this.defaults=i.merge({},t),this.interceptors={request:new a,response:new a}}var o=n(8),i=n(9),u=n(10),a=n(20),s=n(21),c=n(22),f=n(23),l=n(15);r.prototype.request=function(t){"string"==typeof t&&(t=i.merge({url:arguments[0]},arguments[1])),t=i.merge(o,this.defaults,{method:"get"},t),t.baseURL&&!s(t.url)&&(t.url=c(t.baseURL,t.url)),t.withCredentials=t.withCredentials||this.defaults.withCredentials,t.data=l(t.data,t.headers,t.transformRequest),t.headers=i.merge(t.headers.common||{},t.headers[t.method]||{},t.headers||{}),i.forEach(["delete","get","head","post","put","patch","common"],function(e){delete t.headers[e]});var e=[u,void 0],n=Promise.resolve(t);for(this.interceptors.request.forEach(function(t){e.unshift(t.fulfilled,t.rejected)}),this.interceptors.response.forEach(function(t){e.push(t.fulfilled,t.rejected)});e.length;)n=n.then(e.shift(),e.shift());return n};var p=new r(o),d=t.exports=f(r.prototype.request,p);t.exports.Axios=r,d.defaults=p.defaults,d.interceptors=p.interceptors,d.create=function(t){return new r(t)},d.all=function(t){return Promise.all(t)},d.spread=n(24),i.forEach(["delete","get","head"],function(t){r.prototype[t]=function(e,n){return this.request(i.merge(n||{},{method:t,url:e}))},d[t]=f(r.prototype[t],p)}),i.forEach(["post","put","patch"],function(t){r.prototype[t]=function(e,n,r){return this.request(i.merge(r||{},{method:t,url:e,data:n}))},d[t]=f(r.prototype[t],p)})},function(t,e,n){"use strict";var r=n(9),o=/^\)\]\}',?\n/,i={"Content-Type":"application/x-www-form-urlencoded"};t.exports={transformRequest:[function(t,e){return r.isFormData(t)||r.isArrayBuffer(t)||r.isStream(t)?t:r.isArrayBufferView(t)?t.buffer:!r.isObject(t)||r.isFile(t)||r.isBlob(t)?t:(r.isUndefined(e)||(r.forEach(e,function(t,n){"content-type"===n.toLowerCase()&&(e["Content-Type"]=t)}),r.isUndefined(e["Content-Type"])&&(e["Content-Type"]="application/json;charset=utf-8")),JSON.stringify(t))}],transformResponse:[function(t){if("string"==typeof t){t=t.replace(o,"");try{t=JSON.parse(t)}catch(e){}}return t}],headers:{common:{Accept:"application/json, text/plain, */*"},patch:r.merge(i),post:r.merge(i),put:r.merge(i)},timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,validateStatus:function(t){return t>=200&&300>t}}},function(t,e){"use strict";function n(t){return"[object Array]"===w.call(t)}function r(t){return"[object ArrayBuffer]"===w.call(t)}function o(t){return"undefined"!=typeof FormData&&t instanceof FormData}function i(t){var e;return e="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer&&t.buffer instanceof ArrayBuffer}function u(t){return"string"==typeof t}function a(t){return"number"==typeof t}function s(t){return"undefined"==typeof t}function c(t){return null!==t&&"object"==typeof t}function f(t){return"[object Date]"===w.call(t)}function l(t){return"[object File]"===w.call(t)}function p(t){return"[object Blob]"===w.call(t)}function d(t){return"[object Function]"===w.call(t)}function h(t){return c(t)&&d(t.pipe)}function m(t){return t.replace(/^\s*/,"").replace(/\s*$/,"")}function y(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"function"==typeof document.createElement}function v(t,e){if(null!==t&&"undefined"!=typeof t)if("object"==typeof t||n(t)||(t=[t]),n(t))for(var r=0,o=t.length;o>r;r++)e.call(null,t[r],r,t);else for(var i in t)t.hasOwnProperty(i)&&e.call(null,t[i],i,t)}function g(){function t(t,n){"object"==typeof e[n]&&"object"==typeof t?e[n]=g(e[n],t):e[n]=t}for(var e={},n=0,r=arguments.length;r>n;n++)v(arguments[n],t);return e}var w=Object.prototype.toString;t.exports={isArray:n,isArrayBuffer:r,isFormData:o,isArrayBufferView:i,isString:u,isNumber:a,isObject:c,isUndefined:s,isDate:f,isFile:l,isBlob:p,isFunction:d,isStream:h,isStandardBrowserEnv:y,forEach:v,merge:g,trim:m}},function(t,e,n){(function(e){"use strict";t.exports=function(t){return new Promise(function(r,o){try{var i;"function"==typeof t.adapter?i=t.adapter:"undefined"!=typeof XMLHttpRequest?i=n(12):"undefined"!=typeof e&&(i=n(12)),"function"==typeof i&&i(r,o,t)}catch(u){o(u)}})}}).call(e,n(11))},function(t,e){function n(){l&&u&&(l=!1,u.length?f=u.concat(f):p=-1,f.length&&r())}function r(){if(!l){var t=s(n);l=!0;for(var e=f.length;e;){for(u=f,f=[];++p<e;)u&&u[p].run();p=-1,e=f.length}u=null,l=!1,c(t)}}function o(t,e){this.fun=t,this.array=e}function i(){}var u,a=t.exports={},s=setTimeout,c=clearTimeout,f=[],l=!1,p=-1;a.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];f.push(new o(t,e)),1!==f.length||l||s(r,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},a.title="browser",a.browser=!0,a.env={},a.argv=[],a.version="",a.versions={},a.on=i,a.addListener=i,a.once=i,a.off=i,a.removeListener=i,a.removeAllListeners=i,a.emit=i,a.binding=function(t){throw new Error("process.binding is not supported")},a.cwd=function(){return"/"},a.chdir=function(t){throw new Error("process.chdir is not supported")},a.umask=function(){return 0}},function(t,e,n){(function(e){"use strict";var r=n(9),o=n(13),i=n(14),u=n(15),a=n(16),s="undefined"!=typeof window&&window.btoa||n(17),c=n(18);t.exports=function(t,f,l){var p=l.data,d=l.headers;r.isFormData(p)&&delete d["Content-Type"];var h=new XMLHttpRequest,m="onreadystatechange",y=!1;if("test"===e.env.NODE_ENV||"undefined"==typeof window||!window.XDomainRequest||"withCredentials"in h||a(l.url)||(h=new window.XDomainRequest,m="onload",y=!0,h.onprogress=function(){},h.ontimeout=function(){}),l.auth){var v=l.auth.username||"",g=l.auth.password||"";d.Authorization="Basic "+s(v+":"+g)}if(h.open(l.method.toUpperCase(),o(l.url,l.params,l.paramsSerializer),!0),h.timeout=l.timeout,h[m]=function(){if(h&&(4===h.readyState||y)&&0!==h.status){var e="getAllResponseHeaders"in h?i(h.getAllResponseHeaders()):null,n=l.responseType&&"text"!==l.responseType?h.response:h.responseText,r={data:u(n,e,l.transformResponse),status:1223===h.status?204:h.status,statusText:1223===h.status?"No Content":h.statusText,headers:e,config:l,request:h};c(t,f,r),h=null}},h.onerror=function(){f(new Error("Network Error")),h=null},h.ontimeout=function(){var t=new Error("timeout of "+l.timeout+"ms exceeded");t.timeout=l.timeout,t.code="ECONNABORTED",f(t),h=null},r.isStandardBrowserEnv()){var w=n(19),E=l.withCredentials||a(l.url)?w.read(l.xsrfCookieName):void 0;E&&(d[l.xsrfHeaderName]=E)}if("setRequestHeader"in h&&r.forEach(d,function(t,e){"undefined"==typeof p&&"content-type"===e.toLowerCase()?delete d[e]:h.setRequestHeader(e,t)}),l.withCredentials&&(h.withCredentials=!0),l.responseType)try{h.responseType=l.responseType}catch(b){if("json"!==h.responseType)throw b}l.progress&&("post"===l.method||"put"===l.method?h.upload.addEventListener("progress",l.progress):"get"===l.method&&h.addEventListener("progress",l.progress)),void 0===p&&(p=null),h.send(p)}}).call(e,n(11))},function(t,e,n){"use strict";function r(t){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var o=n(9);t.exports=function(t,e,n){if(!e)return t;var i;if(n)i=n(e);else{var u=[];o.forEach(e,function(t,e){null!==t&&"undefined"!=typeof t&&(o.isArray(t)&&(e+="[]"),o.isArray(t)||(t=[t]),o.forEach(t,function(t){o.isDate(t)?t=t.toISOString():o.isObject(t)&&(t=JSON.stringify(t)),u.push(r(e)+"="+r(t))}))}),i=u.join("&")}return i&&(t+=(-1===t.indexOf("?")?"?":"&")+i),t}},function(t,e,n){"use strict";var r=n(9);t.exports=function(t){var e,n,o,i={};return t?(r.forEach(t.split("\n"),function(t){o=t.indexOf(":"),e=r.trim(t.substr(0,o)).toLowerCase(),n=r.trim(t.substr(o+1)),e&&(i[e]=i[e]?i[e]+", "+n:n)}),i):i}},function(t,e,n){"use strict";var r=n(9);t.exports=function(t,e,n){return r.forEach(n,function(n){t=n(t,e)}),t}},function(t,e,n){"use strict";var r=n(9);t.exports=r.isStandardBrowserEnv()?function(){function t(t){var e=t;return n&&(o.setAttribute("href",e),e=o.href),o.setAttribute("href",e),{href:o.href,protocol:o.protocol?o.protocol.replace(/:$/,""):"",host:o.host,search:o.search?o.search.replace(/^\?/,""):"",hash:o.hash?o.hash.replace(/^#/,""):"",hostname:o.hostname,port:o.port,pathname:"/"===o.pathname.charAt(0)?o.pathname:"/"+o.pathname}}var e,n=/(msie|trident)/i.test(navigator.userAgent),o=document.createElement("a");return e=t(window.location.href),function(n){var o=r.isString(n)?t(n):n;return o.protocol===e.protocol&&o.host===e.host}}():function(){return function(){return!0}}()},function(t,e){"use strict";function n(){this.message="String contains an invalid character"}function r(t){for(var e,r,i=String(t),u="",a=0,s=o;i.charAt(0|a)||(s="=",a%1);u+=s.charAt(63&e>>8-a%1*8)){if(r=i.charCodeAt(a+=.75),r>255)throw new n;e=e<<8|r}return u}var o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n.prototype=new Error,n.prototype.code=5,n.prototype.name="InvalidCharacterError",t.exports=r},function(t,e){"use strict";t.exports=function(t,e,n){var r=n.config.validateStatus;n.status&&r&&!r(n.status)?e(n):t(n)}},function(t,e,n){"use strict";var r=n(9);t.exports=r.isStandardBrowserEnv()?function(){return{write:function(t,e,n,o,i,u){var a=[];a.push(t+"="+encodeURIComponent(e)),r.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),r.isString(o)&&a.push("path="+o),r.isString(i)&&a.push("domain="+i),u===!0&&a.push("secure"),document.cookie=a.join("; ")},read:function(t){var e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove:function(t){this.write(t,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}()},function(t,e,n){"use strict";function r(){this.handlers=[]}var o=n(9);r.prototype.use=function(t,e){return this.handlers.push({fulfilled:t,rejected:e}),this.handlers.length-1},r.prototype.eject=function(t){this.handlers[t]&&(this.handlers[t]=null)},r.prototype.forEach=function(t){o.forEach(this.handlers,function(e){null!==e&&t(e)})},t.exports=r},function(t,e){"use strict";t.exports=function(t){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(t)}},function(t,e){"use strict";t.exports=function(t,e){return t.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,"")}},function(t,e){"use strict";t.exports=function(t,e){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return t.apply(e,n)}}},function(t,e){"use strict";t.exports=function(t){return function(e){return t.apply(null,e)}}},function(t,e,n){"use strict";function r(){return(0,i.get)("https://api.github.com/users/petercrona/repos")}function o(t){return(0,i.get)("https://api.github.com/repos/petercrona/"+t.id)}Object.defineProperty(e,"__esModule",{value:!0}),e.getRepos=r,e.getRepo=o;var i=n(6);r.type="READ",r.returnsMultipleEntities=!0,o.type="READ",o.returnsMultipleEntities=!1},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=300;e["default"]={JsonPlacerholderPost:{ttl:n},GithubRepo:{ttl:n}}}]);
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _datastore = __webpack_require__(1);
var datastore = _interopRequireWildcard(_datastore);
var _caching = __webpack_require__(3);
var _caching2 = _interopRequireDefault(_caching);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
exports.default = _extends({}, datastore, {
middleware: {
Caching: _caching2.default
}
});
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.createDatastore = createDatastore;
exports.registerApi = registerApi;
exports.registerMiddleware = registerMiddleware;
exports.build = build;
var _identityMiddleware = __webpack_require__(2);
var IdentityMiddleware = _interopRequireWildcard(_identityMiddleware);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function createDatastore() {
return {
_middleware: [{ name: 'identity', middleware: IdentityMiddleware }],
_apis: [],
_built: false
};
}
function registerApi(name, api) {
return function (datastore) {
if (datastore._built) {
throw new Error('Cannot register APIs after built');
}
return _extends({}, datastore, {
_apis: [].concat(_toConsumableArray(datastore._apis), [{ name: name, api: api }])
});
};
}
function registerMiddleware(middleware) {
return function (datastore) {
if (datastore._built) {
throw new Error('Cannot register middleware after built');
}
return _extends({}, datastore, {
_middleware: [].concat(_toConsumableArray(datastore._middleware), [{ middleware: middleware }])
});
};
}
function build(datastore) {
var builtDatastore = {
_built: true
};
var apis = datastore._apis.map(buildApi(datastore._middleware));
apis.forEach(function (api) {
return builtDatastore[api._name] = api;
});
return builtDatastore;
}
function buildApi(middleware) {
return function (api) {
var readMethods = Object.keys(api.api).filter(function (x) {
return api.api[x].type === 'READ';
});
readMethods = createObject(readMethods, readMethods.map(decorateRead(api, middleware)));
var writeMethods = Object.keys(api.api).filter(function (x) {
return api.api[x].type === 'WRITE';
});
writeMethods = createObject(writeMethods, writeMethods.map(decorateWrite(api, middleware)));
return _extends({
_name: api.name
}, readMethods, writeMethods);
};
}
function decorateRead(api, middleware) {
return function (toDecorate) {
return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var preRead = bindPreRead('preRead', api.name, api.api[toDecorate], toDecorate, middleware.filter(function (x) {
return x.middleware.preRead;
}));
var result = preRead(args);
var postReadMiddleware = middleware.filter(function (x) {
return x.middleware.postRead;
});
var methodMeta = createMethodMeta(api.api[toDecorate]);
postReadMiddleware.forEach(function (x) {
return x.middleware.postRead(api.name, toDecorate, methodMeta, args, result);
});
return result.then(function (x) {
return x.data;
});
};
};
}
function bindPreRead(hook, apiName, toDecorate, toDecorateName, middleware) {
var _middleware = _toArray(middleware);
var x = _middleware[0];
var xs = _middleware.slice(1);
var methodMeta = createMethodMeta(toDecorate);
if (xs.length === 0) {
return x.middleware[hook].bind(null, function (args) {
return toDecorate.apply(undefined, _toConsumableArray(args));
}, apiName, toDecorateName, methodMeta);
} else {
return x.middleware[hook].bind(null, bindPreRead(hook, apiName, toDecorate, toDecorateName, xs), apiName, toDecorateName, methodMeta);
}
}
function bindPreWrite(hook, apiName, toDecorate, toDecorateName, middleware) {
var _middleware2 = _toArray(middleware);
var x = _middleware2[0];
var xs = _middleware2.slice(1);
var methodMeta = createMethodMeta(toDecorate);
if (xs.length === 0) {
return x.middleware[hook].bind(null, function (args) {
return toDecorate.apply(undefined, _toConsumableArray(args));
}, apiName, toDecorateName, methodMeta);
} else {
return x.middleware[hook].bind(null, bindPreWrite(hook, apiName, toDecorate, toDecorateName, xs), apiName, toDecorateName, methodMeta);
}
}
function decorateWrite(api, middleware) {
return function (toDecorate) {
return function () {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
var preWrite = bindPreWrite('preWrite', api.name, api.api[toDecorate], toDecorate, middleware.filter(function (x) {
return x.middleware.preWrite;
}));
var result = preWrite(args);
var postWriteMiddleware = middleware.filter(function (x) {
return x.middleware.postWrite;
});
var methodMeta = createMethodMeta(api.api[toDecorate]);
postWriteMiddleware.forEach(function (x) {
return x.middleware.postWrite(api.name, toDecorate, methodMeta, args, result);
});
return result.then(function (x) {
return x.data;
});
};
};
}
function createMethodMeta(method) {
return {
multipleEntities: method.multipleEntities,
entity: method.entity
};
}
function createObject(keys, vals) {
var obj = {};
keys.forEach(function (key, index) {
return obj[key] = vals[index];
});
return obj;
}
/***/ },
/* 2 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.preRead = preRead;
exports.preWrite = preWrite;
exports.postRead = postRead;
exports.postWrite = postWrite;
function preRead(next, apiName, toDecorateName, multipleEntities, args) {
return next(args);
}
function preWrite(next, apiName, toDecorateName, multipleEntities, args) {
return next(args);
}
function postRead() {}
function postWrite(promise) {
return promise;
}
/***/ },
/* 3 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Caching;
function Caching(config) {
var storage = {
dummyItem: {
timestamp: 1212
}
};
var collectionQueries = {
dummyItem: {
timestamp: 1212
}
};
return {
preRead: preRead,
postRead: postRead,
preWrite: preWrite,
postWrite: postWrite
};
function preRead(next, apiName, methodName, methodMeta, args) {
var typeConfig = getTypeConfig(apiName, methodMeta.entity);
var key = createKey(apiName, methodName, methodMeta.multipleEntities, args, methodMeta.entity);
var fromCache = void 0;
if (typeConfig && (fromCache = getFromCache(typeConfig, key))) {
return new Promise(function (resolve) {
return resolve(fromCache);
});
} else {
return next(args);
}
}
function postRead(apiName, methodName, methodMeta, args, promise) {
var type = methodMeta.entity;
promise.then(function (result) {
saveToCache(createKey(apiName, methodName, methodMeta.multipleEntities, args, type), { data: result.data });
});
}
function preWrite(next, apiName, methodName, methodMeta, args) {
var methodType = methodMeta.entity;
var key = createKey(apiName, methodName, methodMeta.multipleEntities, args, methodType);
saveToCache(key, {
data: args[0]
}, 'WRITE');
return next(args);
}
function postWrite(apiName, methodName, methodMeta, args, promise) {
return promise;
}
function createKey(apiName, methodName, multipleEntities, args, type) {
if (multipleEntities) {
return {
type: 'COLLECTION_KEY',
value: [apiName, methodName, multipleEntities, args].join('-'),
entityType: type
};
} else {
return {
type: 'ENTITY_KEY',
entityType: type,
id: args[0].id
};
}
}
function getTypeConfig(apiName, typeName) {
if (config[typeName]) {
return config[typeName];
} else {
return {};
}
}
function getFromCache(methodConfig, key) {
var value = void 0;
if (key.type === 'COLLECTION_KEY') {
value = getCollectionFromCache(key);
} else {
value = getEntityFromCache(key);
}
if (value && isValid(value, methodConfig, key)) {
return value;
} else {
return false;
}
}
function getCollectionFromCache(key) {
if (collectionQueries[key.value]) {
return {
data: collectionQueries[key.value].ids.map(function (x) {
return storage[key.entityType][x].data;
})
};
} else {
return false;
}
}
function getEntityFromCache(key) {
if (storage[key.entityType][key.id]) {
return storage[key.entityType][key.id];
} else {
return false;
}
}
function isValid(item, methodConfig, key) {
if (key.type === 'COLLECTION_KEY') {
return collectionQueries[key.value].timestamp + methodConfig.ttl * 1000 >= Date.now();
} else {
return item.timestamp + methodConfig.ttl * 1000 >= Date.now();
}
}
function saveToCache(key, val, operation) {
var type = key.entityType;
if (!storage[type]) {
storage[type] = {};
}
if (key.type === 'COLLECTION_KEY') {
saveCollection(key, type, val.data, operation);
} else {
saveEntity(type, val.data);
}
}
function saveCollection(key, type, val, operation) {
val.forEach(function (x) {
storage[type][x.id] = {
data: x,
timestamp: Date.now()
};
});
if (operation !== 'WRITE') {
var ids = val.map(function (x) {
return x.id;
});
collectionQueries[key.value] = {
timestamp: Date.now(),
ids: ids
};
}
}
function saveEntity(type, val) {
storage[type][val.id] = {
data: val,
timestamp: Date.now()
};
}
}
/***/ }
/******/ ]);

4

package.json
{
"name": "laddare",
"version": "0.0.1",
"version": "0.0.2",
"description": "Data fetching layaer with support for caching",
"main": "bundle.js",
"main": "dist/bundle.js",
"dependencies": {

@@ -7,0 +7,0 @@ "axios": "^0.11.1"

const path = require('path');
module.exports = {
entry: './src/example/index.js',
entry: './src/index.js',
output: {

@@ -6,0 +6,0 @@ path: __dirname + '/dist',

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