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

angular-resource-factory

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-resource-factory - npm Package Compare versions

Comparing version 0.8.10 to 0.8.11

dist/doc/cache_cacheService.js.html

2

dist/ngresourcefactory.min.js

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

!function(root,factory){var i,resolved=[],required=["require","exports","module","angular"],len=required.length;if("function"==typeof define&&define.amd)define("ngresourcefactory",["require","exports","module","angular"],factory);else if("object"==typeof exports){for(i=0;i<len;i+=1)resolved.push(require(required[i]));module.exports=factory.apply({},resolved)}else{for(i=0;i<len;i+=1)resolved.push(root[required[i]]);root.ngresourcefactory=factory.apply({},resolved)}}(this,function(require,exports,module,angular){return function(){"use strict";angular.module("ngResourceFactory",["ngResource"])}(),function(){"use strict";angular.module("ngResourceFactory").factory("ResourceCacheService",function(){"ngInject";function constructor(name,pkAttr,options){function isJsonContentType(contentType){return!!contentType&&("application/json"===contentType||0===String(contentType).indexOf("application/json;"))}function getDataForKey(key){if(cache.hasOwnProperty(key))return getDataForEntry(cache[key],cacheUseDataAttr[key])}function getDataForEntry(value,useDataAttr){var data=value[1];return useDataAttr&&options.dataAttr&&data?data[options.dataAttr]:data}function setDataForKey(key,newData){if(cache.hasOwnProperty(key)){var entry=cache[key],entryUseDataAttr=cacheUseDataAttr[key],entryData=entry[1];entryUseDataAttr&&options.dataAttr&&entryData?entryData[options.dataAttr]=newData:entryData=newData,entry[1]=entryData}}function getCurrentTimestamp(){return Math.floor(Date.now()/1e3)}function createOrUpdateTimestamp(key){return cacheTimestamps[key]=getCurrentTimestamp(),cacheTimestamps[key]}function isEntryAlive(key){return!!cache.hasOwnProperty(key)&&getCurrentTimestamp()-cacheTimestamps[key]<=options.ttl}function refreshSingle(newData){var urlAttr=options.urlAttr;urlAttr&&newData&&newData[urlAttr]&&self.insert(newData[urlAttr],newData,!1,!1);for(var key in cache)if(cache.hasOwnProperty(key)&&cacheIsManaged[key]){var entry=cache[key],entryUseDataAttr=cacheUseDataAttr[key],entryData=getDataForEntry(entry,entryUseDataAttr),isList=angular.isArray(entryData);if(isList){for(var i=0;i<entryData.length;i++)entryData[i][pkAttr]===newData[pkAttr]&&(!urlAttr||urlAttr&&entryData[i][urlAttr]===newData[urlAttr])&&(entryData[i]=newData);setDataForKey(key,entryData)}else entryData[pkAttr]===newData[pkAttr]&&(!urlAttr||urlAttr&&entryData[urlAttr]===newData[urlAttr])&&(setDataForKey(key,newData),createOrUpdateTimestamp(key))}}function refreshEach(newEntries){for(var i=0;i<newEntries.length;i++)refreshSingle(newEntries[i])}var self=this,cache={},cacheUseDataAttr={},cacheIsManaged={},cacheTimestamps={};options=angular.extend({pkAttr:null,urlAttr:null,dataAttr:null,dependent:[],ttl:3600},options||{}),function(){if(caches.hasOwnProperty(name))throw Error("Name '"+name+"' is already used by another cache.");caches[name]=self}(),self.refresh=function(value){angular.isArray(value)?refreshEach(value):angular.isObject(value)&&refreshSingle(value)},self.insert=function(key,value,useDataAttr,refresh){var isManaged=angular.isObject(value)||angular.isArray(value),headers=isManaged?{"content-type":"application/json"}:{},entry=[200,value,headers,"OK"];useDataAttr=!!useDataAttr,refresh=!!angular.isUndefined(refresh)||!!refresh,key&&(cache[key]=entry,cacheUseDataAttr[key]=useDataAttr&&isManaged,cacheIsManaged[key]=isManaged,createOrUpdateTimestamp(key),refresh&&self.refresh(getDataForEntry(entry,useDataAttr)))},self.put=function(key,value,useDataAttr){useDataAttr=!!useDataAttr;var isManaged=!1;key&&(value&&value[2]&&isJsonContentType(value[2]["content-type"])?(value[1]=value[1]?angular.fromJson(value[1]):null,isManaged=!0):(useDataAttr=!1,isManaged=!1),cache[key]=value,cacheUseDataAttr[key]=useDataAttr,cacheIsManaged[key]=isManaged,createOrUpdateTimestamp(key),isManaged&&self.refresh(getDataForEntry(value,useDataAttr)))},self.get=function(key,useCacheTtl){var value=void 0;return useCacheTtl=!(!angular.isUndefined(useCacheTtl)&&!useCacheTtl),cache.hasOwnProperty(key)&&(!useCacheTtl||isEntryAlive(key)?(value=cache[key],cacheIsManaged[key]&&(value=angular.copy(value),value[1]=angular.toJson(value[1]))):self.remove(key)),value},self.remove=function(key){cache.hasOwnProperty(key)&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAll=function(){for(var key in cache)cache.hasOwnProperty(key)&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAllLists=function(){for(var key in cache)cache.hasOwnProperty(key)&&angular.isArray(getDataForKey(key))&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAllObjects=function(){for(var key in cache)cache.hasOwnProperty(key)&&angular.isObject(getDataForKey(key))&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAllRaw=function(){for(var key in cache)cache.hasOwnProperty(key)&&!cacheIsManaged[key]&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAllDependent=function(){for(var dependentCacheNames=collectDependentCacheNames(self,[]),i=0;i<dependentCacheNames.length;i++)caches[dependentCacheNames[i]].removeAll()},self.destroy=function(){var cacheIndex=caches.indexOf(self);cacheIndex!==-1&&(self.removeAll(),caches.splice(cacheIndex,1))},self.info=function(){var size=0;for(var key in cache)cache.hasOwnProperty(key)&&size++;return{id:name,size:size,options:options}},self.withDataAttr={put:function(key,value){return self.put(key,value,!0)},get:function(key){return self.get(key,!0)},remove:self.remove,removeAll:self.removeAll,info:self.info},self.withoutDataAttr={put:function(key,value){return self.put(key,value,!1)},get:function(key){return self.get(key,!0)},remove:self.remove,removeAll:self.removeAll,info:self.info},self.withDataAttrNoTtl={put:function(key,value){return self.put(key,value,!0)},get:function(key){return self.get(key,!1)},remove:self.remove,removeAll:self.removeAll,info:self.info},self.withoutDataAttrNoTtl={put:function(key,value){return self.put(key,value,!1)},get:function(key){return self.get(key,!1)},remove:self.remove,removeAll:self.removeAll,info:self.info}}function collectDependentCacheNames(cache,collectedDependentCacheNames){var cacheDependentCacheNames=cache.info().options.dependent;collectedDependentCacheNames=collectedDependentCacheNames||[];for(var i=0;i<cacheDependentCacheNames.length;i++){var cacheDependentCacheName=cacheDependentCacheNames[i],cacheDependentCache=caches[cacheDependentCacheName];cacheDependentCache&&(collectedDependentCacheNames.push(cacheDependentCacheName),collectedDependentCacheNames.indexOf(cacheDependentCacheName)===-1&&collectDependentCacheNames(cacheDependentCache,collectedDependentCacheNames))}return collectedDependentCacheNames}var caches={};return constructor.removeAll=function(){for(var key in caches)caches.hasOwnProperty(key)&&caches[key].removeAll()},constructor.get=function(key){return caches.hasOwnProperty(key)?caches[key]:null},constructor.info=function(){var infos={};for(var key in caches)if(caches.hasOwnProperty(key)){var info=caches[key].info();infos[info.id]=info}return infos},constructor})}(),function(){"use strict";angular.module("ngResourceFactory").factory("ResourceFactoryService",["$q","$resource","ResourceCacheService","ResourcePhantomIdNegativeInt",function($q,$resource,ResourceCacheService,ResourcePhantomIdNegativeInt){"ngInject";function ResourceStore(resource,managedInstances,parentStore){function addResourceInstance(instances,instance){var matchingInstances=resource.filterInstancesByAttr(instances,resource.getPkAttr(),instance[resource.getPkAttr()]);if(matchingInstances.length)for(var i=0;i<matchingInstances.length;i++){var matchingInstanceIndex=instances.indexOf(matchingInstances[i]),matchingInstanceFound=matchingInstanceIndex!==-1;matchingInstanceFound&&instances.splice(matchingInstanceIndex,1,instance)}else instances.push(instance)}function removeResourceInstance(instances,instance){var matchingInstances=resource.filterInstancesByAttr(instances,resource.getPkAttr(),instance[resource.getPkAttr()]);if(matchingInstances.length)for(var i=0;i<matchingInstances.length;i++){var matchingInstanceIndex=instances.indexOf(matchingInstances[i]),matchingInstanceFound=matchingInstanceIndex!==-1;matchingInstanceFound&&instances.splice(matchingInstanceIndex,1)}}function isPromiseLike(obj){return obj&&angular.isFunction(obj.then)}function populate(dst,src,keepMissing){keepMissing=!!angular.isUndefined(keepMissing)||!!keepMissing,dst=dst||void 0;var key,preserve=!!dst,preservedObjects={};src=angular.copy(src);for(key in src)src.hasOwnProperty(key)&&"$"===key[0]&&delete src[key];if(preserve)for(key in dst)dst.hasOwnProperty(key)&&("$"===key[0]?preservedObjects[key]=dst[key]:keepMissing&&!src.hasOwnProperty(key)&&(preservedObjects[key]=dst[key]));if(dst=angular.copy(src,dst),preserve)for(key in preservedObjects)preservedObjects.hasOwnProperty(key)&&(dst[key]=preservedObjects[key]);return dst}function copy(src,dst){if(angular.isArray(src)){dst=angular.isArray(dst)?dst:[],dst.length=0;for(var i=0;i<src.length;i++)dst.push(populate(null,src[i],!1))}else dst=populate(dst,src,!1);return dst}function merge(src,dst){if(angular.isArray(src)){dst=angular.isArray(dst)?dst:[],dst.length=0;for(var i=0;i<src.length;i++)dst.push(populate(null,src[i],!0))}else dst=populate(dst,src,!0);return dst}var self=this,executionRunning=(resource.getResourceName(),!1),relations=[],visibleQueue=[],persistQueue=[],removeQueue=[],beforePersistListeners=[],afterPersistListeners=[],beforeRemoveListeners=[],afterRemoveListeners=[];self.manage=function(newInstances){var doManage=function(newInstances){angular.isArray(newInstances)||(newInstances=[newInstances]);for(var i=0;i<newInstances.length;i++){var newInstance=newInstances[i];newInstance.$store?newInstance.$store:(newInstance.$store=self,addResourceInstance(managedInstances,newInstance),addResourceInstance(visibleQueue,newInstance))}};if(isPromiseLike(newInstances)||isPromiseLike(newInstances.$promise)){var promise=isPromiseLike(newInstances)?newInstances:newInstances.$promise,defer=$q.defer();return promise.then(doManage).then(function(){defer.resolve(newInstances)}),defer.promise}return doManage(newInstances),$q.resolve(newInstances)},self.forget=function(oldInstances){var doForget=function(oldInstances){angular.isArray(oldInstances)||(oldInstances=[oldInstances]);for(var i=0;i<oldInstances.length;i++){var oldInstance=oldInstances[i];oldInstance.$store===self?(delete oldInstance.$store,removeResourceInstance(managedInstances,oldInstance),removeResourceInstance(visibleQueue,oldInstance),removeResourceInstance(persistQueue,oldInstance),removeResourceInstance(removeQueue,oldInstance)):oldInstance.$store}};if(isPromiseLike(oldInstances)||isPromiseLike(oldInstances.$promise)){var promise=isPromiseLike(oldInstances)?oldInstances:oldInstances.$promise,defer=$q.defer();return promise.then(doForget).then(function(){defer.resolve(oldInstances)}),defer.promise}return doForget(oldInstances),$q.resolve(oldInstances)},self.new=function(params){var newInstance=resource.new(params);return self.manage(newInstance),newInstance},self.persist=function(instances){angular.isArray(instances)||(instances=[instances]);for(var i=0;i<instances.length;i++){var instance=instances[i];instance.$store===self&&(addResourceInstance(persistQueue,instance),addResourceInstance(visibleQueue,instance),removeResourceInstance(removeQueue,instance))}},self.remove=function(instances){angular.isArray(instances)||(instances=[instances]);for(var i=0;i<instances.length;i++){var instance=instances[i];instance.$store===self&&(removeResourceInstance(persistQueue,instance),removeResourceInstance(visibleQueue,instance),addResourceInstance(removeQueue,instance))}},self.commit=function(){if(parentStore){for(var i=0;i<persistQueue.length;i++){var childPersistInstance=copy(persistQueue[i]),parentPersistInstance=parentStore.getByInstance(childPersistInstance);delete childPersistInstance.$store,parentPersistInstance?merge(childPersistInstance,parentPersistInstance):(parentPersistInstance=copy(childPersistInstance),parentStore.manage(parentPersistInstance)),parentStore.persist(parentPersistInstance)}for(var j=0;j<removeQueue.length;j++){var childRemoveInstance=copy(removeQueue[i]),parentRemoveInstance=parentStore.getByInstance(childRemoveInstance);delete childRemoveInstance.$store,parentRemoveInstance?merge(childRemoveInstance,parentRemoveInstance):(parentRemoveInstance=copy(childRemoveInstance),parentStore.manage(parentRemoveInstance)),parentStore.remove(parentRemoveInstance)}}},self.executeAll=function(clearAfter){clearAfter=angular.isUndefined(clearAfter)||!!clearAfter;var defer=$q.defer(),executeRelated=function(){for(var promises=[],i=0;i<relations.length;i++){var relation=relations[i],relatedStore=relation.getRelatedStore();promises.push(relatedStore.executeAll(clearAfter))}return $q.all(promises)};return self.execute(clearAfter).then(executeRelated).then(defer.resolve).catch(defer.reject),defer.promise},self.execute=function(clearAfter){if(clearAfter=angular.isUndefined(clearAfter)||!!clearAfter,executionRunning)return $q.reject("Another execution is already running.");if(parentStore)throw"Executing the store is only possible on the topmost store";executionRunning=!0;var defer=$q.defer(),handleError=function(reason){executionRunning=!1,defer.reject(reason)},callListeners=function(item,listeners){for(var i=0;i<listeners.length;i++)listeners[i](item)},relationsRemove=function(pkValue){for(var i=0;i<relations.length;i++)relations[i].handleRemove(pkValue)},relationsUpdate=function(oldPkValue,newPkValue){for(var i=0;i<relations.length;i++)relations[i].handleUpdate(oldPkValue,newPkValue)},executeSingle=function(item,execFn,beforeListeners,afterListeners,defer,isRemove){callListeners(item,beforeListeners),execFn({},item).$promise.then(function(response){if(isRemove&&item&&relationsRemove(item[resource.getPkAttr()]),response&&response[resource.getPkAttr()]){var oldPkValue=item?item[resource.getPkAttr()]:null,newPkValue=response?response[resource.getPkAttr()]:null;isRemove||relationsUpdate(oldPkValue,newPkValue),item[resource.getPkAttr()]=newPkValue}callListeners(item,afterListeners),defer.resolve(item)}).catch(defer.reject)},executeRemoves=function(){for(var promises=[],queue=self.getRemoveQueue(),i=0;i<queue.length;i++){var item=queue[i];if(!item.$isPhantom()){var defer=$q.defer();promises.push(defer.promise),executeSingle(item,resource.remove,beforeRemoveListeners,afterRemoveListeners,defer,!0)}}return $q.all(promises)},executeUpdates=function(){for(var promises=[],queue=self.getUpdateQueue(),i=0;i<queue.length;i++){var item=queue[i],defer=$q.defer();promises.push(defer.promise),executeSingle(item,resource.update,beforePersistListeners,afterPersistListeners,defer,!1)}return $q.all(promises)},executeSaves=function(){for(var promises=[],queue=self.getSaveQueue(),i=0;i<queue.length;i++){var item=queue[i],defer=$q.defer();promises.push(defer.promise),executeSingle(item,resource.save,beforePersistListeners,afterPersistListeners,defer,!1)}return $q.all(promises)},clear=function(){clearAfter&&(persistQueue.length=0,removeQueue.length=0),executionRunning=!1};return $q.when().then(executeRemoves).then(executeUpdates).then(executeSaves).then(clear).then(defer.resolve).catch(handleError),defer.promise},self.createChildStore=function(instances){return instances=instances||managedInstances,new ResourceStore(resource,copy(instances),self)},self.createRelation=function(config){config=angular.extend({relatedStore:null,fkAttr:null,onDelete:"forget",onUpdate:"update"},config);var relation=new ResourceStoreRelation(self,config.relatedStore,config.fkAttr,config.onUpdate,config.onDelete);return relations.push(relation),relation},self.removeRelation=function(relation){var relationIndex=relations.indexOf(relation);relationIndex!==-1&&relations.splice(relationIndex,1)},self.getByPk=function(pkValue){return resource.getInstanceByPk(managedInstances,pkValue)},self.getByInstance=function(instance){var pkValue=instance?instance[resource.getPkAttr()]:void 0;return self.getByPk(pkValue)},self.getManagedInstances=function(){return managedInstances.slice()},self.getVisibleQueue=function(){return visibleQueue.slice()},self.getPersistQueue=function(){return persistQueue.slice()},self.getRemoveQueue=function(){return removeQueue.slice()},self.getSaveQueue=function(){var filterPhantom=function(instance){return instance.$isPhantom()};return persistQueue.filter(filterPhantom)},self.getUpdateQueue=function(){var filterNonPhantom=function(instance){return!instance.$isPhantom()};return persistQueue.filter(filterNonPhantom)},self.getResourceService=function(){return resource},self.addBeforePersistListener=function(fn){beforePersistListeners.push(fn)},self.removeBeforePersistListener=function(fn){var fnIndex=beforePersistListeners.indexOf(fn);fnIndex!==-1&&beforePersistListeners.splice(fnIndex,1)},self.addAfterPersistListener=function(fn){afterPersistListeners.push(fn)},self.removeAfterPersistListener=function(fn){var fnIndex=afterPersistListeners.indexOf(fn);fnIndex!==-1&&afterPersistListeners.splice(fnIndex,1)},self.addBeforeRemoveListener=function(fn){beforeRemoveListeners.push(fn)},self.removeBeforeRemoveListener=function(fn){var fnIndex=beforeRemoveListeners.indexOf(fn);fnIndex!==-1&&beforeRemoveListeners.splice(fnIndex,1)},self.addAfterRemoveListener=function(fn){afterRemoveListeners.push(fn)},self.removeAfterRemoveListener=function(fn){var fnIndex=afterRemoveListeners.indexOf(fn);fnIndex!==-1&&afterRemoveListeners.splice(fnIndex,1)},function(){managedInstances=managedInstances||[],parentStore=parentStore||null;var managed=self.manage(managedInstances),mapPk=function(instance){return instance?String(instance[resource.getPkAttr()]):void 0},filterPks=function(pks){return function(instance){return!!instance&&pks.indexOf(String(instance[resource.getPkAttr()]))!==-1}};parentStore&&managed.then(function(){var parentVisibleQueuePks=parentStore.getVisibleQueue().map(mapPk),parentPersistQueuePks=parentStore.getPersistQueue().map(mapPk),parentRemoveQueuePks=parentStore.getRemoveQueue().map(mapPk);visibleQueue=managedInstances.filter(filterPks(parentVisibleQueuePks)),persistQueue=managedInstances.filter(filterPks(parentPersistQueuePks)),removeQueue=managedInstances.filter(filterPks(parentRemoveQueuePks))})}()}function ResourceStoreRelation(store,relatedStore,fkAttr,onUpdate,onRemove){var self=this;switch(onUpdate){case"update":onUpdate=function(referencingStore,referencingInstance,oldReferencedInstancePk,newReferencedInstancePk,fkAttr){referencingInstance[fkAttr]=newReferencedInstancePk};break;case"null":onUpdate=function(referencingStore,referencingInstance,oldReferencedInstancePk,newReferencedInstancePk,fkAttr){referencingInstance[fkAttr]=null}}switch(onRemove){case"forget":onRemove=function(referencingStore,referencingInstance,oldReferencedInstancePk,fkAttr){referencingStore.forget(referencingInstance)};break;case"null":onRemove=function(referencingStore,referencingInstance,oldReferencedInstancePk,fkAttr){referencingInstance[fkAttr]=null}}self.getStore=function(){return store},self.getRelatedStore=function(){return relatedStore},self.getFkAttr=function(){return fkAttr},self.handleUpdate=function(oldPkValue,newPkValue){for(var referencingInstances=relatedStore.getManagedInstances(),i=0;i<referencingInstances.length;i++){var referencingInstance=referencingInstances[i];referencingInstance&&referencingInstance[fkAttr]==oldPkValue&&oldPkValue!=newPkValue&&onUpdate(relatedStore,referencingInstance,oldPkValue,newPkValue,fkAttr)}},self.handleRemove=function(pkValue){for(var referencingInstances=relatedStore.getManagedInstances(),i=0;i<referencingInstances.length;i++){var referencingInstance=referencingInstances[i];referencingInstance&&referencingInstance[fkAttr]==pkValue&&onRemove(relatedStore,referencingInstance,pkValue,fkAttr)}}}return function(name,url,options){options=angular.extend({stripTrailingSlashes:!1,ignoreLoadingBar:!1,generatePhantomIds:!0,phantomIdGenerator:ResourcePhantomIdNegativeInt,dependent:[],extraMethods:{},extraFunctions:{},pkAttr:"pk",urlAttr:"url",queryDataAttr:null,queryTotalAttr:null,queryFilter:{},cacheClass:ResourceCacheService,toInternal:function(obj,headersGetter,status){return obj},fromInternal:function(obj,headersGetter){return obj}},options||{});var resource,minError=angular.$$minErr("ngResourceFactory"),paramsDefaults={},saveParams={},queryParams={},cache=new options.cacheClass(name,options.pkAttr,{dataAttr:options.queryDataAttr,pkAttr:options.pkAttr,urlAttr:options.urlAttr,dependent:options.dependent,ttl:900}),queryInterceptor={response:function(response){var data=response.data,instance=response.resource;return instance.total=data.total,instance}},insertingInterceptor={response:function(response){var instance=response.resource,url=options.urlAttr?instance[options.urlAttr]:null;return cache.removeAllRaw(),cache.removeAllLists(),cache.removeAllDependent(),url?cache.insert(url,instance,!1):cache.removeAllObjects(),instance}},modifyingInterceptor={response:function(response){var instance=response.resource,url=options.urlAttr?instance[options.urlAttr]:response.config.url;return cache.removeAllRaw(),cache.removeAllLists(),cache.removeAllDependent(),url?cache.insert(url,instance,!1):cache.removeAllObjects(),instance}},deletingInterceptor={response:function(response){var instance=response.resource,url=options.urlAttr?instance[options.urlAttr]:response.config.url;return cache.removeAllRaw(),cache.removeAllLists(),cache.removeAllDependent(),url?cache.remove(url):cache.removeAllObjects(),instance}},transformResponseFromJson=function(responseText,headersGetter,status){return responseText?angular.fromJson(responseText):null},queryTransformResponseToInternal=function(responseData,headersGetter,status){if(angular.isArray(responseData))for(var i=0;i<responseData.length;i++)responseData[i]=options.toInternal(responseData[i],headersGetter,status);else responseData=options.toInternal(responseData,headersGetter,status);return responseData},singleTransformResponseToInternal=function(responseData,headersGetter,status){return options.toInternal(responseData,headersGetter,status)},queryTransformResponseData=function(responseData,headersGetter,status){var result=null;return status>=200&&status<300?(result=options.queryDataAttr&&responseData?responseData[options.queryDataAttr]:responseData,options.queryTotalAttr&&responseData&&responseData[options.queryTotalAttr]&&(result.total=responseData[options.queryTotalAttr])):result=responseData,result},transformRequestToJson=function(requestData,headersGetter){for(var filterPrivate=function(key){return"$"===String(key)[0]},keys=angular.isObject(requestData)?Object.keys(requestData):[],privateKeys=keys.filter(filterPrivate),i=0;i<privateKeys.length;i++)delete requestData[privateKeys[i]];return angular.toJson(requestData)},singleTransformRequestFromInternal=function(requestData,headersGetter){return options.fromInternal(angular.copy(requestData),headersGetter)},methods={restore:{method:"GET",isArray:!1,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,cache:cache.withoutDataAttrNoTtl,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},get:{method:"GET",isArray:!1,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,cache:cache.withoutDataAttr,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},getNoCache:{method:"GET",isArray:!1,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},query:{method:"GET",isArray:!0,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:queryInterceptor,cache:cache.withDataAttr,transformResponse:[transformResponseFromJson,queryTransformResponseData,queryTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},queryNoCache:{method:"GET",isArray:!0,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:queryInterceptor,transformResponse:[transformResponseFromJson,queryTransformResponseData,queryTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},save:{method:"POST",isArray:!1,withCredentials:!0,cancellable:!1,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:insertingInterceptor,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},update:{method:"PATCH",isArray:!1,withCredentials:!0,cancellable:!1,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:modifyingInterceptor,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},remove:{method:"DELETE",isArray:!1,withCredentials:!0,cancellable:!1,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:deletingInterceptor,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]}};angular.extend(methods,options.extraMethods);for(var methodName in methods)if(methods.hasOwnProperty(methodName)){var bgMethodName=methodName+"Bg",bgMethodConfig=angular.copy(methods[methodName]);bgMethodConfig.ignoreLoadingBar=!0,methods[bgMethodName]=bgMethodConfig}return paramsDefaults[options.pkAttr]="@"+options.pkAttr,saveParams[options.pkAttr]=null,queryParams[options.pkAttr]=null,methods.save.params=saveParams,methods.saveBg.params=saveParams,methods.query.params=queryParams,methods.queryBg.params=queryParams,methods.queryNoCache.params=queryParams,methods.queryNoCacheBg.params=queryParams,resource=$resource(url,paramsDefaults,methods,{stripTrailingSlashes:options.stripTrailingSlashes}),resource.getPkAttr=function(){return options.pkAttr},resource.getQueryDataAttr=function(){return options.queryDataAttr},resource.getQueryTotalAttr=function(){return options.queryTotalAttr},resource.getCacheClass=function(){return options.cacheClass},resource.getQueryFilters=function(){return options.queryFilter},resource.setQueryFilters=function(filters){return angular.copy(filters,options.queryFilter)},resource.setDefaultQueryFilters=function(defaultFilters){var filters=angular.extend({},defaultFilters,options.queryFilter);return angular.copy(filters,options.queryFilter)},resource.filter=function(filters){return filters=angular.extend({},resource.getQueryFilters(),filters),resource.query(filters)},resource.filterNoCache=function(filters){return filters=angular.extend({},resource.getQueryFilters(),filters),resource.queryNoCache(filters)},resource.new=function(params){var phantomInstance=new resource(params);return options.pkAttr&&options.generatePhantomIds&&options.phantomIdGenerator&&(phantomInstance[options.pkAttr]=options.phantomIdGenerator.generate(phantomInstance)),phantomInstance},resource.isPhantom=function(instance){var pkValue=instance?instance[options.pkAttr]:void 0;if(options.pkAttr&&options.generatePhantomIds&&options.phantomIdGenerator)return options.phantomIdGenerator.isPhantom(pkValue,instance)},resource.filterInstancesByAttr=function(instances,attrName,attrValue){var filterAttrValue=function(item){return!!item&&item[attrName]==attrValue};return instances.filter(filterAttrValue)},resource.getInstanceByAttr=function(instances,attrName,attrValue){var result=null,filteredInstances=resource.filterInstancesByAttr(instances,attrName,attrValue);return filteredInstances.length&&(filteredInstances.length,result=filteredInstances[0]),result},resource.getInstanceByPk=function(instances,pkValue){return resource.getInstanceByAttr(instances,options.pkAttr,pkValue)},resource.getResourceName=function(){return name},resource.getCache=function(){return cache},resource.createStore=function(instances){return new ResourceStore(resource,instances,null)},resource.persist=function(a1,a2,a3,a4){var instance,successFn,errorFn,params={};switch(arguments.length){case 4:params=a1,instance=a2,successFn=a3,errorFn=a4;break;case 3:angular.isFunction(a2)?(instance=a1,successFn=a2,errorFn=a3):(params=a1,instance=a2,successFn=a3);break;case 2:angular.isFunction(a2)?(instance=a1,successFn=a2):(params=a1,instance=a2);break;case 1:instance=a1;break;default:throw minError("badargs","Expected up to 4 arguments [params, instance, success, error], got {0} arguments",arguments.length)}return(resource.isPhantom(instance)?resource.save:resource.update)(params,instance,successFn,errorFn)},angular.extend(resource.prototype,{$persist:function(a1,a2,a3){var instance=this;return angular.isFunction(a1)&&(a2=a1,a3=a2,a1={}),resource.persist(a1,instance,a2,a3).$promise},$isPhantom:function(){return resource.isPhantom(this)}}),angular.extend(resource.prototype,options.extraFunctions),resource}}])}(),function(){"use strict";var module=angular.module("ngResourceFactory");module.service("ResourcePhantomIdFactoryService",function(){"ngInject";function ResourcePhantomIdFactory(generateFn,isPhantomFn){var self=this;self.generate=function(instance){return generateFn(instance)},self.isPhantom=function(pkValue,instance){return isPhantomFn(pkValue,instance)}}this.createPhantomIdFactory=function(config){return config=angular.extend({generate:function(){},is:function(){}},config),new ResourcePhantomIdFactory(config.generate,config.is)}}),module.factory("ResourcePhantomIdNegativeInt",["ResourcePhantomIdFactoryService",function(ResourcePhantomIdFactoryService){"ngInject";var lastPkValue=0;return ResourcePhantomIdFactoryService.createPhantomIdFactory({generate:function(){return--lastPkValue},is:function(pkValue){return pkValue<0}})}]),module.factory("ResourcePhantomIdUuid4",["ResourcePhantomIdFactoryService",function(ResourcePhantomIdFactoryService){"ngInject";function uuid4(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var r=16*Math.random()|0;return("x"===c?r:3&r|8).toString(16)})}var generatedIds=[];return ResourcePhantomIdFactoryService.createPhantomIdFactory({generate:function(){var pkValue=uuid4();return generatedIds.push(pkValue),pkValue},is:function(pkValue){return generatedIds.indexOf(pkValue)!==-1}})}])}(),angular.module("ngResourceFactory")});
!function(root,factory){var i,resolved=[],required=["require","exports","module","angular"],len=required.length;if("function"==typeof define&&define.amd)define("ngresourcefactory",["require","exports","module","angular"],factory);else if("object"==typeof exports){for(i=0;i<len;i+=1)resolved.push(require(required[i]));module.exports=factory.apply({},resolved)}else{for(i=0;i<len;i+=1)resolved.push(root[required[i]]);root.ngresourcefactory=factory.apply({},resolved)}}(this,function(require,exports,module,angular){return function(){"use strict";angular.module("ngResourceFactory",["ngResource"])}(),function(){"use strict";angular.module("ngResourceFactory").factory("ResourceCacheService",function(){"ngInject";function constructor(name,pkAttr,options){function isJsonContentType(contentType){return!!contentType&&("application/json"===contentType||0===String(contentType).indexOf("application/json;"))}function getDataForKey(key){if(cache.hasOwnProperty(key))return getDataForEntry(cache[key],cacheUseDataAttr[key])}function getDataForEntry(value,useDataAttr){var data=value[1];return useDataAttr&&options.dataAttr&&data?data[options.dataAttr]:data}function setDataForKey(key,newData){if(cache.hasOwnProperty(key)){var entry=cache[key],entryUseDataAttr=cacheUseDataAttr[key],entryData=entry[1];entryUseDataAttr&&options.dataAttr&&entryData?entryData[options.dataAttr]=newData:entryData=newData,entry[1]=entryData}}function getCurrentTimestamp(){return Math.floor(Date.now()/1e3)}function createOrUpdateTimestamp(key){return cacheTimestamps[key]=getCurrentTimestamp(),cacheTimestamps[key]}function isEntryAlive(key){return!!cache.hasOwnProperty(key)&&getCurrentTimestamp()-cacheTimestamps[key]<=options.ttl}function refreshSingle(newData){var urlAttr=options.urlAttr;urlAttr&&newData&&newData[urlAttr]&&self.insert(newData[urlAttr],newData,!1,!1);for(var key in cache)if(cache.hasOwnProperty(key)&&cacheIsManaged[key]){var entry=cache[key],entryUseDataAttr=cacheUseDataAttr[key],entryData=getDataForEntry(entry,entryUseDataAttr),isList=angular.isArray(entryData);if(isList){for(var i=0;i<entryData.length;i++)entryData[i][pkAttr]===newData[pkAttr]&&(!urlAttr||urlAttr&&entryData[i][urlAttr]===newData[urlAttr])&&(entryData[i]=newData);setDataForKey(key,entryData)}else entryData[pkAttr]===newData[pkAttr]&&(!urlAttr||urlAttr&&entryData[urlAttr]===newData[urlAttr])&&(setDataForKey(key,newData),createOrUpdateTimestamp(key))}}function refreshEach(newEntries){for(var i=0;i<newEntries.length;i++)refreshSingle(newEntries[i])}var self=this,cache={},cacheUseDataAttr={},cacheIsManaged={},cacheTimestamps={};options=angular.extend({urlAttr:null,dataAttr:null,dependent:[],ttl:3600},options||{}),function(){if(caches.hasOwnProperty(name))throw Error("Name '"+name+"' is already used by another cache.");caches[name]=self}(),self.refresh=function(value){angular.isArray(value)?refreshEach(value):angular.isObject(value)&&refreshSingle(value)},self.insert=function(key,value,useDataAttr,refresh){var isManaged=angular.isObject(value)||angular.isArray(value),headers=isManaged?{"content-type":"application/json"}:{},entry=[200,value,headers,"OK"];useDataAttr=!!useDataAttr,refresh=!!angular.isUndefined(refresh)||!!refresh,key&&(cache[key]=entry,cacheUseDataAttr[key]=useDataAttr&&isManaged,cacheIsManaged[key]=isManaged,createOrUpdateTimestamp(key),refresh&&self.refresh(getDataForEntry(entry,useDataAttr)))},self.put=function(key,value,useDataAttr){useDataAttr=!!useDataAttr;var isManaged=!1;key&&(value&&value[2]&&isJsonContentType(value[2]["content-type"])?(value[1]=value[1]?angular.fromJson(value[1]):null,isManaged=!0):(useDataAttr=!1,isManaged=!1),cache[key]=value,cacheUseDataAttr[key]=useDataAttr,cacheIsManaged[key]=isManaged,createOrUpdateTimestamp(key),isManaged&&self.refresh(getDataForEntry(value,useDataAttr)))},self.get=function(key,useCacheTtl){var value=void 0;return useCacheTtl=!(!angular.isUndefined(useCacheTtl)&&!useCacheTtl),cache.hasOwnProperty(key)&&(!useCacheTtl||isEntryAlive(key)?(value=cache[key],cacheIsManaged[key]&&(value=angular.copy(value),value[1]=angular.toJson(value[1]))):self.remove(key)),value},self.remove=function(key){cache.hasOwnProperty(key)&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAll=function(){for(var key in cache)cache.hasOwnProperty(key)&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAllLists=function(){for(var key in cache)cache.hasOwnProperty(key)&&angular.isArray(getDataForKey(key))&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAllObjects=function(){for(var key in cache)cache.hasOwnProperty(key)&&angular.isObject(getDataForKey(key))&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAllRaw=function(){for(var key in cache)cache.hasOwnProperty(key)&&!cacheIsManaged[key]&&(delete cache[key],delete cacheTimestamps[key],delete cacheUseDataAttr[key],delete cacheIsManaged[key])},self.removeAllDependent=function(){for(var dependentCacheNames=collectDependentCacheNames(self,[]),i=0;i<dependentCacheNames.length;i++)caches[dependentCacheNames[i]].removeAll()},self.destroy=function(){var cacheIndex=caches.indexOf(self);cacheIndex!==-1&&(self.removeAll(),caches.splice(cacheIndex,1))},self.info=function(){var size=0;for(var key in cache)cache.hasOwnProperty(key)&&size++;return{id:name,size:size,options:options}},self.withDataAttr={put:function(key,value){return self.put(key,value,!0)},get:function(key){return self.get(key,!0)},remove:self.remove,removeAll:self.removeAll,info:self.info},self.withoutDataAttr={put:function(key,value){return self.put(key,value,!1)},get:function(key){return self.get(key,!0)},remove:self.remove,removeAll:self.removeAll,info:self.info},self.withDataAttrNoTtl={put:function(key,value){return self.put(key,value,!0)},get:function(key){return self.get(key,!1)},remove:self.remove,removeAll:self.removeAll,info:self.info},self.withoutDataAttrNoTtl={put:function(key,value){return self.put(key,value,!1)},get:function(key){return self.get(key,!1)},remove:self.remove,removeAll:self.removeAll,info:self.info}}function collectDependentCacheNames(cache,collectedDependentCacheNames){var cacheDependentCacheNames=cache.info().options.dependent;collectedDependentCacheNames=collectedDependentCacheNames||[];for(var i=0;i<cacheDependentCacheNames.length;i++){var cacheDependentCacheName=cacheDependentCacheNames[i],cacheDependentCache=caches[cacheDependentCacheName];cacheDependentCache&&(collectedDependentCacheNames.push(cacheDependentCacheName),collectedDependentCacheNames.indexOf(cacheDependentCacheName)===-1&&collectDependentCacheNames(cacheDependentCache,collectedDependentCacheNames))}return collectedDependentCacheNames}var caches={};return constructor.removeAll=function(){for(var key in caches)caches.hasOwnProperty(key)&&caches[key].removeAll()},constructor.get=function(key){return caches.hasOwnProperty(key)?caches[key]:null},constructor.info=function(){var infos={};for(var key in caches)if(caches.hasOwnProperty(key)){var info=caches[key].info();infos[info.id]=info}return infos},constructor})}(),function(){"use strict";angular.module("ngResourceFactory").factory("ResourceFactoryService",["$q","$resource","ResourceCacheService","ResourcePhantomIdNegativeInt",function($q,$resource,ResourceCacheService,ResourcePhantomIdNegativeInt){"ngInject";function ResourceStore(resource,managedInstances,parentStore){function addResourceInstance(instances,instance){var matchingInstances=resource.filterInstancesByAttr(instances,resource.getPkAttr(),instance[resource.getPkAttr()]);if(matchingInstances.length)for(var i=0;i<matchingInstances.length;i++){var matchingInstanceIndex=instances.indexOf(matchingInstances[i]),matchingInstanceFound=matchingInstanceIndex!==-1;matchingInstanceFound&&instances.splice(matchingInstanceIndex,1,instance)}else instances.push(instance)}function removeResourceInstance(instances,instance){var matchingInstances=resource.filterInstancesByAttr(instances,resource.getPkAttr(),instance[resource.getPkAttr()]);if(matchingInstances.length)for(var i=0;i<matchingInstances.length;i++){var matchingInstanceIndex=instances.indexOf(matchingInstances[i]),matchingInstanceFound=matchingInstanceIndex!==-1;matchingInstanceFound&&instances.splice(matchingInstanceIndex,1)}}function isPromiseLike(obj){return obj&&angular.isFunction(obj.then)}function populate(dst,src,keepMissing){keepMissing=!!angular.isUndefined(keepMissing)||!!keepMissing,dst=dst||void 0;var key,preserve=!!dst,preservedObjects={};src=angular.copy(src);for(key in src)src.hasOwnProperty(key)&&"$"===key[0]&&delete src[key];if(preserve)for(key in dst)dst.hasOwnProperty(key)&&("$"===key[0]?preservedObjects[key]=dst[key]:keepMissing&&!src.hasOwnProperty(key)&&(preservedObjects[key]=dst[key]));if(dst=angular.copy(src,dst),preserve)for(key in preservedObjects)preservedObjects.hasOwnProperty(key)&&(dst[key]=preservedObjects[key]);return dst}function copy(src,dst){if(angular.isArray(src)){dst=angular.isArray(dst)?dst:[],dst.length=0;for(var i=0;i<src.length;i++)dst.push(populate(null,src[i],!1))}else dst=populate(dst,src,!1);return dst}function merge(src,dst){if(angular.isArray(src)){dst=angular.isArray(dst)?dst:[],dst.length=0;for(var i=0;i<src.length;i++)dst.push(populate(null,src[i],!0))}else dst=populate(dst,src,!0);return dst}var self=this,executionRunning=(resource.getResourceName(),!1),relations=[],visibleQueue=[],persistQueue=[],removeQueue=[],beforePersistListeners=[],afterPersistListeners=[],beforeRemoveListeners=[],afterRemoveListeners=[];self.manage=function(newInstances){var doManage=function(newInstances){angular.isArray(newInstances)||(newInstances=[newInstances]);for(var i=0;i<newInstances.length;i++){var newInstance=newInstances[i];newInstance.$store?newInstance.$store:(newInstance.$store=self,addResourceInstance(managedInstances,newInstance),addResourceInstance(visibleQueue,newInstance))}};if(isPromiseLike(newInstances)||isPromiseLike(newInstances.$promise)){var promise=isPromiseLike(newInstances)?newInstances:newInstances.$promise,defer=$q.defer();return promise.then(doManage).then(function(){defer.resolve(newInstances)}),defer.promise}return doManage(newInstances),$q.resolve(newInstances)},self.forget=function(oldInstances){var doForget=function(oldInstances){angular.isArray(oldInstances)||(oldInstances=[oldInstances]);for(var i=0;i<oldInstances.length;i++){var oldInstance=oldInstances[i];oldInstance.$store===self?(delete oldInstance.$store,removeResourceInstance(managedInstances,oldInstance),removeResourceInstance(visibleQueue,oldInstance),removeResourceInstance(persistQueue,oldInstance),removeResourceInstance(removeQueue,oldInstance)):oldInstance.$store}};if(isPromiseLike(oldInstances)||isPromiseLike(oldInstances.$promise)){var promise=isPromiseLike(oldInstances)?oldInstances:oldInstances.$promise,defer=$q.defer();return promise.then(doForget).then(function(){defer.resolve(oldInstances)}),defer.promise}return doForget(oldInstances),$q.resolve(oldInstances)},self.new=function(params){var newInstance=resource.new(params);return self.manage(newInstance),newInstance},self.persist=function(instances){angular.isArray(instances)||(instances=[instances]);for(var i=0;i<instances.length;i++){var instance=instances[i];instance.$store===self&&(addResourceInstance(persistQueue,instance),addResourceInstance(visibleQueue,instance),removeResourceInstance(removeQueue,instance))}},self.remove=function(instances){angular.isArray(instances)||(instances=[instances]);for(var i=0;i<instances.length;i++){var instance=instances[i];instance.$store===self&&(removeResourceInstance(persistQueue,instance),removeResourceInstance(visibleQueue,instance),addResourceInstance(removeQueue,instance))}},self.commit=function(){if(parentStore){for(var i=0;i<persistQueue.length;i++){var childPersistInstance=copy(persistQueue[i]),parentPersistInstance=parentStore.getByInstance(childPersistInstance);delete childPersistInstance.$store,parentPersistInstance?merge(childPersistInstance,parentPersistInstance):(parentPersistInstance=copy(childPersistInstance),parentStore.manage(parentPersistInstance)),parentStore.persist(parentPersistInstance)}for(var j=0;j<removeQueue.length;j++){var childRemoveInstance=copy(removeQueue[i]),parentRemoveInstance=parentStore.getByInstance(childRemoveInstance);delete childRemoveInstance.$store,parentRemoveInstance?merge(childRemoveInstance,parentRemoveInstance):(parentRemoveInstance=copy(childRemoveInstance),parentStore.manage(parentRemoveInstance)),parentStore.remove(parentRemoveInstance)}}},self.executeAll=function(clearAfter){clearAfter=angular.isUndefined(clearAfter)||!!clearAfter;var defer=$q.defer(),executeRelated=function(){for(var promises=[],i=0;i<relations.length;i++){var relation=relations[i],relatedStore=relation.getRelatedStore();promises.push(relatedStore.executeAll(clearAfter))}return $q.all(promises)};return self.execute(clearAfter).then(executeRelated).then(defer.resolve).catch(defer.reject),defer.promise},self.execute=function(clearAfter){if(clearAfter=angular.isUndefined(clearAfter)||!!clearAfter,executionRunning)return $q.reject("Another execution is already running.");if(parentStore)throw"Executing the store is only possible on the topmost store";executionRunning=!0;var defer=$q.defer(),handleError=function(reason){executionRunning=!1,defer.reject(reason)},callListeners=function(item,listeners){for(var i=0;i<listeners.length;i++)listeners[i](item)},relationsRemove=function(pkValue){for(var i=0;i<relations.length;i++)relations[i].handleRemove(pkValue)},relationsUpdate=function(oldPkValue,newPkValue){for(var i=0;i<relations.length;i++)relations[i].handleUpdate(oldPkValue,newPkValue)},executeSingle=function(item,execFn,beforeListeners,afterListeners,defer,isRemove){callListeners(item,beforeListeners),execFn({},item).$promise.then(function(response){if(isRemove&&item&&relationsRemove(item[resource.getPkAttr()]),response&&response[resource.getPkAttr()]){var oldPkValue=item?item[resource.getPkAttr()]:null,newPkValue=response?response[resource.getPkAttr()]:null;isRemove||relationsUpdate(oldPkValue,newPkValue),item[resource.getPkAttr()]=newPkValue}callListeners(item,afterListeners),defer.resolve(item)}).catch(defer.reject)},executeRemoves=function(){for(var promises=[],queue=self.getRemoveQueue(),i=0;i<queue.length;i++){var item=queue[i];if(!item.$isPhantom()){var defer=$q.defer();promises.push(defer.promise),executeSingle(item,resource.remove,beforeRemoveListeners,afterRemoveListeners,defer,!0)}}return $q.all(promises)},executeUpdates=function(){for(var promises=[],queue=self.getUpdateQueue(),i=0;i<queue.length;i++){var item=queue[i],defer=$q.defer();promises.push(defer.promise),executeSingle(item,resource.update,beforePersistListeners,afterPersistListeners,defer,!1)}return $q.all(promises)},executeSaves=function(){for(var promises=[],queue=self.getSaveQueue(),i=0;i<queue.length;i++){var item=queue[i],defer=$q.defer();promises.push(defer.promise),executeSingle(item,resource.save,beforePersistListeners,afterPersistListeners,defer,!1)}return $q.all(promises)},clear=function(){clearAfter&&(persistQueue.length=0,removeQueue.length=0),executionRunning=!1};return $q.when().then(executeRemoves).then(executeUpdates).then(executeSaves).then(clear).then(defer.resolve).catch(handleError),defer.promise},self.createChildStore=function(instances){return instances=instances||managedInstances,new ResourceStore(resource,copy(instances),self)},self.createRelation=function(config){config=angular.extend({relatedStore:null,fkAttr:null,onRemove:"forget",onUpdate:"update"},config);var relation=new ResourceStoreRelation(self,config.relatedStore,config.fkAttr,config.onUpdate,config.onRemove);return relations.push(relation),relation},self.removeRelation=function(relation){var relationIndex=relations.indexOf(relation);relationIndex!==-1&&relations.splice(relationIndex,1)},self.getByPk=function(pkValue){return resource.getInstanceByPk(managedInstances,pkValue)},self.getByInstance=function(instance){var pkValue=instance?instance[resource.getPkAttr()]:void 0;return self.getByPk(pkValue)},self.getManagedInstances=function(){return managedInstances.slice()},self.getVisibleQueue=function(){return visibleQueue.slice()},self.getPersistQueue=function(){return persistQueue.slice()},self.getRemoveQueue=function(){return removeQueue.slice()},self.getSaveQueue=function(){var filterPhantom=function(instance){return instance.$isPhantom()};return persistQueue.filter(filterPhantom)},self.getUpdateQueue=function(){var filterNonPhantom=function(instance){return!instance.$isPhantom()};return persistQueue.filter(filterNonPhantom)},self.getResourceService=function(){return resource},self.addBeforePersistListener=function(fn){beforePersistListeners.push(fn)},self.removeBeforePersistListener=function(fn){var fnIndex=beforePersistListeners.indexOf(fn);fnIndex!==-1&&beforePersistListeners.splice(fnIndex,1)},self.addAfterPersistListener=function(fn){afterPersistListeners.push(fn)},self.removeAfterPersistListener=function(fn){var fnIndex=afterPersistListeners.indexOf(fn);fnIndex!==-1&&afterPersistListeners.splice(fnIndex,1)},self.addBeforeRemoveListener=function(fn){beforeRemoveListeners.push(fn)},self.removeBeforeRemoveListener=function(fn){var fnIndex=beforeRemoveListeners.indexOf(fn);fnIndex!==-1&&beforeRemoveListeners.splice(fnIndex,1)},self.addAfterRemoveListener=function(fn){afterRemoveListeners.push(fn)},self.removeAfterRemoveListener=function(fn){var fnIndex=afterRemoveListeners.indexOf(fn);fnIndex!==-1&&afterRemoveListeners.splice(fnIndex,1)},function(){managedInstances=managedInstances||[],parentStore=parentStore||null;var managed=self.manage(managedInstances),mapPk=function(instance){return instance?String(instance[resource.getPkAttr()]):void 0},filterPks=function(pks){return function(instance){return!!instance&&pks.indexOf(String(instance[resource.getPkAttr()]))!==-1}};parentStore&&managed.then(function(){var parentVisibleQueuePks=parentStore.getVisibleQueue().map(mapPk),parentPersistQueuePks=parentStore.getPersistQueue().map(mapPk),parentRemoveQueuePks=parentStore.getRemoveQueue().map(mapPk);visibleQueue=managedInstances.filter(filterPks(parentVisibleQueuePks)),persistQueue=managedInstances.filter(filterPks(parentPersistQueuePks)),removeQueue=managedInstances.filter(filterPks(parentRemoveQueuePks))})}()}function ResourceStoreRelation(store,relatedStore,fkAttr,onUpdate,onRemove){var self=this;switch(onUpdate){case"update":onUpdate=function(referencingStore,referencingInstance,oldReferencedInstancePk,newReferencedInstancePk,fkAttr){referencingInstance[fkAttr]=newReferencedInstancePk};break;case"null":onUpdate=function(referencingStore,referencingInstance,oldReferencedInstancePk,newReferencedInstancePk,fkAttr){referencingInstance[fkAttr]=null}}switch(onRemove){case"forget":onRemove=function(referencingStore,referencingInstance,oldReferencedInstancePk,fkAttr){referencingStore.forget(referencingInstance)};break;case"null":onRemove=function(referencingStore,referencingInstance,oldReferencedInstancePk,fkAttr){referencingInstance[fkAttr]=null}}self.getStore=function(){return store},self.getRelatedStore=function(){return relatedStore},self.getFkAttr=function(){return fkAttr},self.handleUpdate=function(oldPkValue,newPkValue){for(var referencingInstances=relatedStore.getManagedInstances(),i=0;i<referencingInstances.length;i++){var referencingInstance=referencingInstances[i];referencingInstance&&referencingInstance[fkAttr]==oldPkValue&&oldPkValue!=newPkValue&&onUpdate(relatedStore,referencingInstance,oldPkValue,newPkValue,fkAttr)}},self.handleRemove=function(pkValue){for(var referencingInstances=relatedStore.getManagedInstances(),i=0;i<referencingInstances.length;i++){var referencingInstance=referencingInstances[i];referencingInstance&&referencingInstance[fkAttr]==pkValue&&onRemove(relatedStore,referencingInstance,pkValue,fkAttr)}}}return function(name,url,options){options=angular.extend({stripTrailingSlashes:!1,ignoreLoadingBar:!1,generatePhantomIds:!0,phantomIdGenerator:ResourcePhantomIdNegativeInt,dependent:[],extraMethods:{},extraFunctions:{},pkAttr:"pk",urlAttr:"url",queryDataAttr:null,queryTotalAttr:null,queryFilter:{},cacheClass:ResourceCacheService,toInternal:function(obj,headersGetter,status){return obj},fromInternal:function(obj,headersGetter){return obj}},options||{});var resource,minError=angular.$$minErr("ngResourceFactory"),paramsDefaults={},saveParams={},queryParams={},cache=new options.cacheClass(name,options.pkAttr,{dataAttr:options.queryDataAttr,pkAttr:options.pkAttr,urlAttr:options.urlAttr,dependent:options.dependent,ttl:900}),queryInterceptor={response:function(response){var data=response.data,instance=response.resource;return instance.total=data.total,instance}},insertingInterceptor={response:function(response){var instance=response.resource,url=options.urlAttr?instance[options.urlAttr]:null;return cache.removeAllRaw(),cache.removeAllLists(),cache.removeAllDependent(),url?cache.insert(url,instance,!1):cache.removeAllObjects(),instance}},modifyingInterceptor={response:function(response){var instance=response.resource,url=options.urlAttr?instance[options.urlAttr]:response.config.url;return cache.removeAllRaw(),cache.removeAllLists(),cache.removeAllDependent(),url?cache.insert(url,instance,!1):cache.removeAllObjects(),instance}},deletingInterceptor={response:function(response){var instance=response.resource,url=options.urlAttr?instance[options.urlAttr]:response.config.url;return cache.removeAllRaw(),cache.removeAllLists(),cache.removeAllDependent(),url?cache.remove(url):cache.removeAllObjects(),instance}},transformResponseFromJson=function(responseText,headersGetter,status){return responseText?angular.fromJson(responseText):null},queryTransformResponseToInternal=function(responseData,headersGetter,status){if(angular.isArray(responseData))for(var i=0;i<responseData.length;i++)responseData[i]=options.toInternal(responseData[i],headersGetter,status);else responseData=options.toInternal(responseData,headersGetter,status);return responseData},singleTransformResponseToInternal=function(responseData,headersGetter,status){return options.toInternal(responseData,headersGetter,status)},queryTransformResponseData=function(responseData,headersGetter,status){var result=null;return status>=200&&status<300?(result=options.queryDataAttr&&responseData?responseData[options.queryDataAttr]:responseData,options.queryTotalAttr&&responseData&&responseData[options.queryTotalAttr]&&(result.total=responseData[options.queryTotalAttr])):result=responseData,result},transformRequestToJson=function(requestData,headersGetter){for(var filterPrivate=function(key){return"$"===String(key)[0]},keys=angular.isObject(requestData)?Object.keys(requestData):[],privateKeys=keys.filter(filterPrivate),i=0;i<privateKeys.length;i++)delete requestData[privateKeys[i]];return angular.toJson(requestData)},singleTransformRequestFromInternal=function(requestData,headersGetter){return options.fromInternal(angular.copy(requestData),headersGetter)},methods={restore:{method:"GET",isArray:!1,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,cache:cache.withoutDataAttrNoTtl,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},get:{method:"GET",isArray:!1,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,cache:cache.withoutDataAttr,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},getNoCache:{method:"GET",isArray:!1,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},query:{method:"GET",isArray:!0,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:queryInterceptor,cache:cache.withDataAttr,transformResponse:[transformResponseFromJson,queryTransformResponseData,queryTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},queryNoCache:{method:"GET",isArray:!0,withCredentials:!0,cancellable:!0,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:queryInterceptor,transformResponse:[transformResponseFromJson,queryTransformResponseData,queryTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},save:{method:"POST",isArray:!1,withCredentials:!0,cancellable:!1,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:insertingInterceptor,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},update:{method:"PATCH",isArray:!1,withCredentials:!0,cancellable:!1,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:modifyingInterceptor,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]},remove:{method:"DELETE",isArray:!1,withCredentials:!0,cancellable:!1,ignoreLoadingBar:options.ignoreLoadingBar,interceptor:deletingInterceptor,transformResponse:[transformResponseFromJson,singleTransformResponseToInternal],transformRequest:[singleTransformRequestFromInternal,transformRequestToJson]}};angular.extend(methods,options.extraMethods);for(var methodName in methods)if(methods.hasOwnProperty(methodName)){var bgMethodName=methodName+"Bg",bgMethodConfig=angular.copy(methods[methodName]);bgMethodConfig.ignoreLoadingBar=!0,methods[bgMethodName]=bgMethodConfig}return paramsDefaults[options.pkAttr]="@"+options.pkAttr,saveParams[options.pkAttr]=null,queryParams[options.pkAttr]=null,methods.save.params=saveParams,methods.saveBg.params=saveParams,methods.query.params=queryParams,methods.queryBg.params=queryParams,methods.queryNoCache.params=queryParams,methods.queryNoCacheBg.params=queryParams,resource=$resource(url,paramsDefaults,methods,{stripTrailingSlashes:options.stripTrailingSlashes}),resource.getPkAttr=function(){return options.pkAttr},resource.getQueryDataAttr=function(){return options.queryDataAttr},resource.getQueryTotalAttr=function(){return options.queryTotalAttr},resource.getCacheClass=function(){return options.cacheClass},resource.getQueryFilters=function(){return options.queryFilter},resource.setQueryFilters=function(filters){return angular.copy(filters,options.queryFilter)},resource.setDefaultQueryFilters=function(defaultFilters){var filters=angular.extend({},defaultFilters,options.queryFilter);return angular.copy(filters,options.queryFilter)},resource.filter=function(filters){return filters=angular.extend({},resource.getQueryFilters(),filters),resource.query(filters)},resource.filterNoCache=function(filters){return filters=angular.extend({},resource.getQueryFilters(),filters),resource.queryNoCache(filters)},resource.new=function(params){var phantomInstance=new resource(params);return options.pkAttr&&options.generatePhantomIds&&options.phantomIdGenerator&&!phantomInstance[options.pkAttr]&&(phantomInstance[options.pkAttr]=options.phantomIdGenerator.generate(phantomInstance)),phantomInstance},resource.isPhantom=function(instance){var pkValue=instance?instance[options.pkAttr]:void 0;if(options.pkAttr&&options.generatePhantomIds&&options.phantomIdGenerator)return options.phantomIdGenerator.isPhantom(pkValue,instance)},resource.filterInstancesByAttr=function(instances,attrName,attrValue){var filterAttrValue=function(item){return!!item&&item[attrName]==attrValue};return instances.filter(filterAttrValue)},resource.getInstanceByAttr=function(instances,attrName,attrValue){var result=null,filteredInstances=resource.filterInstancesByAttr(instances,attrName,attrValue);return filteredInstances.length&&(filteredInstances.length,result=filteredInstances[0]),result},resource.getInstanceByPk=function(instances,pkValue){return resource.getInstanceByAttr(instances,options.pkAttr,pkValue)},resource.getResourceName=function(){return name},resource.getCache=function(){return cache},resource.createStore=function(instances){return instances=instances||[],angular.isArray(instances)||(instances=[instances]),new ResourceStore(resource,instances,null)},resource.persist=function(a1,a2,a3,a4){var instance,successFn,errorFn,params={};switch(arguments.length){case 4:params=a1,instance=a2,successFn=a3,errorFn=a4;break;case 3:angular.isFunction(a2)?(instance=a1,successFn=a2,errorFn=a3):(params=a1,instance=a2,successFn=a3);break;case 2:angular.isFunction(a2)?(instance=a1,successFn=a2):(params=a1,instance=a2);break;case 1:instance=a1;break;default:throw minError("badargs","Expected up to 4 arguments [params, instance, success, error], got {0} arguments",arguments.length)}return(resource.isPhantom(instance)?resource.save:resource.update)(params,instance,successFn,errorFn)},angular.extend(resource.prototype,{$persist:function(a1,a2,a3){var instance=this;return angular.isFunction(a1)&&(a2=a1,a3=a2,a1={}),resource.persist(a1,instance,a2,a3).$promise},$isPhantom:function(){return resource.isPhantom(this)}}),angular.extend(resource.prototype,options.extraFunctions),resource}}])}(),function(){"use strict";var module=angular.module("ngResourceFactory");module.service("ResourcePhantomIdFactoryService",function(){"ngInject";function ResourcePhantomIdFactory(generateFn,isPhantomFn){var self=this;self.generate=function(instance){return generateFn(instance)},self.isPhantom=function(pkValue,instance){return isPhantomFn(pkValue,instance)}}this.createPhantomIdFactory=function(config){return config=angular.extend({generate:function(){},is:function(){}},config),new ResourcePhantomIdFactory(config.generate,config.is)}}),module.factory("ResourcePhantomIdNegativeInt",["ResourcePhantomIdFactoryService",function(ResourcePhantomIdFactoryService){"ngInject";var lastPkValue=0;return ResourcePhantomIdFactoryService.createPhantomIdFactory({generate:function(){return--lastPkValue},is:function(pkValue){return pkValue<0}})}]),module.factory("ResourcePhantomIdUuid4",["ResourcePhantomIdFactoryService",function(ResourcePhantomIdFactoryService){"ngInject";function uuid4(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(c){var r=16*Math.random()|0;return("x"===c?r:3&r|8).toString(16)})}var generatedIds=[];return ResourcePhantomIdFactoryService.createPhantomIdFactory({generate:function(){var pkValue=uuid4();return generatedIds.push(pkValue),pkValue},is:function(pkValue){return generatedIds.indexOf(pkValue)!==-1}})}])}(),angular.module("ngResourceFactory")});

@@ -146,4 +146,4 @@ 'use strict';

'node_modules/jsdoc/jsdoc.js '+
'--configure node_modules/angular-jsdoc/common/conf.json '+ // config file
'--template node_modules/angular-jsdoc/default '+ // template file
'--configure jsdoc.json '+ // config file
'--template node_modules/simple-jsdoc '+ // template file
'--destination "' + config.documentationDir + '" '+ // output directory

@@ -150,0 +150,0 @@ '--readme ./README.md ' + // to include README.md as index contents

{
"name": "angular-resource-factory",
"version": "0.8.10",
"version": "0.8.11",
"description": "A factory build upon $resource helping you to interact with RESTful APIs with advanced features as caches and data stores.",

@@ -27,3 +27,2 @@ "main": "dist/ngresourcefactory.min.js",

"devDependencies": {
"angular-jsdoc": "^1.5.0",
"angular-mocks": "^1.6.0",

@@ -47,3 +46,3 @@ "gulp": "^3.9.1",

"gulp-watch": "^4.3.11",
"jsdoc": "^3.4.3",
"jsdoc": "^3.5.3",
"karma": "^1.6.0",

@@ -54,5 +53,7 @@ "karma-jasmine": "^1.1.0",

"karma-verbose-reporter": "0.0.6",
"latodoc": "github:smeijer/latodoc",
"license-checker": "^8.0.4",
"lodash": "^4.17.4",
"license-checker": "^8.0.4"
"simple-jsdoc": "0.0.4"
}
}

@@ -28,6 +28,37 @@ /**

/**
* Factory service to create new cache.
* Factory that gives a cache class whose instances can be used for caching resources. Instances of this cache class
* are capable of invalidating related caches, updating resource list instances when getting data from detail calls
* and respecting the `dataAttr` of resource instances.
*
* @name ResourceCacheService
* @ngdoc factory
* @ngdoc service
* @param {String} name Name of the cache
* @param {String} pkAttr Name of the primary key attribute on cached instances
* @param {Object} [options] Additional configuration
* @param {String|null} options.urlAttr Name of the attribute to get the URL of the objects (default: `null`)
* @param {String|null} options.dataAttr Name of the attribute to get the actual data from (default: `null`)
* @param {String[]} options.dependent List of dependent cache names (default: `[]`)
* @param {int} options.ttl Time to live for cache entries in seconds (default: `3600`)
* @class
*
* @example
* // Directly using `ResourceCacheService`
* inject(function (ResourceCacheService) {
* var
* exampleValue = {pk: 123, attr1: 1, attr2: 2},
* cacheInstance = new ResourceCacheService('MyExampleResourceCache', 'pk');
*
* cacheInstance.put('example-1', exampleValue, false);
* expect(cacheInstance.get('example-1', false)).toEqual(exampleValue);
* });
*
* @example
* // Using `ResourceCacheService` for `$http`
* inject(function (ResourceCacheService, $http) {
* var
* cacheInstance = new ResourceCacheService('MyExampleResourceCache', 'pk'),
* httpInstance = $http({cache: cacheInstance.withoutDataAttr});
*
* httpInstance.get('http://example.com/api/endpoint-1/');
* });
*/

@@ -41,9 +72,2 @@ module.factory('ResourceCacheService',

/**
* Constructor function for the cache.
*
* @name ResourceCache
* @ngdoc constructor
* @constructor
*/
function constructor (name, pkAttr, options) {

@@ -56,2 +80,3 @@ var

* @type {{}}
* @private
*/

@@ -63,2 +88,3 @@ cache = {},

* @type {{}}
* @private
*/

@@ -70,2 +96,3 @@ cacheUseDataAttr = {},

* @type {{}}
* @private
*/

@@ -77,2 +104,3 @@ cacheIsManaged = {},

* @type {{}}
* @private
*/

@@ -83,10 +111,5 @@ cacheTimestamps = {};

/**
* Name of the attribute to get the ID of the objects
* @type {String|null}
*/
pkAttr: null,
/**
* Name of the attribute to get the URL of the objects
* @type {String|null}
* @private
*/

@@ -98,2 +121,3 @@ urlAttr: null,

* @type {String|null}
* @private
*/

@@ -105,2 +129,3 @@ dataAttr: null,

* @type {Array<String>}
* @private
*/

@@ -112,2 +137,3 @@ dependent: [],

* @type {int}
* @private
*/

@@ -124,4 +150,6 @@ ttl: 60 * 60

*
* @memberOf ResourceCache
* @param {Object|Array<Object>} value
* @memberOf ResourceCacheService
* @function refresh
* @param {Object|Array<Object>} value Instance or list of instances used to refresh data on the cache
* @instance
*/

@@ -149,7 +177,9 @@ self.refresh = function (value) {

*
* @memberOf ResourceCache
* @param key
* @param value
* @param useDataAttr
* @param [refresh]
* @memberOf ResourceCacheService
* @function insert
* @param {String} key Cache entry key
* @param {*} value Cache entry value
* @param {Boolean} useDataAttr Use the `dataAttr` to get actual cache entry value
* @param {Boolean} [refresh] Refresh the existing cache entries by using the new value
* @instance
*/

@@ -185,6 +215,8 @@ self.insert = function (key, value, useDataAttr, refresh) {

*
* @memberOf ResourceCache
* @param key
* @param value
* @param useDataAttr
* @memberOf ResourceCacheService
* @function put
* @param {String} key Cache entry key
* @param {*} value Cache entry value
* @param {Boolean} useDataAttr Use the `dataAttr` to get actual cache entry value
* @instance
*/

@@ -235,6 +267,8 @@ self.put = function (key, value, useDataAttr) {

*
* @memberOf ResourceCache
* @param key
* @param useCacheTtl
* @returns {*|undefined}
* @memberOf ResourceCacheService
* @function get
* @param {String} key Cache entry key
* @param {Boolean} [useCacheTtl] If `true` this method will return `undefined` when the TTL of the entry is outreached (default: `true`)
* @returns {*} Cache entry
* @instance
*/

@@ -276,4 +310,6 @@ self.get = function (key, useCacheTtl) {

*
* @memberOf ResourceCache
* @param key
* @memberOf ResourceCacheService
* @function remove
* @param {String} key Cache entry key
* @instance
*/

@@ -294,3 +330,5 @@ self.remove = function (key) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function removeAll
* @instance
*/

@@ -313,3 +351,5 @@ self.removeAll = function () {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function removeAllLists
* @instance
*/

@@ -332,3 +372,5 @@ self.removeAllLists = function () {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function removeAllObjects
* @instance
*/

@@ -351,3 +393,5 @@ self.removeAllObjects = function () {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function removeAllRaw
* @instance
*/

@@ -371,3 +415,5 @@ self.removeAllRaw = function () {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function removeAllDependent
* @instance
*/

@@ -386,3 +432,5 @@ self.removeAllDependent = function () {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function destroy
* @instance
*/

@@ -405,4 +453,6 @@ self.destroy = function () {

*
* @memberOf ResourceCache
* @returns {{id: *, size: number}}
* @memberOf ResourceCacheService
* @function info
* @returns {ResourceCacheServiceMeta} Information about the cache instance
* @instance
*/

@@ -432,4 +482,6 @@ self.info = function () {

*
* @memberOf ResourceCache
* @type {{put: constructor.withDataAttrNoTtl.put, get: constructor.withDataAttrNoTtl.get, remove: (*), removeAll: (*), info: (*)}}
* @memberOf ResourceCacheService
* @member withDataAttr
* @type {HttpCacheInstance}
* @instance
*/

@@ -451,4 +503,6 @@ self.withDataAttr = {

*
* @memberOf ResourceCache
* @type {{put: constructor.withDataAttrNoTtl.put, get: constructor.withDataAttrNoTtl.get, remove: (*), removeAll: (*), info: (*)}}
* @memberOf ResourceCacheService
* @member withoutDataAttr
* @type {HttpCacheInstance}
* @instance
*/

@@ -470,4 +524,6 @@ self.withoutDataAttr = {

*
* @memberOf ResourceCache
* @type {{put: constructor.withDataAttrNoTtl.put, get: constructor.withDataAttrNoTtl.get, remove: (*), removeAll: (*), info: (*)}}
* @memberOf ResourceCacheService
* @member withDataAttrNoTtl
* @type {HttpCacheInstance}
* @instance
*/

@@ -489,4 +545,6 @@ self.withDataAttrNoTtl = {

*
* @memberOf ResourceCache
* @type {{put: constructor.withDataAttrNoTtl.put, get: constructor.withDataAttrNoTtl.get, remove: (*), removeAll: (*), info: (*)}}
* @memberOf ResourceCacheService
* @member withoutDataAttrNoTtl
* @type {HttpCacheInstance}
* @instance
*/

@@ -507,4 +565,8 @@ self.withoutDataAttrNoTtl = {

* Checks if the given content type string indicates JSON.
* @param contentType
* @return {boolean}
*
* @memberOf ResourceCacheService
* @function isJsonContentType
* @param {String} contentType Content type string to check for
* @return {Boolean}
* @private
*/

@@ -521,5 +583,6 @@ function isJsonContentType (contentType) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function getDataForKey
* @param {String} key Cache entry key
* @private
* @param key
*/

@@ -539,7 +602,8 @@ function getDataForKey (key) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function getDataForEntry
* @param {Object} value Object to get the actual value from
* @param {Boolean} useDataAttr Use the `dataAttr` to get the actual value from the given object
* @returns {*}
* @private
* @param value
* @param useDataAttr
* @returns {*}
*/

@@ -561,6 +625,7 @@ function getDataForEntry (value, useDataAttr) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function setDataForKey
* @param {String} key Cache entry key
* @param {*} newData New value for the cache entry
* @private
* @param key
* @param newData
*/

@@ -588,5 +653,6 @@ function setDataForKey (key, newData) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function getCurrentTimestamp
* @returns {int} Current unix epoch
* @private
* @returns {int}
*/

@@ -600,6 +666,7 @@ function getCurrentTimestamp () {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function createOrUpdateTimestamp
* @param {String} key Cache entry key
* @returns {int} Current unix epoch
* @private
* @param key
* @returns {int}
*/

@@ -615,6 +682,7 @@ function createOrUpdateTimestamp (key) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function isEntryAlive
* @param {String} key Cache entry key
* @returns {Boolean} Cache entry alive or not alive
* @private
* @param key
* @returns {boolean}
*/

@@ -636,5 +704,6 @@ function isEntryAlive (key) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function refreshSingle
* @param {Object} newData New data to refresh the cache with
* @private
* @param {Object} newData
*/

@@ -691,5 +760,6 @@ function refreshSingle (newData) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function refreshEach
* @param {Array<Object>} newEntries List of new data to refresh the cache with
* @private
* @param {Array<Object>} newEntries
*/

@@ -705,3 +775,4 @@ function refreshEach (newEntries) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function init
* @private

@@ -722,3 +793,4 @@ */

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function removeAll
* @static

@@ -737,6 +809,7 @@ */

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function get
* @param {String} key Cache name
* @returns {ResourceCacheService} Cache instance with the given name
* @static
* @param key
* @returns {*|null}
*/

@@ -757,5 +830,6 @@ constructor.get = function (key) {

*
* @memberOf ResourceCache
* @memberOf ResourceCacheService
* @function info
* @returns {Object} Information object for all caches
* @static
* @returns {{}}
*/

@@ -783,6 +857,7 @@ constructor.info = function () {

* @memberOf ResourceCacheService
* @private
* @function collectDependentCacheNames
* @param {Object} cache
* @param {Array<String>|undefined} collectedDependentCacheNames
* @returns {Array<String>}
* @private
*/

@@ -789,0 +864,0 @@ function collectDependentCacheNames (cache, collectedDependentCacheNames) {

@@ -24,2 +24,17 @@ /**

/**
* A resource instance created via an instance of `ResourceFactoryService`.
* @typedef {Object|Object[]} ResourceInstance
*/
/**
* A `$http` compatible cache instance
* @typedef {{put: Function, get: Function, remove: Function, removeAll: Function, info: Function}} HttpCacheInstance
*/
/**
* Object holding resource cache meta information.
* @typedef {{id: String, size: int, options: Object}} ResourceCacheServiceMeta
*/
var

@@ -26,0 +41,0 @@ app = angular.module('ngResourceFactory', [

@@ -32,18 +32,36 @@ /**

* @ngdoc service
* @see ResourcePhantomIdNegativeInt
* @see ResourcePhantomIdUuid4
* @class
*
* @example
* // Example of a phantom ID generator that uses negative numbers as phantom IDs.
* angular.module('example').factory('ExampleIdFactory',
* function(ResourcePhantomIdFactoryService) {
* var lastPkValue = 0;
* // ResourcePhantomIdFactory that creates negative IDs as phantom IDs (NOTE: this is already a build-in
* // phantom ID factory, so you do not have to implement this - @see ResourcePhantomIdNegativeInt)
* inject(function (ResourceFactoryService, ResourcePhantomIdFactoryService) {
* var
* lastPkValue = 0,
* generator = ResourcePhantomIdFactoryService.createPhantomIdFactory({
* generate: function () {
* return --lastPkValue;
* },
* is: function (pkValue) {
* return pkValue < 0;
* }
* }),
* service = ResourceFactoryService('TestResourceService', 'http://test/:pk/', {
* phantomIdGenerator: generator
* }),
* phantomInstance1 = service.new(),
* phantomInstance2 = service.new();
*
* return ResourcePhantomIdFactoryService.createPhantomIdFactory({
* generate: function () {
* return --lastPkValue;
* },
* is: function (pkValue) {
* return pkValue < 0;
* }
* });
* }
* );
* expect(phantomInstance1.$isPhantom()).toBe(true);
* expect(phantomInstance2.$isPhantom()).toBe(true);
*
* // Change IDs to non-negative numbers
* phantomInstance1.pk = 1;
* phantomInstance2.pk = 2;
*
* expect(phantomInstance1.$isPhantom()).toBe(false);
* expect(phantomInstance2.$isPhantom()).toBe(false);
* });
*/

@@ -61,4 +79,6 @@ module.service('ResourcePhantomIdFactoryService',

* @memberOf ResourcePhantomIdFactoryService
* @param config
* @return {ResourcePhantomIdFactory}
* @function createPhantomIdFactory
* @param {{generate: Function, is: Function}} config Configuration object for new phantom ID factory
* @return {ResourcePhantomIdFactory} New phantom ID factory instance
* @static
*/

@@ -79,6 +99,38 @@ self.createPhantomIdFactory = function (config) {

* @name ResourcePhantomIdFactory
* @ngdoc constructor
* @param generateFn
* @param isPhantomFn
* @constructor
* @param {Function} generateFn Function that returns a new, phantom ID. Gets the instance as the first parameter
* @param {Function} isPhantomFn Function that checks if the first given parameter is a phantom ID. Gets the instance as the second parameter
* @see ResourcePhantomIdNegativeInt
* @see ResourcePhantomIdUuid4
* @class
*
* @example
* // ResourcePhantomIdFactory that creates negative IDs as phantom IDs (NOTE: this is already a build-in
* // phantom ID factory, so you do not have to implement this)
* inject(function (ResourceFactoryService, ResourcePhantomIdFactoryService) {
* var
* lastPkValue = 0,
* generator = ResourcePhantomIdFactoryService.createPhantomIdFactory({
* generate: function () {
* return --lastPkValue;
* },
* is: function (pkValue) {
* return pkValue < 0;
* }
* }),
* service = ResourceFactoryService('TestResourceService', 'http://test/:pk/', {
* phantomIdGenerator: generator
* }),
* phantomInstance1 = service.new(),
* phantomInstance2 = service.new();
*
* expect(phantomInstance1.$isPhantom()).toBe(true);
* expect(phantomInstance2.$isPhantom()).toBe(true);
*
* // Change IDs to non-negative numbers
* phantomInstance1.pk = 1;
* phantomInstance2.pk = 2;
*
* expect(phantomInstance1.$isPhantom()).toBe(false);
* expect(phantomInstance2.$isPhantom()).toBe(false);
* });
*/

@@ -93,4 +145,6 @@ function ResourcePhantomIdFactory (generateFn, isPhantomFn) {

* @memberof ResourcePhantomIdFactory
* @param instance
* @return {*}
* @function generate
* @param {ResourceInstance} instance Instance to generate the phantom ID for
* @return {String|int}
* @instance
*/

@@ -105,5 +159,7 @@ self.generate = function (instance) {

* @memberof ResourcePhantomIdFactory
* @param pkValue
* @param instance
* @function isPhantom
* @param {String|int} pkValue ID value to check
* @param {ResourceInstance} instance Instance to work on
* @return {*}
* @instance
*/

@@ -121,4 +177,31 @@ self.isPhantom = function (pkValue, instance) {

* @name ResourcePhantomIdNegativeInt
* @ngdoc factory
* @ngdoc object
* @param {ResourcePhantomIdFactoryService} ResourcePhantomIdFactoryService Phantom ID factory service
*
* @example
* // Using `ResourcePhantomIdNegativeInt`
* inject(function (ResourceFactoryService, ResourcePhantomIdNegativeInt) {
* var
* service = ResourceFactoryService('TestResourceService', 'http://test/:pk/', {
* phantomIdGenerator: ResourcePhantomIdNegativeInt
* }),
* phantomInstance1 = service.new(),
* phantomInstance2 = service.new();
*
* // Test if IDs are negative
* expect(phantomInstance1.pk).toBe(-1);
* expect(phantomInstance2.pk).toBe(-2);
*
* // Test if instances are marked as phantom
* expect(phantomInstance1.$isPhantom()).toBe(true);
* expect(phantomInstance2.$isPhantom()).toBe(true);
*
* // Change IDs
* phantomInstance1.pk = 1;
* phantomInstance2.pk = 2;
*
* // Test if instances are marked as concrete for positive IDs
* expect(phantomInstance1.$isPhantom()).toBe(false);
* expect(phantomInstance2.$isPhantom()).toBe(false);
* });
*/

@@ -147,4 +230,31 @@ module.factory('ResourcePhantomIdNegativeInt',

* @name ResourcePhantomIdUuid4
* @ngdoc factory
* @ngdoc object
* @param {ResourcePhantomIdFactoryService} ResourcePhantomIdFactoryService Phantom ID factory service
*
* @example
* // Using `ResourcePhantomIdUuid4`
* inject(function (ResourceFactoryService, ResourcePhantomIdUuid4) {
* var
* service = ResourceFactoryService('TestResourceService', 'http://test/:pk/', {
* phantomIdGenerator: ResourcePhantomIdUuid4
* }),
* phantomInstance1 = service.new(),
* phantomInstance2 = service.new();
*
* // Test if IDs are valid UUID4s
* expect(phantomInstance1.pk).toMatch(/[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/i);
* expect(phantomInstance2.pk).toMatch(/[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/i);
*
* // Test if instances are marked as phantom as long as UUID4s match one of the generated
* expect(phantomInstance1.$isPhantom()).toBe(true);
* expect(phantomInstance2.$isPhantom()).toBe(true);
*
* // Change IDs
* phantomInstance1.pk = '00000000-0000-0000-0000-000000000000';
* phantomInstance2.pk = '11111111-1111-1111-1111-111111111111';
*
* // Test if instances are marked as concrete for not generated UUID4s
* expect(phantomInstance1.$isPhantom()).toBe(false);
* expect(phantomInstance2.$isPhantom()).toBe(false);
* });
*/

@@ -151,0 +261,0 @@ module.factory('ResourcePhantomIdUuid4',

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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