-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathng-rest-api.min.js
1 lines (1 loc) · 7.47 KB
/
ng-rest-api.min.js
1
!function(e){function t(n){if(a[n])return a[n].exports;var i=a[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var a={};return t.m=e,t.c=a,t.p="",t(0)}([function(e,t,a){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=a(1),r=n(i);t["default"]=angular.module("ng-rest-api",["ngResource","angular-cache"]).provider("api",r["default"])},function(e,t,a){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var a=0;a<t.length;a++){var n=t[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,a,n){return a&&e(t.prototype,a),n&&e(t,n),t}}(),o=a(2),u=n(o),c=a(3),s=n(c),l=function(){function e(){i(this,e),this.baseRoute="",this.httpParamSerializerJQLikeMode=!1,this.endpoints={}}return r(e,[{key:"setBaseRoute",value:function(e){this.baseRoute=e}},{key:"setCacheDefaultLifetime",value:function(e){this.cacheDefaultLifetime=e}},{key:"setCacheDefaultStorageMode",value:function(e){this.cacheDefaultStorageMode=e}},{key:"enableHttpParamSerializerJQLikeMode",value:function(){this.httpParamSerializerJQLikeMode=!0}},{key:"endpoint",value:function(e){var t=new u["default"];return this.endpoints[e]=t,t}},{key:"$get",value:["$injector",function(e){"ngInject";var t=this,a={};return angular.forEach(this.endpoints,function(n,i){a[i]=e.instantiate(s["default"],{baseRoute:t.baseRoute,cacheDefaultLifetime:t.cacheDefaultLifetime,cacheDefaultStorageMode:t.cacheDefaultStorageMode,httpParamSerializerJQLikeMode:t.httpParamSerializerJQLikeMode,endpointConfig:n})}),a}]}]),e}();t["default"]=l},function(e,t){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var a=0;a<t.length;a++){var n=t[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,a,n){return a&&e(t.prototype,a),n&&e(t,n),t}}(),i=function(){function e(){var t=this;a(this,e),this.actions={},this.modelClass=!1;var n={GET:"get",PUT:"update",POST:"save",PATCH:"patch",DELETE:"remove"};angular.forEach(n,function(e,a){t.addHttpAction(a,e)})}return n(e,[{key:"route",value:function(e){return this.route=e,this}},{key:"model",value:function(e){return this.modelClass=e,this}},{key:"addHttpAction",value:function(e,t,a){return this.actions[t]=angular.merge({method:e.toUpperCase()},a),this}}]),e}();t["default"]=i},function(e,t,a){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},u=function(){function e(e,t){for(var a=0;a<t.length;a++){var n=t[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,a,n){return a&&e(t.prototype,a),n&&e(t,n),t}}(),c=a(4),s=n(c),l=function(){function e(t,a,n,r,u,c,l,f,h,d){"ngInject";var v=this;i(this,e),this.config=n,this.$injector=l,this.$q=h,this.resource=f(t+n.route,{},n.actions),this.httpParamSerializerJQLikeMode=a,this.$httpParamSerializerJQLike=r,angular.isString(this.config.modelClass)&&(this.config.modelClass=l.get(this.config.modelClass)),angular.forEach(n.actions,function(e,t){var a=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];e.method=e.method.toUpperCase();var i=v.request,r=a[t]?a[t]:{},l={name:t,instantiateModel:r.instantiateModel!==!1,headersForReading:r.headersForReading||!1,isSaveRequest:"PUT"===e.method||"POST"===e.method||"PATCH"===e.method};n.model&&(i=l.isSaveRequest?v.saveRequestWithModel:v.getRequestWithModel);var f="object"===o(r.$cache)?r.$cache.lifetime:null;e.$cache=new s["default"]({name:"api."+t,active:!!r.$cache,lifetime:"number"==typeof f?f:u,storageMode:("object"===o(r.$cache)?r.$cache.storageMode:null)||c,Cache:d}),v[t]=angular.bind(v,i,l),v[t].$cache=e.$cache})}return e.$inject=["baseRoute","httpParamSerializerJQLikeMode","endpointConfig","$httpParamSerializerJQLike","cacheDefaultLifetime","cacheDefaultStorageMode","$injector","$resource","$q","CacheFactory"],u(e,[{key:"instantiateModel",value:function(e){var t=this.config.modelClass?new this.config.modelClass(e):e;return t&&angular.isFunction(t.afterLoad)&&t.afterLoad(),t}},{key:"request",value:function(e){var t=this,a=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];(this.httpParamSerializerJQLikeMode&&e.httpParamSerializerJQLikeMode!==!1||e.httpParamSerializerJQLikeMode)&&(n=this.$httpParamSerializerJQLike(n));var i=!1,o=this.config.actions[e.name].$cache,u=JSON.stringify(r({},e.name,a,n)),c=null;this.config.actions[e.name].transformResponse=function(t,a){e.headersForReading&&Array.isArray(e.headersForReading)&&!function(){var t=a()||o.headers(u);i={},e.headersForReading.map(function(e){t[e]&&(i[e]=t[e])})}();var n=e.instantiateModel&&t?angular.fromJson(t):{data:t};return o.isActive()&&o.put(u,n,i),n},o.isActive()&&(c=o.get(u),i=o.headers(u));var s=c?new Promise(function(e){return e(c)}):this.resource[e.name](a,n).$promise;return s.then(function(a){var n=null;return n=e.instantiateModel?angular.isArray(a)?a.map(function(e){return t.instantiateModel(e)}):function(){return t.instantiateModel(a)}():a.data,n=i?[n,i]:n})}},{key:"getRequestWithModel",value:function(e,t){return this.request(e,t)}},{key:"saveRequestWithModel",value:function(e,t,a){a||(a=t,t={});var n=angular.copy(a);return n&&angular.isFunction(n.beforeSave)&&n.beforeSave(),this.request(e,t,n)}}]),e}();t["default"]=l},function(e,t){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var a=0;a<t.length;a++){var n=t[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,a,n){return a&&e(t.prototype,a),n&&e(t,n),t}}(),i=function(){function e(t){var n=t.name,i=t.active,r=t.storageMode,o=t.lifetime,u=t.Cache;a(this,e),this.name=n,this.active=i,this.lifetime=o,this.lastCacheTime={},this.cacher=u.get(n)||u.createCache(n,{storageMode:r||"localStorage"}),this._headerPostfix=".headers"}return n(e,[{key:"_isValid",value:function(e){var t=(new Date).getTime();return!this.lifetime||this.lastCacheTime[e]+this.lifetime>t}},{key:"isActive",value:function(){return!!this.active}},{key:"enable",value:function(e){this.active=e}},{key:"setLifetime",value:function(e){this.lifetime=e}},{key:"clear",value:function(){this.cacher.removeAll()}},{key:"get",value:function(e){return this._isValid(e)?this.cacher.get(e):null}},{key:"headers",value:function(e){return this._isValid(e)?this.cacher.get(e+this._headerPostfix):null}},{key:"put",value:function(e,t,a){this.cacher.put(e,t),this.cacher.put(e+this._headerPostfix,a),this.lastCacheTime[e]=(new Date).getTime()}}]),e}();t["default"]=i}]);