Comparing version 2.7.0 to 2.7.1
@@ -20,3 +20,2 @@ (function() { | ||
getAbsyncProvider.$inject = ["$provide", "absyncCache"]; | ||
angular | ||
@@ -35,2 +34,3 @@ .module( "absync" ) | ||
} | ||
getAbsyncProvider.$inject = ["$provide", "absyncCache"]; | ||
@@ -311,7 +311,7 @@ /** | ||
* @param {Object} absyncNoopLog A log interface that does nothing. | ||
* @param {Object} absyncUncachedFilter A filter that mutates URLs so they will bypass the browser cache. | ||
* @returns {CacheService} | ||
* @ngInject | ||
*/ | ||
CacheService.$inject = ["$http", "$injector", "$log", "$q", "$rootScope", "absync", "absyncNoopLog"]; | ||
function CacheService( $http, $injector, $log, $q, $rootScope, absync, absyncNoopLog ) { | ||
function CacheService( $http, $injector, $log, $q, $rootScope, absync, absyncNoopLog, absyncUncachedFilter ) { | ||
var self = this; | ||
@@ -347,2 +347,13 @@ | ||
self.__requestCache = {}; | ||
// When we make HTTP requests, the browser is generally allowed to cache the responses. | ||
// The server can control this behavior with cache control HTTPS headers. | ||
// However, at times it may be desirable to force the browser to always fetch fresh data from the backend. | ||
// This hash controls this behavior. | ||
self.allowBrowserCache = angular.merge( {}, { | ||
// Should browser caching be allowed for initial cache sync operations? | ||
sync : true, | ||
// Should browser caching be allowed when we retrieve single entities from the backend? | ||
request : true | ||
}, configuration.allowBrowserCache ); | ||
self.__uncached = absyncUncachedFilter; | ||
@@ -403,2 +414,3 @@ // TODO: Using deferreds is an anti-pattern and probably provides no value here. | ||
} | ||
CacheService.$inject = ["$http", "$injector", "$log", "$q", "$rootScope", "absync", "absyncNoopLog", "absyncUncachedFilter"]; | ||
@@ -530,3 +542,4 @@ /** | ||
self.httpInterface | ||
.get( configuration.entityUri ) | ||
.get( configuration.allowBrowserCache.sync ? configuration.entityUri : self.__uncached( | ||
configuration.entityUri ) ) | ||
.then( onSingleEntityReceived, onSingleEntityRetrievalFailure ); | ||
@@ -543,3 +556,4 @@ | ||
self.httpInterface | ||
.get( configuration.collectionUri ) | ||
.get( configuration.allowBrowserCache.sync ? configuration.collectionUri : self.__uncached( | ||
configuration.collectionUri ) ) | ||
.then( onCollectionReceived, onCollectionRetrievalFailure ); | ||
@@ -581,7 +595,5 @@ } | ||
self.__entityCacheRaw = null; | ||
self.scope.$emit( "absyncError", serverResponse ); | ||
if( self.throwFailures ) { | ||
throw serverResponse; | ||
} | ||
self.__dataAvailableDeferred.reject( serverResponse ); | ||
} | ||
@@ -610,10 +622,13 @@ | ||
self.__entityCacheRaw = null; | ||
self.scope.$emit( "absyncError", serverResponse ); | ||
if( self.throwFailures ) { | ||
throw serverResponse; | ||
} | ||
self.__dataAvailableDeferred.reject( serverResponse ); | ||
} | ||
}; | ||
CacheService.prototype.sync = function CacheService$sync() { | ||
var self = this; | ||
return self.ensureLoaded( true ); | ||
}; | ||
/** | ||
@@ -701,3 +716,3 @@ * Read a single entity from the cache, or load it from the server if required. | ||
var request = self.httpInterface | ||
.get( requestUri ) | ||
.get( configuration.allowBrowserCache.request ? requestUri : self.__uncached( requestUri ) ) | ||
.then( remoteRequestFromCache.bind( self, id ) ); | ||
@@ -1136,5 +1151,6 @@ | ||
* @param {Boolean} [debug=false] Should additional debugging output be enabled? | ||
* @param {Object} [allowBrowserCache] A hash that controls the browsing caching behavior. | ||
* @constructor | ||
*/ | ||
function AbsyncServiceConfiguration( model, collectionUri, entityUri, collectionName, entityName, deserialize, serialize, injector, debug ) { | ||
function AbsyncServiceConfiguration( model, collectionUri, entityUri, collectionName, entityName, deserialize, serialize, injector, debug, allowBrowserCache ) { | ||
this.model = model; | ||
@@ -1154,2 +1170,7 @@ this.collectionUri = collectionUri; | ||
this.debug = debug || false; | ||
this.allowBrowserCache = angular.merge( {}, { | ||
sync : true, | ||
request : true | ||
}, allowBrowserCache ); | ||
} | ||
@@ -1167,2 +1188,24 @@ }());;(function() { | ||
} ); | ||
}());;(function() { | ||
"use strict"; | ||
/* globals angular */ | ||
angular | ||
.module( "absync" ) | ||
.filter( "absyncUncached", uncachedFilterProvider ); | ||
function uncachedFilterProvider() { | ||
return uncachedFilter; | ||
function uncachedFilter( url ) { | ||
if( !url ) { | ||
return url; | ||
} | ||
var delimiter = -1 < url.indexOf( "?" ) ? "&" : "?"; | ||
var discriminator = new Date().getTime(); | ||
return url + delimiter + "t" + discriminator; | ||
} | ||
} | ||
}()); |
@@ -15,3 +15,2 @@ (function() { | ||
getAbsyncProvider.$inject = ["$provide", "absyncCache"]; | ||
angular | ||
@@ -30,2 +29,3 @@ .module( "absync" ) | ||
} | ||
getAbsyncProvider.$inject = ["$provide", "absyncCache"]; | ||
@@ -32,0 +32,0 @@ /** |
@@ -39,7 +39,7 @@ (function() { | ||
* @param {Object} absyncNoopLog A log interface that does nothing. | ||
* @param {Object} absyncUncachedFilter A filter that mutates URLs so they will bypass the browser cache. | ||
* @returns {CacheService} | ||
* @ngInject | ||
*/ | ||
CacheService.$inject = ["$http", "$injector", "$log", "$q", "$rootScope", "absync", "absyncNoopLog"]; | ||
function CacheService( $http, $injector, $log, $q, $rootScope, absync, absyncNoopLog ) { | ||
function CacheService( $http, $injector, $log, $q, $rootScope, absync, absyncNoopLog, absyncUncachedFilter ) { | ||
var self = this; | ||
@@ -75,2 +75,13 @@ | ||
self.__requestCache = {}; | ||
// When we make HTTP requests, the browser is generally allowed to cache the responses. | ||
// The server can control this behavior with cache control HTTPS headers. | ||
// However, at times it may be desirable to force the browser to always fetch fresh data from the backend. | ||
// This hash controls this behavior. | ||
self.allowBrowserCache = angular.merge( {}, { | ||
// Should browser caching be allowed for initial cache sync operations? | ||
sync : true, | ||
// Should browser caching be allowed when we retrieve single entities from the backend? | ||
request : true | ||
}, configuration.allowBrowserCache ); | ||
self.__uncached = absyncUncachedFilter; | ||
@@ -131,2 +142,3 @@ // TODO: Using deferreds is an anti-pattern and probably provides no value here. | ||
} | ||
CacheService.$inject = ["$http", "$injector", "$log", "$q", "$rootScope", "absync", "absyncNoopLog", "absyncUncachedFilter"]; | ||
@@ -258,3 +270,4 @@ /** | ||
self.httpInterface | ||
.get( configuration.entityUri ) | ||
.get( configuration.allowBrowserCache.sync ? configuration.entityUri : self.__uncached( | ||
configuration.entityUri ) ) | ||
.then( onSingleEntityReceived, onSingleEntityRetrievalFailure ); | ||
@@ -271,3 +284,4 @@ | ||
self.httpInterface | ||
.get( configuration.collectionUri ) | ||
.get( configuration.allowBrowserCache.sync ? configuration.collectionUri : self.__uncached( | ||
configuration.collectionUri ) ) | ||
.then( onCollectionReceived, onCollectionRetrievalFailure ); | ||
@@ -309,7 +323,5 @@ } | ||
self.__entityCacheRaw = null; | ||
self.scope.$emit( "absyncError", serverResponse ); | ||
if( self.throwFailures ) { | ||
throw serverResponse; | ||
} | ||
self.__dataAvailableDeferred.reject( serverResponse ); | ||
} | ||
@@ -338,10 +350,13 @@ | ||
self.__entityCacheRaw = null; | ||
self.scope.$emit( "absyncError", serverResponse ); | ||
if( self.throwFailures ) { | ||
throw serverResponse; | ||
} | ||
self.__dataAvailableDeferred.reject( serverResponse ); | ||
} | ||
}; | ||
CacheService.prototype.sync = function CacheService$sync() { | ||
var self = this; | ||
return self.ensureLoaded( true ); | ||
}; | ||
/** | ||
@@ -429,3 +444,3 @@ * Read a single entity from the cache, or load it from the server if required. | ||
var request = self.httpInterface | ||
.get( requestUri ) | ||
.get( configuration.allowBrowserCache.request ? requestUri : self.__uncached( requestUri ) ) | ||
.then( remoteRequestFromCache.bind( self, id ) ); | ||
@@ -432,0 +447,0 @@ |
@@ -35,5 +35,6 @@ (function() { | ||
* @param {Boolean} [debug=false] Should additional debugging output be enabled? | ||
* @param {Object} [allowBrowserCache] A hash that controls the browsing caching behavior. | ||
* @constructor | ||
*/ | ||
function AbsyncServiceConfiguration( model, collectionUri, entityUri, collectionName, entityName, deserialize, serialize, injector, debug ) { | ||
function AbsyncServiceConfiguration( model, collectionUri, entityUri, collectionName, entityName, deserialize, serialize, injector, debug, allowBrowserCache ) { | ||
this.model = model; | ||
@@ -53,3 +54,8 @@ this.collectionUri = collectionUri; | ||
this.debug = debug || false; | ||
this.allowBrowserCache = angular.merge( {}, { | ||
sync : true, | ||
request : true | ||
}, allowBrowserCache ); | ||
} | ||
}()); |
@@ -1,2 +0,2 @@ | ||
!function(){"use strict";angular.module("absync",[])}(),function(){"use strict";function e(e,n){return new t(e,n)}function t(e,t){var n=this;n.__provide=e,n.__absyncCache=t,n.__ioSocket=null,n.__registerLater=[],n.__collections={},n.__entities={}}function n(e){this.__absyncProvider=e}e.$inject=["$provide","absyncCache"],angular.module("absync").provider("absync",e),t.prototype.configure=function(e,t){var n=this,r=e.socket||e,i=io&&io.Socket&&r instanceof io.Socket;if("function"==typeof r)n.__ioSocket=r();else{if(!i)throw new Error("configure() expects input to be a function or a socket.io Socket instance.");n.__ioSocket=r}n.__registerLater.length&&(n.__registerLater.forEach(n.__registerListener.bind(n)),n.__registerLater=[]),n.debug=t||!1},t.prototype.__registerListener=function(e){var t=this;t.$get().__handleEntityEvent(e.eventName,e.callback)},t.prototype.collection=function(e,t){var n=this;if(n.__collections[e])throw new Error("A collection with the name '"+e+"' was already requested. Names for collections must be unique.");if(n.__entities[e])throw new Error("An entity with the name '"+e+"' was already requested. Names for collections must be unique and can't be shared with entities.");t.debug="undefined"==typeof t.debug?n.debug:t.debug,n.__collections[e]=n.__absyncCache(e,t),n.__provide.service(e,n.__collections[e])},t.prototype.entity=function(e,t){var n=this;if(n.__entities[e])throw new Error("An entity with the name '"+e+"' was already requested. Names for entities must be unique.");if(n.__collections[e])throw new Error("A collection with the name '"+e+"' was already requested. Names for entities must be unique and can't be shared with collections.");t.debug="undefined"==typeof t.debug?n.debug:t.debug,n.__entities[e]=n.__absyncCache(e,t),n.__provide.service(e,n.__entities[e])},t.prototype.$get=function(){return new n(this)},n.prototype.configure=function(e,t){var n=this.__absyncProvider;n.configure(e,t||!1)},n.prototype.on=function(e,t){var n=this.__absyncProvider,r=this;return n.__ioSocket?r.__handleEntityEvent(e,t):n.__registerLater.length>8192?null:(n.__registerLater.push({eventName:e,callback:t}),null)},n.prototype.__handleEntityEvent=function(e,t){var n=this.__absyncProvider;return n.__ioSocket.on(e,t),function(){n.__ioSocket.removeListener(e,t)}},n.prototype.emit=function(e,t,n){var r=this.__absyncProvider;if(!r.__ioSocket)throw new Error("socket.io is not initialized.");r.__ioSocket.emit(e,t,function(){n&&n.apply(r.__ioSocket,arguments)})}}(),function(){"use strict";function e(e,n){function r(r,i,o,a,c,s,l){var h=this,d=n.injector||i,u=d.has(n.model);if(!u)throw new Error("Unable to construct the '"+e+"' service, because the referenced model '"+n.model+"' is not available for injection.");var y="string"==typeof n.model?d.get(n.model):n.model,f=y.serialize||n.serialize||t,_=y.deserialize||n.deserialize||t;h.name=e,h.configuration=n,h.entityCache=n.collectionName?[]:{},h.__entityCacheRaw=null,h.enableRequestCache=!0,h.__requestCache={},h.__dataAvailableDeferred=a.defer(),h.__objectsAvailableDeferred=a.defer(),h.dataAvailable=h.__dataAvailableDeferred.promise,h.objectsAvailable=h.__objectsAvailableDeferred.promise,h.httpInterface=r,h.logInterface=n.debug?o:l,h.scope=c,h.q=a,h.logPrefix="absync:"+e.toLocaleUpperCase()+" ",h.forceEarlyCacheUpdate=!1,h.throwFailures=!1,h.serializer=f,h.deserializer=_,s.on(n.entityName,h.__onEntityOnWebsocket.bind(h)),n.collectionName&&s.on(n.collectionName,h.__onCollectionOnWebsocket.bind(h)),c.$on(n.entityName,h.__onEntityReceived.bind(h)),n.collectionName&&c.$on(n.collectionName,h.__onCollectionReceived.bind(h)),h.dataAvailable.then(h.__onDataAvailable.bind(h)),h.logInterface.info(h.logPrefix+"service was instantiated.")}function i(e){var t=this;if(e.data[n.entityName]){var r=t.deserializer(e.data[n.entityName]);return t.forceEarlyCacheUpdate&&t.__updateCacheWithEntity(r),r}throw new Error("The response from the server was not in the expected format. It should have a member named '"+n.entityName+"'.")}function o(e){var t=this;if(t.logInterface.error(t.logPrefix+"Unable to store entity on the server.",e),t.logInterface.error(e),t.scope.$emit("absyncError",e),t.throwFailures)throw e}return r.$inject=["$http","$injector","$log","$q","$rootScope","absync","absyncNoopLog"],r.prototype.__onEntityOnWebsocket=function(e){var t=this;t.scope.$broadcast(n.entityName,e[n.entityName])},r.prototype.__onCollectionOnWebsocket=function(e){var t=this;t.scope.$broadcast(n.collectionName,e[n.collectionName])},r.prototype.__onDataAvailable=function(e){function t(e){r.entityCache.push(r.deserializer(e))}var r=this;if(Array.isArray(r.entityCache))e[n.collectionName].forEach(t),r.__objectsAvailableDeferred.resolve(r.entityCache),r.scope.$broadcast("collectionNew",{service:r,cache:r.entityCache});else{var i=r.deserializer(e[n.entityName]);r.__updateCacheWithEntity(i),r.__objectsAvailableDeferred.resolve(r.entityCache)}},r.prototype.__onEntityReceived=function(e,t){var n=this,r=t;1===Object.keys(r).length&&r.hasOwnProperty("id")?(n.logInterface.info(n.logPrefix+"Entity was deleted from the server. Updating cache…"),n.__removeEntityFromCache(r.id)):(n.logInterface.debug(n.logPrefix+"Entity was updated on the server. Updating cache…"),n.__updateCacheWithEntity(n.deserializer(r)))},r.prototype.__onCollectionReceived=function(e,t){function n(e){var t=r.deserializer(e);r.__updateCacheWithEntity(t)}var r=this,i=t;r.entityCache.length=0,i.forEach(n)},r.prototype.ensureLoaded=function(e){function t(e){if(!e.data[n.collectionName])throw new Error("The response from the server was not in the expected format. It should have a member named '"+n.collectionName+"'.");a.__entityCacheRaw=e.data,a.__dataAvailableDeferred.resolve(e.data)}function r(e){if(a.logInterface.error(a.logPrefix+"Unable to retrieve the collection from the server.",e),a.__entityCacheRaw=null,a.scope.$emit("absyncError",e),a.throwFailures)throw e}function i(e){if(!e.data[n.entityName])throw new Error("The response from the server was not in the expected format. It should have a member named '"+n.entityName+"'.");a.__entityCacheRaw=e.data,a.__dataAvailableDeferred.resolve(e.data)}function o(e){if(a.logInterface.error(a.logPrefix+"Unable to retrieve the entity from the server.",e),a.__entityCacheRaw=null,a.scope.$emit("absyncError",e),a.throwFailures)throw e}var a=this;if(e=e===!0,null===a.__entityCacheRaw||e)if(a.__entityCacheRaw=[],n.collectionName&&n.collectionUri)a.logInterface.info(a.logPrefix+"Retrieving '"+n.collectionName+"' collection…"),a.httpInterface.get(n.collectionUri).then(t,r);else{if(!n.entityName||!n.entityUri)return a.q.when([]);a.__entityCacheRaw={},a.httpInterface.get(n.entityUri).then(i,o)}return a.q.all([a.dataAvailable,a.objectsAvailable]).then(function(){return a.entityCache})},r.prototype.read=function(e,t){function r(e){if(!e.data[n.entityName])throw new Error("The response from the server was not in the expected format. It should have a member named '"+n.entityName+"'.");var t=o.deserializer(e.data[n.entityName]);return o.__updateCacheWithEntity(t),t}function i(t){if(o.logInterface.error(o.logPrefix+"Unable to retrieve entity with ID '"+e+"' from the server.",t),o.scope.$emit("absyncError",t),o.throwFailures)throw t}var o=this;if(t=t===!0,o.logInterface.debug(o.logPrefix+"Requesting entity '"+e+"' (forceReload:"+t+")…"),!t)for(var a=0,c=o.entityCache[0];a<o.entityCache.length;++a,c=o.entityCache[a])if(c.id===e)return o.logInterface.debug(o.logPrefix+"Requested entity '"+e+"' is served from cache."),o.q.when(c);return o.logInterface.debug(o.logPrefix+"Requested entity '"+e+"' is fetched from backend."),o.__requestEntity(e).then(r,i)},r.prototype.__requestEntity=function(e){function t(e,t){return delete r.__requestCache[e],t}var r=this;if(r.enableRequestCache&&r.__requestCache&&r.__requestCache[e])return r.logInterface.debug(r.logPrefix+"Entity request '"+e+"' served from request cache."),r.__requestCache[e];var i=n.entityUri+(e?"/"+e:""),o=r.httpInterface.get(i).then(t.bind(r,e));return r.enableRequestCache&&r.__requestCache&&(r.__requestCache[e]=o),o},r.prototype.update=function(e){var t=this,r=t.reduceComplex(e),a=t.serializer(r),c={};return c[n.entityName]=a,"undefined"!=typeof e.id?t.httpInterface.put(n.entityUri+"/"+e.id,c).then(i.bind(t),o.bind(t)):t.httpInterface.post(n.collectionUri,c).then(i.bind(t),o.bind(t))},r.prototype.patch=function(e){var t=this,r=t.reduceComplex(e),a=t.serializer(r),c={};if(c[n.entityName]=a,"undefined"!=typeof e.id)return t.httpInterface.patch(n.entityUri+"/"+e.id,c).then(i.bind(t),o.bind(t));throw new Error("Attempted to patch an entity that was never stored on the server.")},r.prototype.create=r.prototype.update,r.prototype["delete"]=function(e){function t(e){return i.__removeEntityFromCache(o)}function r(e){if(i.logInterface.error(e.data),i.scope.$emit("absyncError",e),i.throwFailures)throw e}var i=this,o=e.id;return i.httpInterface["delete"](n.entityUri+"/"+o).then(t)["catch"](r)},r.prototype.__updateCacheWithEntity=function(e){var t=this;if(t.logInterface.info(t.logPrefix+"Updating entity '"+(e.id||t.name)+"' in cache…",e),!Array.isArray(t.entityCache))return t.scope.$broadcast("beforeEntityUpdated",{service:t,cache:t.entityCache,entity:t.entityCache,updated:e}),"function"==typeof t.entityCache.copyFrom?t.entityCache.copyFrom(e):angular.extend(t.entityCache,e),void t.scope.$broadcast("entityUpdated",{service:t,cache:t.entityCache,entity:t.entityCache});for(var n=!1,r=0,i=t.entityCache[0];r<t.entityCache.length;++r,i=t.entityCache[r])if(i.id==e.id){t.scope.$broadcast("beforeEntityUpdated",{service:t,cache:t.entityCache,entity:t.entityCache[r],updated:e});var o=t.entityCache[r];"function"==typeof o.copyFrom?o.copyFrom(e):angular.extend(o,e),n=!0,t.scope.$broadcast("entityUpdated",{service:t,cache:t.entityCache,entity:t.entityCache[r]});break}n||(t.scope.$broadcast("beforeEntityNew",{service:t,cache:t.entityCache,entity:e}),t.entityCache.push(e),t.scope.$broadcast("entityNew",{service:t,cache:t.entityCache,entity:e}))},r.prototype.__removeEntityFromCache=function(e){for(var t=this,n=0,r=t.entityCache[0];n<t.entityCache.length;++n,r=t.entityCache[n])if(r.id==e){t.scope.$broadcast("beforeEntityRemoved",{service:t,cache:t.entityCache,entity:r}),t.entityCache.splice(n,1),t.scope.$broadcast("entityRemoved",{service:t,cache:t.entityCache,entity:r});break}},r.prototype.lookupTableById=function(){for(var e=this,t=[],n=0;n<e.entityCache.length;++n)t[e.entityCache[n].id]=e.entityCache[n];return t},r.prototype.reduceComplex=function(e,t){var n=this,r=t?[]:{};for(var i in e)e.hasOwnProperty(i)&&(Array.isArray(e[i])?r[i]=n.reduceComplex(e[i],!0):e[i]&&e[i].id?r[i]=e[i].id:r[i]=e[i]);return r},r.prototype.populateComplex=function(e,t,n,r){function i(i,o){function c(n){return e[t][o]=n,e}if("string"!=typeof e[t][o]){if(!r||"object"!=typeof e[t][o]||"string"!=typeof e[t][o].id)return a.q.when(!1);e[t][o]=e[t][o].id}return n.read(e[t][o]).then(c)}function o(n){e[t]=n}var a=this;if(Array.isArray(e[t])){var c=e[t].map(i);return a.q.all(c)}if("string"!=typeof e[t]){if(!r||"object"!=typeof e[t]||"string"!=typeof e[t].id)return a.q.when(!1);e[t]=e[t].id}return n.read(e[t]).then(o)},r}function t(e){return e}angular.module("absync").constant("absyncCache",e)}(),function(){"use strict";function e(){return t}function t(e,t,n,r,i,o,a,c,s){this.model=e,this.collectionUri=t,this.entityUri=n;var l=e.prototype.constructor.name.toLowerCase();this.collectionName=r||l+"s",this.entityName=i||l,this.deserialize=o||void 0,this.serialize=a||void 0,this.injector=c||void 0,this.debug=s||!1}angular.module("absync").service("AbsyncServiceConfiguration",e)}(),function(){"use strict";angular.module("absync").constant("absyncNoopLog",{debug:angular.noop,info:angular.noop,error:angular.noop})}(); | ||
!function(){"use strict";angular.module("absync",[])}(),function(){"use strict";function e(e,r){return new t(e,r)}function t(e,t){var r=this;r.__provide=e,r.__absyncCache=t,r.__ioSocket=null,r.__registerLater=[],r.__collections={},r.__entities={}}function r(e){this.__absyncProvider=e}angular.module("absync").provider("absync",e),e.$inject=["$provide","absyncCache"],t.prototype.configure=function(e,t){var r=this,n=e.socket||e,i=io&&io.Socket&&n instanceof io.Socket;if("function"==typeof n)r.__ioSocket=n();else{if(!i)throw new Error("configure() expects input to be a function or a socket.io Socket instance.");r.__ioSocket=n}r.__registerLater.length&&(r.__registerLater.forEach(r.__registerListener.bind(r)),r.__registerLater=[]),r.debug=t||!1},t.prototype.__registerListener=function(e){var t=this;t.$get().__handleEntityEvent(e.eventName,e.callback)},t.prototype.collection=function(e,t){var r=this;if(r.__collections[e])throw new Error("A collection with the name '"+e+"' was already requested. Names for collections must be unique.");if(r.__entities[e])throw new Error("An entity with the name '"+e+"' was already requested. Names for collections must be unique and can't be shared with entities.");t.debug="undefined"==typeof t.debug?r.debug:t.debug,r.__collections[e]=r.__absyncCache(e,t),r.__provide.service(e,r.__collections[e])},t.prototype.entity=function(e,t){var r=this;if(r.__entities[e])throw new Error("An entity with the name '"+e+"' was already requested. Names for entities must be unique.");if(r.__collections[e])throw new Error("A collection with the name '"+e+"' was already requested. Names for entities must be unique and can't be shared with collections.");t.debug="undefined"==typeof t.debug?r.debug:t.debug,r.__entities[e]=r.__absyncCache(e,t),r.__provide.service(e,r.__entities[e])},t.prototype.$get=function(){return new r(this)},r.prototype.configure=function(e,t){var r=this.__absyncProvider;r.configure(e,t||!1)},r.prototype.on=function(e,t){var r=this.__absyncProvider,n=this;return r.__ioSocket?n.__handleEntityEvent(e,t):r.__registerLater.length>8192?null:(r.__registerLater.push({eventName:e,callback:t}),null)},r.prototype.__handleEntityEvent=function(e,t){var r=this.__absyncProvider;return r.__ioSocket.on(e,t),function(){r.__ioSocket.removeListener(e,t)}},r.prototype.emit=function(e,t,r){var n=this.__absyncProvider;if(!n.__ioSocket)throw new Error("socket.io is not initialized.");n.__ioSocket.emit(e,t,function(){r&&r.apply(n.__ioSocket,arguments)})}}(),function(){"use strict";function e(e,r){function n(n,i,o,a,c,s,l,h){var d=this,u=r.injector||i,y=u.has(r.model);if(!y)throw new Error("Unable to construct the '"+e+"' service, because the referenced model '"+r.model+"' is not available for injection.");var f="string"==typeof r.model?u.get(r.model):r.model,_=f.serialize||r.serialize||t,p=f.deserialize||r.deserialize||t;d.name=e,d.configuration=r,d.entityCache=r.collectionName?[]:{},d.__entityCacheRaw=null,d.enableRequestCache=!0,d.__requestCache={},d.allowBrowserCache=angular.merge({},{sync:!0,request:!0},r.allowBrowserCache),d.__uncached=h,d.__dataAvailableDeferred=a.defer(),d.__objectsAvailableDeferred=a.defer(),d.dataAvailable=d.__dataAvailableDeferred.promise,d.objectsAvailable=d.__objectsAvailableDeferred.promise,d.httpInterface=n,d.logInterface=r.debug?o:l,d.scope=c,d.q=a,d.logPrefix="absync:"+e.toLocaleUpperCase()+" ",d.forceEarlyCacheUpdate=!1,d.throwFailures=!1,d.serializer=_,d.deserializer=p,s.on(r.entityName,d.__onEntityOnWebsocket.bind(d)),r.collectionName&&s.on(r.collectionName,d.__onCollectionOnWebsocket.bind(d)),c.$on(r.entityName,d.__onEntityReceived.bind(d)),r.collectionName&&c.$on(r.collectionName,d.__onCollectionReceived.bind(d)),d.dataAvailable.then(d.__onDataAvailable.bind(d)),d.logInterface.info(d.logPrefix+"service was instantiated.")}function i(e){var t=this;if(e.data[r.entityName]){var n=t.deserializer(e.data[r.entityName]);return t.forceEarlyCacheUpdate&&t.__updateCacheWithEntity(n),n}throw new Error("The response from the server was not in the expected format. It should have a member named '"+r.entityName+"'.")}function o(e){var t=this;if(t.logInterface.error(t.logPrefix+"Unable to store entity on the server.",e),t.logInterface.error(e),t.scope.$emit("absyncError",e),t.throwFailures)throw e}return n.$inject=["$http","$injector","$log","$q","$rootScope","absync","absyncNoopLog","absyncUncachedFilter"],n.prototype.__onEntityOnWebsocket=function(e){var t=this;t.scope.$broadcast(r.entityName,e[r.entityName])},n.prototype.__onCollectionOnWebsocket=function(e){var t=this;t.scope.$broadcast(r.collectionName,e[r.collectionName])},n.prototype.__onDataAvailable=function(e){function t(e){n.entityCache.push(n.deserializer(e))}var n=this;if(Array.isArray(n.entityCache))e[r.collectionName].forEach(t),n.__objectsAvailableDeferred.resolve(n.entityCache),n.scope.$broadcast("collectionNew",{service:n,cache:n.entityCache});else{var i=n.deserializer(e[r.entityName]);n.__updateCacheWithEntity(i),n.__objectsAvailableDeferred.resolve(n.entityCache)}},n.prototype.__onEntityReceived=function(e,t){var r=this,n=t;1===Object.keys(n).length&&n.hasOwnProperty("id")?(r.logInterface.info(r.logPrefix+"Entity was deleted from the server. Updating cache…"),r.__removeEntityFromCache(n.id)):(r.logInterface.debug(r.logPrefix+"Entity was updated on the server. Updating cache…"),r.__updateCacheWithEntity(r.deserializer(n)))},n.prototype.__onCollectionReceived=function(e,t){function r(e){var t=n.deserializer(e);n.__updateCacheWithEntity(t)}var n=this,i=t;n.entityCache.length=0,i.forEach(r)},n.prototype.ensureLoaded=function(e){function t(e){if(!e.data[r.collectionName])throw new Error("The response from the server was not in the expected format. It should have a member named '"+r.collectionName+"'.");a.__entityCacheRaw=e.data,a.__dataAvailableDeferred.resolve(e.data)}function n(e){a.logInterface.error(a.logPrefix+"Unable to retrieve the collection from the server.",e),a.__entityCacheRaw=null,a.scope.$emit("absyncError",e),a.__dataAvailableDeferred.reject(e)}function i(e){if(!e.data[r.entityName])throw new Error("The response from the server was not in the expected format. It should have a member named '"+r.entityName+"'.");a.__entityCacheRaw=e.data,a.__dataAvailableDeferred.resolve(e.data)}function o(e){a.logInterface.error(a.logPrefix+"Unable to retrieve the entity from the server.",e),a.__entityCacheRaw=null,a.scope.$emit("absyncError",e),a.__dataAvailableDeferred.reject(e)}var a=this;if(e=e===!0,null===a.__entityCacheRaw||e)if(a.__entityCacheRaw=[],r.collectionName&&r.collectionUri)a.logInterface.info(a.logPrefix+"Retrieving '"+r.collectionName+"' collection…"),a.httpInterface.get(r.allowBrowserCache.sync?r.collectionUri:a.__uncached(r.collectionUri)).then(t,n);else{if(!r.entityName||!r.entityUri)return a.q.when([]);a.__entityCacheRaw={},a.httpInterface.get(r.allowBrowserCache.sync?r.entityUri:a.__uncached(r.entityUri)).then(i,o)}return a.q.all([a.dataAvailable,a.objectsAvailable]).then(function(){return a.entityCache})},n.prototype.sync=function(){var e=this;return e.ensureLoaded(!0)},n.prototype.read=function(e,t){function n(e){if(!e.data[r.entityName])throw new Error("The response from the server was not in the expected format. It should have a member named '"+r.entityName+"'.");var t=o.deserializer(e.data[r.entityName]);return o.__updateCacheWithEntity(t),t}function i(t){if(o.logInterface.error(o.logPrefix+"Unable to retrieve entity with ID '"+e+"' from the server.",t),o.scope.$emit("absyncError",t),o.throwFailures)throw t}var o=this;if(t=t===!0,o.logInterface.debug(o.logPrefix+"Requesting entity '"+e+"' (forceReload:"+t+")…"),!t)for(var a=0,c=o.entityCache[0];a<o.entityCache.length;++a,c=o.entityCache[a])if(c.id===e)return o.logInterface.debug(o.logPrefix+"Requested entity '"+e+"' is served from cache."),o.q.when(c);return o.logInterface.debug(o.logPrefix+"Requested entity '"+e+"' is fetched from backend."),o.__requestEntity(e).then(n,i)},n.prototype.__requestEntity=function(e){function t(e,t){return delete n.__requestCache[e],t}var n=this;if(n.enableRequestCache&&n.__requestCache&&n.__requestCache[e])return n.logInterface.debug(n.logPrefix+"Entity request '"+e+"' served from request cache."),n.__requestCache[e];var i=r.entityUri+(e?"/"+e:""),o=n.httpInterface.get(r.allowBrowserCache.request?i:n.__uncached(i)).then(t.bind(n,e));return n.enableRequestCache&&n.__requestCache&&(n.__requestCache[e]=o),o},n.prototype.update=function(e){var t=this,n=t.reduceComplex(e),a=t.serializer(n),c={};return c[r.entityName]=a,"undefined"!=typeof e.id?t.httpInterface.put(r.entityUri+"/"+e.id,c).then(i.bind(t),o.bind(t)):t.httpInterface.post(r.collectionUri,c).then(i.bind(t),o.bind(t))},n.prototype.patch=function(e){var t=this,n=t.reduceComplex(e),a=t.serializer(n),c={};if(c[r.entityName]=a,"undefined"!=typeof e.id)return t.httpInterface.patch(r.entityUri+"/"+e.id,c).then(i.bind(t),o.bind(t));throw new Error("Attempted to patch an entity that was never stored on the server.")},n.prototype.create=n.prototype.update,n.prototype["delete"]=function(e){function t(e){return i.__removeEntityFromCache(o)}function n(e){if(i.logInterface.error(e.data),i.scope.$emit("absyncError",e),i.throwFailures)throw e}var i=this,o=e.id;return i.httpInterface["delete"](r.entityUri+"/"+o).then(t)["catch"](n)},n.prototype.__updateCacheWithEntity=function(e){var t=this;if(t.logInterface.info(t.logPrefix+"Updating entity '"+(e.id||t.name)+"' in cache…",e),!Array.isArray(t.entityCache))return t.scope.$broadcast("beforeEntityUpdated",{service:t,cache:t.entityCache,entity:t.entityCache,updated:e}),"function"==typeof t.entityCache.copyFrom?t.entityCache.copyFrom(e):angular.extend(t.entityCache,e),void t.scope.$broadcast("entityUpdated",{service:t,cache:t.entityCache,entity:t.entityCache});for(var r=!1,n=0,i=t.entityCache[0];n<t.entityCache.length;++n,i=t.entityCache[n])if(i.id==e.id){t.scope.$broadcast("beforeEntityUpdated",{service:t,cache:t.entityCache,entity:t.entityCache[n],updated:e});var o=t.entityCache[n];"function"==typeof o.copyFrom?o.copyFrom(e):angular.extend(o,e),r=!0,t.scope.$broadcast("entityUpdated",{service:t,cache:t.entityCache,entity:t.entityCache[n]});break}r||(t.scope.$broadcast("beforeEntityNew",{service:t,cache:t.entityCache,entity:e}),t.entityCache.push(e),t.scope.$broadcast("entityNew",{service:t,cache:t.entityCache,entity:e}))},n.prototype.__removeEntityFromCache=function(e){for(var t=this,r=0,n=t.entityCache[0];r<t.entityCache.length;++r,n=t.entityCache[r])if(n.id==e){t.scope.$broadcast("beforeEntityRemoved",{service:t,cache:t.entityCache,entity:n}),t.entityCache.splice(r,1),t.scope.$broadcast("entityRemoved",{service:t,cache:t.entityCache,entity:n});break}},n.prototype.lookupTableById=function(){for(var e=this,t=[],r=0;r<e.entityCache.length;++r)t[e.entityCache[r].id]=e.entityCache[r];return t},n.prototype.reduceComplex=function(e,t){var r=this,n=t?[]:{};for(var i in e)e.hasOwnProperty(i)&&(Array.isArray(e[i])?n[i]=r.reduceComplex(e[i],!0):e[i]&&e[i].id?n[i]=e[i].id:n[i]=e[i]);return n},n.prototype.populateComplex=function(e,t,r,n){function i(i,o){function c(r){return e[t][o]=r,e}if("string"!=typeof e[t][o]){if(!n||"object"!=typeof e[t][o]||"string"!=typeof e[t][o].id)return a.q.when(!1);e[t][o]=e[t][o].id}return r.read(e[t][o]).then(c)}function o(r){e[t]=r}var a=this;if(Array.isArray(e[t])){var c=e[t].map(i);return a.q.all(c)}if("string"!=typeof e[t]){if(!n||"object"!=typeof e[t]||"string"!=typeof e[t].id)return a.q.when(!1);e[t]=e[t].id}return r.read(e[t]).then(o)},n}function t(e){return e}angular.module("absync").constant("absyncCache",e)}(),function(){"use strict";function e(){return t}function t(e,t,r,n,i,o,a,c,s,l){this.model=e,this.collectionUri=t,this.entityUri=r;var h=e.prototype.constructor.name.toLowerCase();this.collectionName=n||h+"s",this.entityName=i||h,this.deserialize=o||void 0,this.serialize=a||void 0,this.injector=c||void 0,this.debug=s||!1,this.allowBrowserCache=angular.merge({},{sync:!0,request:!0},l)}angular.module("absync").service("AbsyncServiceConfiguration",e)}(),function(){"use strict";angular.module("absync").constant("absyncNoopLog",{debug:angular.noop,info:angular.noop,error:angular.noop})}(),function(){"use strict";function e(){function e(e){if(!e)return e;var t=-1<e.indexOf("?")?"&":"?",r=(new Date).getTime();return e+t+"t"+r}return e}angular.module("absync").filter("absyncUncached",e)}(); | ||
//# sourceMappingURL=maps/absync.concat.min.js.map |
{ | ||
"name": "absync", | ||
"version": "2.7.0", | ||
"version": "2.7.1", | ||
"description": "absync", | ||
@@ -5,0 +5,0 @@ "main": "dist/development/absync.concat.js", |
@@ -17,5 +17,5 @@ /* globals angular */ | ||
var discriminator = new Date().getTime(); | ||
return url + delimiter + "t" + discriminator; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
871714
42
9463