eze-link
Version:
2 lines (1 loc) • 27.9 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=function(){return e=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},e.apply(this,arguments)};function r(e,r,t,n){return new(t||(t=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function u(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(a,u)}s((n=n.apply(e,r||[])).next())}))}function t(e,r){var t,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(t=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=r.call(e,a)}catch(e){u=[6,e],n=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}function n(e,r,t){if(t||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return e.concat(n||Array.prototype.slice.call(r))}"function"==typeof SuppressedError&&SuppressedError;var o={create:function(n){var o=n.headers,a=n.onResponse,u=n.onError,s=n.onRequest,l=n.options,c=void 0===l?{}:l,d={get:f("get"),delete:f("delete"),post:f("post"),put:f("put"),patch:f("patch"),update:f("update"),getBlob:b("get"),postBlob:b("post"),setHeader:function(e){o="function"==typeof e?e(o):e},setOnResponse:function(e){a=e},setOnError:function(e){u=e},setOnRequest:function(e){s=e}},h={};function f(n){var l=this;return function(d){var f=d.url,b=d.body,y=d.headers,v=d.abortId,g=void 0===v?"".concat(n,"-").concat(f.split("?")[0]):v;h[g]&&(console.warn("A B O R T E D \n"+g+"\n?"+f.split("?")[1]),h[g].abort()),h[g]=new AbortController;var p=e({method:n.toUpperCase(),headers:e(e({"Content-Type":"application/json"},o),y),body:b?JSON.stringify(b):void 0,signal:h[g].signal},c);return new Promise((function(e,n){return r(l,void 0,void 0,(function(){var r,o,l,c,d,b,y;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,12,,13]),[4,null==s?void 0:s(p)];case 1:return t.sent(),[4,fetch(f,p)];case 2:if(r=t.sent(),h[g]=null,!r.ok)return[3,7];t.label=3;case 3:return t.trys.push([3,5,,6]),o=r,[4,r.json()];case 4:return o.data=t.sent(),[3,6];case 5:return t.sent(),[3,6];case 6:return null==a||a(r),e(r),[3,11];case 7:return t.trys.push([7,9,,10]),l=r,d=(c=JSON).parse,[4,r.text()];case 8:return l.message=d.apply(c,[t.sent()]),[3,10];case 9:return t.sent(),[3,10];case 10:p.url=f,b=i(r,p),u&&(b=u(b)),b&&n(b),t.label=11;case 11:return[3,13];case 12:return"AbortError"===(y=t.sent()).name?[2]:(u&&(y=u(y)),y&&n(y),[3,13]);case 13:return[2]}}))}))}))}}function b(n){var l=this;return function(c){var d=c.url,f=c.body,b=c.headers,y=c.abortId,v=void 0===y?"".concat(n,"-").concat(d.split("?")[0]):y;h[v]&&(console.warn("A B O R T E D \n"+v+"\n?"+d.split("?")[1]),h[v].abort()),h[v]=new AbortController;var g={method:n.toUpperCase(),headers:e(e({"Content-Type":"application/json"},o),b),body:f?JSON.stringify(f):void 0,signal:h[v].signal};return new Promise((function(e,n){return r(l,void 0,void 0,(function(){var r,o,l,c,f,b,y;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,9,,10]),[4,null==s?void 0:s(g)];case 1:return t.sent(),[4,fetch(d,g)];case 2:return r=t.sent(),h[v]=null,r.ok?[4,r.blob()]:[3,4];case 3:return o=t.sent(),null==a||a(r),e(o),[3,8];case 4:return t.trys.push([4,6,,7]),l=r,f=(c=JSON).parse,[4,r.text()];case 5:return l.message=f.apply(c,[t.sent()]),[3,7];case 6:return t.sent(),[3,7];case 7:g.url=d,b=i(r,g),u&&(b=u(b)),b&&n(b),t.label=8;case 8:return[3,10];case 9:return"AbortError"===(y=t.sent()).name?[2]:(u&&(y=u(y)),y&&n(y),[3,10]);case 10:return[2]}}))}))}))}}return d}},i=function(e,r){return{props:r,response:e,statusMessage:a[e.status]||"Unknown Error"}},a={0:"There Is No Response From Server Body Is Empty Connection May Be Very Slow",100:"Continue",101:"Switching protocols",102:"Processing",103:"Early Hints",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found (Previously 'Moved Temporarily')",303:"See Other",304:"Not Modified",305:"Use Proxy",306:"Switch Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a Teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Headers Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",510:"Not Extended",511:"Network Authentication Required"},u=function(){function r(r){var t,o=r.storage,i=void 0===o?"sessionStorage":o,a=r.storeKey,u=void 0===a?"storable":a,s=this;Object.defineProperty(this,"storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storeKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"set",{enumerable:!0,configurable:!0,writable:!0,value:function(e,r){return Object.values(r).length>0?s.storage.setItem(s.getCleanString(e),JSON.stringify(r)):s.remove(e)}}),Object.defineProperty(this,"get",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return JSON.parse(s.storage.getItem(s.getCleanString(e)))}}),Object.defineProperty(this,"insert",{enumerable:!0,configurable:!0,writable:!0,value:function(r,t){var o,i,a=Array.isArray(t),u=null!==(o=s.get(r))&&void 0!==o?o:a?[]:{},l=t;(null===(i=Object.keys(u))||void 0===i?void 0:i.length)&&(a?l=n(n([],u,!0),l,!0):"object"==typeof l&&(l=e(e({},u),l))),s.set(r,l)}}),Object.defineProperty(this,"remove",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return s.storage.removeItem(s.getCleanString(e))}}),Object.defineProperty(this,"clear",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var r,t;if(e)for(var n=0;n<(null===(r=s.storage)||void 0===r?void 0:r.length);n++){(o=s.storage.key(n)).startsWith(s.getCleanString(e))&&s.storage.removeItem(o)}else for(n=0;n<(null===(t=s.storage)||void 0===t?void 0:t.length);n++){var o;(o=s.storage.key(n)).startsWith(s.storeKey)&&s.storage.removeItem(o)}}}),Object.defineProperty(this,"select",{enumerable:!0,configurable:!0,writable:!0,value:function(e,r){var t;return(null!==(t=s.get(e))&&void 0!==t?t:[])[r]}}),Object.defineProperty(this,"getCleanString",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return void 0===e&&(e=""),s.storeKey+e.replace(/[?&=/!]/g,"-")}}),this.storage={},"localStorage"===i?this.storage=localStorage:"sessionStorage"===i?this.storage=sessionStorage:"memoryStorage"===i?this.storage=(t={getItem:function(e){var r;return null!==(r=t[e])&&void 0!==r?r:null},setItem:function(e,r){t[e]=r,t.length++},removeItem:function(e){delete t[e],t.length--},key:function(e){var r;return null!==(r=Object.keys(t)[e])&&void 0!==r?r:null},length:0},t):i instanceof Storage&&(this.storage=i),this.storeKey=u}return Object.defineProperty(r,"clear",{enumerable:!0,configurable:!0,writable:!0,value:function(e,r){for(var t="localStorage"===e?localStorage:sessionStorage,n=0;n<(null==t?void 0:t.length);n++){var o=t.key(n);o.startsWith(r)&&t.removeItem(o)}}}),r}();var s=function(){function n(n){var i=n.api,a=void 0===i?o.create({}):i,s=n.limit,c=n.storage,d=n.storeKey,h=n.generateQuery,f=n.roots,b=this;Object.defineProperty(this,"limit",{enumerable:!0,configurable:!0,writable:!0,value:25}),Object.defineProperty(this,"storable",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"generateQuery",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"useCash",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"roots",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"getRoot",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var r=e.root,t=e.url;if(!r)return b.roots[Object.keys(b.roots)[0]]+t;var n=b.roots[r];return n?n+t:r+t}}),Object.defineProperty(this,"clearCash",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var r;return null===(r=b.storable)||void 0===r?void 0:r.clear(e)}}),Object.defineProperty(this,"GET_Blob",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.headers;return new Promise((function(e,u){return r(b,void 0,void 0,(function(){var r,s,c,d,h,f=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return f.GET_Blob({root:n,url:o,query:i,headers:a})},t.label=1;case 1:return t.trys.push([1,3,,4]),s=l({url:this.getRoot({root:n,url:o}),query:i}),[4,this.api.getBlob({url:s,headers:a})];case 2:return c=t.sent(),e(c),[3,4];case 3:return d=t.sent(),(h=d).retry=r,u(h),[3,4];case 4:return[2]}}))}))}))}}),Object.defineProperty(this,"POST_Blob",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.headers,u=e.body;return new Promise((function(e,s){return r(b,void 0,void 0,(function(){var r,c,d,h,f,b=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return b.POST_Blob({root:n,url:o,query:i,headers:a,body:u})},t.label=1;case 1:return t.trys.push([1,3,,4]),c=l({url:this.getRoot({root:n,url:o}),query:i}),[4,this.api.postBlob({url:c,body:u,headers:a})];case 2:return d=t.sent(),e(d),[3,4];case 3:return h=t.sent(),(f=h).retry=r,s(f),[3,4];case 4:return[2]}}))}))}))}}),Object.defineProperty(this,"OffsetPaginatorWithCash",{enumerable:!0,configurable:!0,writable:!0,value:function(n){var o=n.root,i=n.url,a=n.getUrl,u=n.getHeaders,s=n.limit,l=void 0===s?b.limit:s,c=n.storageKey,d=void 0===c?"":c,h=n.abortId,f=0,y="",v=null,g="",p=a?function(e){return b.getRoot({root:o,url:a(e)})}:function(){return b.getRoot({root:o,url:i})},m={hasMore:!1,limit:l,load:function(n,o){return new Promise((function(i,a){return r(b,void 0,void 0,(function(){var r,s,l;return t(this,(function(t){switch(t.label){case 0:f=0,t.label=1;case 1:return t.trys.push([1,5,,6]),v=null==u?void 0:u(n),y=this.generateQuery({url:p(n),query:e({limit:m.limit},n)}),g=d+y,r=y,(s=o?null:this.storable.get(g))?[3,3]:[4,this.api.get({url:r,headers:v,abortId:h})];case 2:return s=t.sent().data,m.hasMore=s.length>=m.limit,this.storable.set(g,s),[3,4];case 3:m.hasMore=!0,t.label=4;case 4:return f+=s.length,i(s),[3,6];case 5:return(l=t.sent()).retry=function(){return m.load(n,o)},a(l),[3,6];case 6:return[2]}}))}))}))},loadMore:function(){return new Promise((function(e,n){return r(b,void 0,void 0,(function(){var r,o,i;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),r=y+"&offset=".concat(f),[4,this.api.get({url:r,headers:v,abortId:h})];case 1:return o=t.sent().data,f+=o.length,m.hasMore=o.length>=m.limit,this.storable.insert(g,o),e(o),[3,3];case 2:return(i=t.sent()).retry=function(){return m.loadMore()},n(i),[3,3];case 3:return[2]}}))}))}))},reload:function(e){return m.load(e,!0)},loadAll:function(e){return r(b,void 0,void 0,(function(){var n=this;return t(this,(function(o){return[2,new Promise((function(o,i){return r(n,void 0,void 0,(function(){var r,n,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),v=null==u?void 0:u(e),r=this.generateQuery({url:p(e),query:e}),[4,this.api.get({url:r,headers:v})];case 1:return n=t.sent().data,o(n),[3,3];case 2:return(a=t.sent()).retry=function(){return m.loadAll(e)},i(a),[3,3];case 3:return[2]}}))}))}))]}))}))}};return m}}),Object.defineProperty(this,"OffsetPaginator",{enumerable:!0,configurable:!0,writable:!0,value:function(n){var o=n.root,i=n.url,a=n.getUrl,u=n.getHeaders,s=n.limit,l=void 0===s?b.limit:s,c=n.abortId,d=0,h="",f=null,y=a?function(e){return b.getRoot({root:o,url:a(e)})}:function(){return b.getRoot({root:o,url:i})},v={hasMore:!1,limit:l,load:function(n){return new Promise((function(o,i){return r(b,void 0,void 0,(function(){var r,a,s,l;return t(this,(function(t){switch(t.label){case 0:d=0,t.label=1;case 1:return t.trys.push([1,3,,4]),f=null==u?void 0:u(n),h=this.generateQuery({url:y(n),query:e({limit:v.limit},n)}),r=h,[4,this.api.get({url:r,headers:f,abortId:c})];case 2:return a=t.sent().data,s=Array.isArray(a)?a:Object.values(a).find((function(e){return Array.isArray(e)})),d+=s.length,v.hasMore=s.length>=v.limit,o(a),[3,4];case 3:return(l=t.sent()).retry=function(){return v.load(n)},i(l),[3,4];case 4:return[2]}}))}))}))},loadMore:function(){return new Promise((function(e,n){return r(b,void 0,void 0,(function(){var r,o,i,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),r=h+"&offset=".concat(d),[4,this.api.get({url:r,headers:f,abortId:c})];case 1:return o=t.sent().data,i=Array.isArray(o)?o:Object.values(o).find((function(e){return Array.isArray(e)})),d+=i.length,v.hasMore=i.length>=v.limit,e(o),[3,3];case 2:return(a=t.sent()).retry=function(){return v.loadMore()},n(a),[3,3];case 3:return[2]}}))}))}))},reload:function(e){return v.load(e)},loadAll:function(n){return r(b,void 0,void 0,(function(){var o=this;return t(this,(function(i){return[2,new Promise((function(i,a){return r(o,void 0,void 0,(function(){var r,o,s;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),f=null==u?void 0:u(n),r=this.generateQuery({url:y(n),query:e(e({},n),{limit:null})}),[4,this.api.get({url:r,headers:f})];case 1:return o=t.sent().data,i(o),[3,3];case 2:return(s=t.sent()).retry=function(){return v.loadAll(n)},a(s),[3,3];case 3:return[2]}}))}))}))]}))}))}};return v}}),Object.defineProperty(this,"PaginatorWithCash",{enumerable:!0,configurable:!0,writable:!0,value:function(n){var o=n.root,i=n.url,a=n.getUrl,u=n.getHeaders,s=n.limit,l=void 0===s?b.limit:s,c=n.storageKey,d=void 0===c?"":c,h=0,f="",y=null,v="",g=a?function(e){return b.getRoot({root:o,url:a(e)})}:function(){return b.getRoot({root:o,url:i})},p={hasMore:!1,limit:l,load:function(n,o){return new Promise((function(i,a){return r(b,void 0,void 0,(function(){var r,s,l;return t(this,(function(t){switch(t.label){case 0:h=0,t.label=1;case 1:return t.trys.push([1,4,,5]),y=null==u?void 0:u(n),f=this.generateQuery({url:g(n),query:e({limit:p.limit},n)}),v=d+f,r=f,(s=o?null:this.storable.get(v))?[3,3]:[4,this.api.get({url:r,headers:y})];case 2:s=t.sent().data,p.hasMore=s.length>=p.limit,this.storable.set(v,s),t.label=3;case 3:return h++,i(s),[3,5];case 4:return(l=t.sent()).retry=function(){return p.load(n,o)},a(l),[3,5];case 5:return[2]}}))}))}))},loadMore:function(){return new Promise((function(e,n){return r(b,void 0,void 0,(function(){var r,o,i;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),r=f+"&page=".concat(h),[4,this.api.get({url:r,headers:y})];case 1:return o=t.sent().data,h++,p.hasMore=o.length>=p.limit,this.storable.insert(v,o),e(o),[3,3];case 2:return(i=t.sent()).retry=function(){return p.loadMore()},n(i),[3,3];case 3:return[2]}}))}))}))},reload:function(e){return p.load(e,!0)}};return p}}),Object.defineProperty(this,"Paginator",{enumerable:!0,configurable:!0,writable:!0,value:function(n){var o=n.root,i=n.url,a=n.getUrl,u=n.getHeaders,s=n.limit,l=void 0===s?b.limit:s,c=0,d="",h=null,f=a?function(e){return b.getRoot({root:o,url:a(e)})}:function(){return b.getRoot({root:o,url:i})},y={hasMore:!1,limit:l,load:function(n){return new Promise((function(o,i){return r(b,void 0,void 0,(function(){var r,a,s;return t(this,(function(t){switch(t.label){case 0:c=0,t.label=1;case 1:return t.trys.push([1,3,,4]),h=null==u?void 0:u(n),d=this.generateQuery({url:f(n),query:e({limit:y.limit},n)}),r=d,[4,this.api.get({url:r,headers:h})];case 2:return a=t.sent().data,c++,y.hasMore=a.length>=y.limit,o(a),[3,4];case 3:return(s=t.sent()).retry=function(){return y.load(n)},i(s),[3,4];case 4:return[2]}}))}))}))},loadMore:function(){return new Promise((function(e,n){return r(b,void 0,void 0,(function(){var r,o,i;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),r=d+"&page=".concat(c),[4,this.api.get({url:r,headers:h})];case 1:return o=t.sent().data,c++,y.hasMore=o.length>=y.limit,e(o),[3,3];case 2:return(i=t.sent()).retry=function(){return y.loadMore()},n(i),[3,3];case 3:return[2]}}))}))}))},reload:function(e){return y.load(e)}};return y}}),Object.defineProperty(this,"IdPaginatorWithCash",{enumerable:!0,configurable:!0,writable:!0,value:function(n){var o=n.root,i=n.url,a=n.getUrl,u=n.getHeaders,s=n.limit,l=void 0===s?b.limit:s,c=n.storageKey,d=void 0===c?"":c,h="",f="",y=null,v="",g=a?function(e){return b.getRoot({root:o,url:a(e)})}:function(){return b.getRoot({root:o,url:i})},p={hasMore:!1,limit:l,load:function(n,o){return new Promise((function(i,a){return r(b,void 0,void 0,(function(){var r,s,l,c,b;return t(this,(function(t){switch(t.label){case 0:h="",t.label=1;case 1:return t.trys.push([1,4,,5]),y=null==u?void 0:u(n),f=this.generateQuery({url:g(n),query:e({limit:p.limit},n)}),null===(b=f.split("sort")[1])||void 0===b||b.split("&")[0].includes("-id"),v=d+f,r=f,(s=o?null:this.storable.get(v))?[3,3]:[4,this.api.get({url:r,headers:y})];case 2:s=t.sent().data,this.storable.set(v,s),t.label=3;case 3:return(l=Array.isArray(s)?s:Object.values(s).find((function(e){return Array.isArray(e)}))).length>0&&(h=l[l.length-1].id),p.hasMore=l.length>=p.limit,i(s),[3,5];case 4:return(c=t.sent()).retry=function(){return p.load(n,o)},a(c),[3,5];case 5:return[2]}}))}))}))},loadMore:function(){return new Promise((function(e,n){return r(b,void 0,void 0,(function(){var r,o,i,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),r=f+"&last_id=".concat(h),[4,this.api.get({url:r,headers:y})];case 1:return o=t.sent().data,(i=Array.isArray(o)?o:Object.values(o).find((function(e){return Array.isArray(e)}))).length&&(h=i[i.length-1].id),p.hasMore=i.length>=p.limit,this.storable.insert(v,o),e(o),[3,3];case 2:return(a=t.sent()).retry=function(){return p.loadMore()},n(a),[3,3];case 3:return[2]}}))}))}))},reload:function(e){return p.load(e,!0)}};return p}}),Object.defineProperty(this,"IdPaginator",{enumerable:!0,configurable:!0,writable:!0,value:function(n){var o=n.root,i=n.url,a=n.getUrl,u=n.getHeaders,s=n.limit,l=void 0===s?b.limit:s,c="",d="",h=null,f=a?function(e){return b.getRoot({root:o,url:a(e)})}:function(){return b.getRoot({root:o,url:i})},y={hasMore:!1,limit:l,load:function(n){return new Promise((function(o,i){return r(b,void 0,void 0,(function(){var r,a,s,l,b;return t(this,(function(t){switch(t.label){case 0:c="",t.label=1;case 1:return t.trys.push([1,3,,4]),h=null==u?void 0:u(n),d=this.generateQuery({url:f(n),query:e({limit:y.limit},n)}),r=d,null===(b=d.split("sort")[1])||void 0===b||b.split("&")[0].includes("-id"),[4,this.api.get({url:r,headers:h})];case 2:return a=t.sent().data,(s=Array.isArray(a)?a:Object.values(a).find((function(e){return Array.isArray(e)}))).length>0&&(c=s[s.length-1].id),y.hasMore=s.length>=y.limit,o(a),[3,4];case 3:return(l=t.sent()).retry=function(){return y.load(n)},i(l),[3,4];case 4:return[2]}}))}))}))},loadMore:function(){return new Promise((function(e,n){return r(b,void 0,void 0,(function(){var r,o,i,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),r=d+"&last_id=".concat(c),[4,this.api.get({url:r,headers:h})];case 1:return o=t.sent().data,(i=Array.isArray(o)?o:Object.values(o).find((function(e){return Array.isArray(e)}))).length&&(c=i[i.length-1].id),y.hasMore=i.length>=y.limit,e(o),[3,3];case 2:return(a=t.sent()).retry=function(){return y.loadMore()},n(a),[3,3];case 3:return[2]}}))}))}))},reload:function(e){return y.load(e)}};return y}}),Object.defineProperty(this,"GET",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.headers;return new Promise((function(e,u){return r(b,void 0,void 0,(function(){var r,s,c,d,h,f=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return f.GET({root:n,url:o,query:i,headers:a})},t.label=1;case 1:return t.trys.push([1,3,,4]),s=l({url:this.getRoot({root:n,url:o}),query:i}),[4,this.api.get({url:s,headers:a})];case 2:return c=t.sent(),e(c.data),[3,4];case 3:return d=t.sent(),(h=d).retry=r,u(h),[3,4];case 4:return[2]}}))}))}))}}),Object.defineProperty(this,"GET_WithCash",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.headers,u=e.clearCash,s=e.storageKey,c=void 0===s?"":s,d=e.abortId;return new Promise((function(e,s){return r(b,void 0,void 0,(function(){var r,h,f,b,y,v=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return v.GET_WithCash({root:n,url:o,query:i,headers:a})},t.label=1;case 1:return t.trys.push([1,4,,5]),h=l({url:this.getRoot({root:n,url:o}),query:i}),(f=u?null:this.storable.get(c+h))?[3,3]:[4,this.api.get({url:h,headers:a,abortId:d})];case 2:f=t.sent(),this.storable.set(c+h,f),t.label=3;case 3:return e(f),[3,5];case 4:return b=t.sent(),(y=b).retry=r,s(y),[3,5];case 5:return[2]}}))}))}))}}),Object.defineProperty(this,"POST",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.headers,u=e.getHeaders,s=e.body,c=e.onSuccess,d=e.onError,h=e.abortId;return new Promise((function(e,f){return r(b,void 0,void 0,(function(){var r,b,y,v,g,p=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return p.POST({root:n,url:o,query:i,headers:a,body:s})},t.label=1;case 1:return t.trys.push([1,3,,4]),b=l({url:this.getRoot({root:n,url:o}),query:i}),[4,this.api.post({url:b,body:s,headers:null!=a?a:null==u?void 0:u(i),abortId:h})];case 2:return y=t.sent(),null==c||c(y.data),e(y.data),[3,4];case 3:return v=t.sent(),(g=v).retry=r,null==d||d(g),f(g),[3,4];case 4:return[2]}}))}))}))}}),Object.defineProperty(this,"POST_WithCash",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.headers,u=e.getHeaders,s=e.body,c=e.clearCash,d=e.storageKey,h=void 0===d?"":d,f=e.onError,y=e.onSuccess,v=e.abortId;return new Promise((function(e,d){return r(b,void 0,void 0,(function(){var r,b,g,p,m,w,P=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return P.POST_WithCash({root:n,url:o,query:i,headers:a,body:s,clearCash:c,storageKey:h})},t.label=1;case 1:return t.trys.push([1,4,,5]),b=l({url:this.getRoot({root:n,url:o}),query:i}),g=h+b,(p=c?null:this.storable.get(g))?[3,3]:[4,this.api.post({url:b,body:s,headers:null!=a?a:null==u?void 0:u(i),abortId:v})];case 2:p=t.sent(),this.storable.set(g,p),null==y||y(p),t.label=3;case 3:return e(p),[3,5];case 4:return m=t.sent(),(w=m).retry=r,null==f||f(w),d(w),[3,5];case 5:return[2]}}))}))}))}}),Object.defineProperty(this,"PUT",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.headers,u=e.body,s=e.getHeaders,c=e.onError,d=e.onSuccess;return e.abortId,new Promise((function(e,h){return r(b,void 0,void 0,(function(){var r,f,b,y,v=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return v.PUT({root:n,url:o,query:i,body:u})},t.label=1;case 1:return t.trys.push([1,3,,4]),f=l({url:this.getRoot({root:n,url:o}),query:i}),[4,this.api.put({url:f,body:u,headers:null!=a?a:null==s?void 0:s(i)})];case 2:return b=t.sent(),null==d||d(b.data),e(b.data),[3,4];case 3:return(y=t.sent()).retry=r,null==c||c(y),h(y),[3,4];case 4:return[2]}}))}))}))}}),Object.defineProperty(this,"UPDATE",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.headers,u=e.getHeaders,s=e.body,c=e.onError,d=e.onSuccess,h=e.abortId;return new Promise((function(e,f){return r(b,void 0,void 0,(function(){var r,b,y,v,g=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return g.UPDATE({root:n,url:o,query:i,body:s})},t.label=1;case 1:return t.trys.push([1,3,,4]),b=l({url:this.getRoot({root:n,url:o}),query:i}),[4,this.api.update({url:b,body:s,headers:null!=a?a:null==u?void 0:u(i),abortId:h})];case 2:return y=t.sent(),null==d||d(y.data),e(y.data),[3,4];case 3:return(v=t.sent()).retry=r,null==c||c(v),f(v),[3,4];case 4:return[2]}}))}))}))}}),Object.defineProperty(this,"PATCH",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.body,u=e.headers,s=e.getHeaders,c=e.onError,d=e.onSuccess,h=e.abortId;return new Promise((function(e,f){return r(b,void 0,void 0,(function(){var r,b,y,v,g=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return g.PATCH({root:n,url:o,query:i,body:a})},t.label=1;case 1:return t.trys.push([1,3,,4]),b=l({url:this.getRoot({root:n,url:o}),query:i}),[4,this.api.patch({url:b,body:a,headers:null!=u?u:null==s?void 0:s(i),abortId:h})];case 2:return y=t.sent(),null==d||d(y.data),e(y.data),[3,4];case 3:return(v=t.sent()).retry=r,null==c||c(v),f(v),[3,4];case 4:return[2]}}))}))}))}}),Object.defineProperty(this,"DELETE",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var n=e.root,o=e.url,i=e.query,a=e.body,u=e.headers,s=e.getHeaders,c=e.onError,d=e.onSuccess,h=e.abortId;return new Promise((function(e,f){return r(b,void 0,void 0,(function(){var r,b,y,v,g=this;return t(this,(function(t){switch(t.label){case 0:r=function(){return g.DELETE({root:n,url:o,query:i})},t.label=1;case 1:return t.trys.push([1,3,,4]),b=l({url:this.getRoot({root:n,url:o}),query:i}),[4,this.api.delete({url:b,body:a,headers:null!=u?u:null==s?void 0:s(i),abortId:h})];case 2:return y=t.sent(),null==d||d(y.data),e(y.data),[3,4];case 3:return(v=t.sent()).retry=r,null==c||c(v),f(v),[3,4];case 4:return[2]}}))}))}))}}),this.roots=f,this.useCash=!!d,this.storable=this.useCash?new u({storage:c,storeKey:d}):null,this.useCash||(this.GET_WithCash=this.GET,this.POST_WithCash=this.POST,this.PaginatorWithCash=this.Paginator,this.OffsetPaginatorWithCash=this.OffsetPaginator,this.IdPaginatorWithCash=this.IdPaginator),this.api=a,h&&(this.generateQuery=h),s&&(this.limit=s)}return Object.defineProperty(n,"clearCash",{enumerable:!0,configurable:!0,writable:!0,value:function(e,r){void 0===r&&(r="sessionStorage"),u.clear(r,e)}}),n}(),l=function(e){var r=e.url,t=e.query;if(!t)return r;var n="".concat(r,"?");return"object"==typeof t.query&&(t=t.query),new URLSearchParams(t).forEach((function(e,r){c(e)&&(n+="".concat(r,"=").concat(e,"&"))})),n.endsWith("&")&&(n=n.slice(0,-1)),n},c=function(e){return![void 0,"undefined","null","","none","NaN"].includes(e)};exports.ApiService=o,exports.ClientBuilder=s,exports.Storable=u;