Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-cacheable

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-cacheable - npm Package Compare versions

Comparing version 1.4.0-beta.1 to 1.4.0-beta.2

9

cache-buster.decorator.js

@@ -1,5 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var operators_1 = require("rxjs/operators");
function CacheBuster(cacheBusterConfig) {
import { tap } from 'rxjs/operators';
export function CacheBuster(cacheBusterConfig) {
return function (_target, _propertyKey, propertyDescriptor) {

@@ -14,3 +12,3 @@ var oldMethod = propertyDescriptor.value;

}
return oldMethod.call.apply(oldMethod, [this].concat(parameters)).pipe(operators_1.tap(function () {
return oldMethod.call.apply(oldMethod, [this].concat(parameters)).pipe(tap(function () {
if (cacheBusterConfig.cacheBusterNotifier) {

@@ -26,4 +24,3 @@ cacheBusterConfig.cacheBusterNotifier.next();

}
exports.CacheBuster = CacheBuster;
;
//# sourceMappingURL=cache-buster.decorator.js.map

@@ -1,8 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var common_1 = require("./common");
exports.globalCacheBusterNotifier = new rxjs_1.Subject();
function Cacheable(cacheConfig) {
import { empty, merge, of, Subject } from 'rxjs';
import { delay, finalize, tap, publishReplay, refCount } from 'rxjs/operators';
import { DEFAULT_CACHE_RESOLVER, GlobalCacheConfig, DEFAULT_HASHER } from './common';
export var globalCacheBusterNotifier = new Subject();
export function Cacheable(cacheConfig) {
if (cacheConfig === void 0) { cacheConfig = {}; }

@@ -14,3 +12,3 @@ return function (_target, _propertyKey, propertyDescriptor) {

var storageStrategy_1 = !cacheConfig.storageStrategy
? new common_1.GlobalCacheConfig.storageStrategy()
? new GlobalCacheConfig.storageStrategy()
: new cacheConfig.storageStrategy();

@@ -23,16 +21,16 @@ var pendingCachePairs_1 = [];

*/
rxjs_1.merge(exports.globalCacheBusterNotifier.asObservable(), cacheConfig.cacheBusterObserver
merge(globalCacheBusterNotifier.asObservable(), cacheConfig.cacheBusterObserver
? cacheConfig.cacheBusterObserver
: rxjs_1.empty()).subscribe(function (_) {
: empty()).subscribe(function (_) {
storageStrategy_1.removeAll(cacheKey);
pendingCachePairs_1.length = 0;
});
var cacheResolver = cacheConfig.cacheResolver || common_1.GlobalCacheConfig.cacheResolver;
var cacheResolver = cacheConfig.cacheResolver || GlobalCacheConfig.cacheResolver;
cacheConfig.cacheResolver = cacheResolver
? cacheResolver
: common_1.DEFAULT_CACHE_RESOLVER;
var cacheHasher = cacheConfig.cacheHasher || common_1.GlobalCacheConfig.cacheHasher;
: DEFAULT_CACHE_RESOLVER;
var cacheHasher = cacheConfig.cacheHasher || GlobalCacheConfig.cacheHasher;
cacheConfig.cacheHasher = cacheHasher
? cacheHasher
: common_1.DEFAULT_HASHER;
: DEFAULT_HASHER;
/* use function instead of an arrow function to keep context of invocation */

@@ -55,5 +53,5 @@ propertyDescriptor.value = function () {

*/
if ((cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge) && _foundCachePair && _foundCachePair.created) {
if ((cacheConfig.maxAge || GlobalCacheConfig.maxAge) && _foundCachePair && _foundCachePair.created) {
if (new Date().getTime() - new Date(_foundCachePair.created).getTime() >
(cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge)) {
(cacheConfig.maxAge || GlobalCacheConfig.maxAge)) {
/**

@@ -65,3 +63,3 @@ * cache duration has expired - remove it from the cachePairs array

}
else if (cacheConfig.slidingExpiration || common_1.GlobalCacheConfig.slidingExpiration) {
else if (cacheConfig.slidingExpiration || GlobalCacheConfig.slidingExpiration) {
/**

@@ -75,4 +73,4 @@ * renew cache duration

if (_foundCachePair) {
var cached$ = rxjs_1.of(_foundCachePair.response);
return cacheConfig.async ? cached$.pipe(operators_1.delay(0)) : cached$;
var cached$ = of(_foundCachePair.response);
return cacheConfig.async ? cached$.pipe(delay(0)) : cached$;
}

@@ -83,3 +81,3 @@ else if (_foundPendingCachePair) {

else {
var response$ = oldMethod.call.apply(oldMethod, [this].concat(parameters)).pipe(operators_1.finalize(function () {
var response$ = oldMethod.call.apply(oldMethod, [this].concat(parameters)).pipe(finalize(function () {
/**

@@ -92,3 +90,3 @@ * if there has been an observable cache pair for these parameters, when it completes or errors, remove it

pendingCachePairs_1.splice(pendingCachePairs_1.indexOf(_pendingCachePairToRemove), 1);
}), operators_1.tap(function (response) {
}), tap(function (response) {
/**

@@ -100,6 +98,6 @@ * if maxCacheCount has not been passed, just shift the cachePair to make room for the new one

cacheConfig.shouldCacheDecider(response)) {
if (!(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) ||
(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) === 1 ||
((cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) &&
(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) < cachePairs.length + 1)) {
if (!(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) ||
(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) === 1 ||
((cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) &&
(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) < cachePairs.length + 1)) {
storageStrategy_1.removeAtIndex(0, cacheKey);

@@ -110,6 +108,6 @@ }

response: response,
created: (cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge) ? new Date() : null
created: (cacheConfig.maxAge || GlobalCacheConfig.maxAge) ? new Date() : null
}, cacheKey);
}
}), operators_1.publishReplay(1), operators_1.refCount());
}), publishReplay(1), refCount());
/**

@@ -130,4 +128,3 @@ * cache the stream

}
exports.Cacheable = Cacheable;
;
//# sourceMappingURL=cacheable.decorator.js.map

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

"use strict";
var __extends = (this && this.__extends) || (function () {

@@ -12,5 +11,4 @@ var extendStatics = Object.setPrototypeOf ||

})();
Object.defineProperty(exports, "__esModule", { value: true });
var IStorageStrategy_1 = require("./IStorageStrategy");
var _1 = require(".");
import { IStorageStrategy } from './IStorageStrategy';
import { GlobalCacheConfig } from '.';
var DOMStorageStrategy = /** @class */ (function (_super) {

@@ -20,3 +18,3 @@ __extends(DOMStorageStrategy, _super);

var _this = _super.call(this) || this;
_this.masterCacheKey = _1.GlobalCacheConfig.globalCacheKey;
_this.masterCacheKey = GlobalCacheConfig.globalCacheKey;
if (typeof localStorage == 'undefined') {

@@ -74,4 +72,4 @@ throw new Error('Platform not supported.');

return DOMStorageStrategy;
}(IStorageStrategy_1.IStorageStrategy));
exports.DOMStorageStrategy = DOMStorageStrategy;
}(IStorageStrategy));
export { DOMStorageStrategy };
//# sourceMappingURL=DOMStorageStrategy.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IAsyncStorageStrategy = /** @class */ (function () {

@@ -8,3 +6,3 @@ function IAsyncStorageStrategy() {

}());
exports.IAsyncStorageStrategy = IAsyncStorageStrategy;
export { IAsyncStorageStrategy };
//# sourceMappingURL=IAsyncStorageStrategy.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ICacheBusterConfig.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ICacheConfig.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ICachePair.js.map

@@ -1,15 +0,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IStorageStrategy_1 = require("./IStorageStrategy");
exports.IStorageStrategy = IStorageStrategy_1.IStorageStrategy;
var InMemoryStorageStrategy_1 = require("./InMemoryStorageStrategy");
exports.DEFAULT_CACHE_RESOLVER = function (oldParams, newParams) {
import { IStorageStrategy } from './IStorageStrategy';
import { InMemoryStorageStrategy } from './InMemoryStorageStrategy';
export var DEFAULT_CACHE_RESOLVER = function (oldParams, newParams) {
return JSON.stringify(oldParams) === JSON.stringify(newParams);
};
exports.DEFAULT_HASHER = function (parameters) { return parameters.map(function (param) { return param !== undefined ? JSON.parse(JSON.stringify(param)) : param; }); };
exports.GlobalCacheConfig = {
storageStrategy: InMemoryStorageStrategy_1.InMemoryStorageStrategy,
export var DEFAULT_HASHER = function (parameters) { return parameters.map(function (param) { return param !== undefined ? JSON.parse(JSON.stringify(param)) : param; }); };
export var GlobalCacheConfig = {
storageStrategy: InMemoryStorageStrategy,
globalCacheKey: 'CACHE_STORAGE',
promiseImplementation: Promise
};
export { IStorageStrategy };
//# sourceMappingURL=index.js.map

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

"use strict";
var __extends = (this && this.__extends) || (function () {

@@ -12,4 +11,3 @@ var extendStatics = Object.setPrototypeOf ||

})();
Object.defineProperty(exports, "__esModule", { value: true });
var IStorageStrategy_1 = require("./IStorageStrategy");
import { IStorageStrategy } from './IStorageStrategy';
var InMemoryStorageStrategy = /** @class */ (function (_super) {

@@ -41,4 +39,4 @@ __extends(InMemoryStorageStrategy, _super);

return InMemoryStorageStrategy;
}(IStorageStrategy_1.IStorageStrategy));
exports.InMemoryStorageStrategy = InMemoryStorageStrategy;
}(IStorageStrategy));
export { InMemoryStorageStrategy };
//# sourceMappingURL=InMemoryStorageStrategy.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IObservableCacheConfig.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IStorageStrategy = /** @class */ (function () {

@@ -8,3 +6,3 @@ function IStorageStrategy() {

}());
exports.IStorageStrategy = IStorageStrategy;
export { IStorageStrategy };
//# sourceMappingURL=IStorageStrategy.js.map

@@ -1,3 +0,5 @@

import { tap } from 'rxjs/operators';
export function CacheBuster(cacheBusterConfig) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var operators_1 = require("rxjs/operators");
function CacheBuster(cacheBusterConfig) {
return function (_target, _propertyKey, propertyDescriptor) {

@@ -12,3 +14,3 @@ var oldMethod = propertyDescriptor.value;

}
return oldMethod.call.apply(oldMethod, [this].concat(parameters)).pipe(tap(function () {
return oldMethod.call.apply(oldMethod, [this].concat(parameters)).pipe(operators_1.tap(function () {
if (cacheBusterConfig.cacheBusterNotifier) {

@@ -24,3 +26,4 @@ cacheBusterConfig.cacheBusterNotifier.next();

}
exports.CacheBuster = CacheBuster;
;
//# sourceMappingURL=cache-buster.decorator.js.map

@@ -1,6 +0,8 @@

import { empty, merge, of, Subject } from 'rxjs';
import { delay, finalize, tap, publishReplay, refCount } from 'rxjs/operators';
import { DEFAULT_CACHE_RESOLVER, GlobalCacheConfig, DEFAULT_HASHER } from './common';
export var globalCacheBusterNotifier = new Subject();
export function Cacheable(cacheConfig) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var common_1 = require("./common");
exports.globalCacheBusterNotifier = new rxjs_1.Subject();
function Cacheable(cacheConfig) {
if (cacheConfig === void 0) { cacheConfig = {}; }

@@ -12,3 +14,3 @@ return function (_target, _propertyKey, propertyDescriptor) {

var storageStrategy_1 = !cacheConfig.storageStrategy
? new GlobalCacheConfig.storageStrategy()
? new common_1.GlobalCacheConfig.storageStrategy()
: new cacheConfig.storageStrategy();

@@ -21,16 +23,16 @@ var pendingCachePairs_1 = [];

*/
merge(globalCacheBusterNotifier.asObservable(), cacheConfig.cacheBusterObserver
rxjs_1.merge(exports.globalCacheBusterNotifier.asObservable(), cacheConfig.cacheBusterObserver
? cacheConfig.cacheBusterObserver
: empty()).subscribe(function (_) {
: rxjs_1.empty()).subscribe(function (_) {
storageStrategy_1.removeAll(cacheKey);
pendingCachePairs_1.length = 0;
});
var cacheResolver = cacheConfig.cacheResolver || GlobalCacheConfig.cacheResolver;
var cacheResolver = cacheConfig.cacheResolver || common_1.GlobalCacheConfig.cacheResolver;
cacheConfig.cacheResolver = cacheResolver
? cacheResolver
: DEFAULT_CACHE_RESOLVER;
var cacheHasher = cacheConfig.cacheHasher || GlobalCacheConfig.cacheHasher;
: common_1.DEFAULT_CACHE_RESOLVER;
var cacheHasher = cacheConfig.cacheHasher || common_1.GlobalCacheConfig.cacheHasher;
cacheConfig.cacheHasher = cacheHasher
? cacheHasher
: DEFAULT_HASHER;
: common_1.DEFAULT_HASHER;
/* use function instead of an arrow function to keep context of invocation */

@@ -53,5 +55,5 @@ propertyDescriptor.value = function () {

*/
if ((cacheConfig.maxAge || GlobalCacheConfig.maxAge) && _foundCachePair && _foundCachePair.created) {
if ((cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge) && _foundCachePair && _foundCachePair.created) {
if (new Date().getTime() - new Date(_foundCachePair.created).getTime() >
(cacheConfig.maxAge || GlobalCacheConfig.maxAge)) {
(cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge)) {
/**

@@ -63,3 +65,3 @@ * cache duration has expired - remove it from the cachePairs array

}
else if (cacheConfig.slidingExpiration || GlobalCacheConfig.slidingExpiration) {
else if (cacheConfig.slidingExpiration || common_1.GlobalCacheConfig.slidingExpiration) {
/**

@@ -73,4 +75,4 @@ * renew cache duration

if (_foundCachePair) {
var cached$ = of(_foundCachePair.response);
return cacheConfig.async ? cached$.pipe(delay(0)) : cached$;
var cached$ = rxjs_1.of(_foundCachePair.response);
return cacheConfig.async ? cached$.pipe(operators_1.delay(0)) : cached$;
}

@@ -81,3 +83,3 @@ else if (_foundPendingCachePair) {

else {
var response$ = oldMethod.call.apply(oldMethod, [this].concat(parameters)).pipe(finalize(function () {
var response$ = oldMethod.call.apply(oldMethod, [this].concat(parameters)).pipe(operators_1.finalize(function () {
/**

@@ -90,3 +92,3 @@ * if there has been an observable cache pair for these parameters, when it completes or errors, remove it

pendingCachePairs_1.splice(pendingCachePairs_1.indexOf(_pendingCachePairToRemove), 1);
}), tap(function (response) {
}), operators_1.tap(function (response) {
/**

@@ -98,6 +100,6 @@ * if maxCacheCount has not been passed, just shift the cachePair to make room for the new one

cacheConfig.shouldCacheDecider(response)) {
if (!(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) ||
(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) === 1 ||
((cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) &&
(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) < cachePairs.length + 1)) {
if (!(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) ||
(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) === 1 ||
((cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) &&
(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) < cachePairs.length + 1)) {
storageStrategy_1.removeAtIndex(0, cacheKey);

@@ -108,6 +110,6 @@ }

response: response,
created: (cacheConfig.maxAge || GlobalCacheConfig.maxAge) ? new Date() : null
created: (cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge) ? new Date() : null
}, cacheKey);
}
}), publishReplay(1), refCount());
}), operators_1.publishReplay(1), operators_1.refCount());
/**

@@ -128,3 +130,4 @@ * cache the stream

}
exports.Cacheable = Cacheable;
;
//# sourceMappingURL=cacheable.decorator.js.map

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

"use strict";
var __extends = (this && this.__extends) || (function () {

@@ -11,4 +12,5 @@ var extendStatics = Object.setPrototypeOf ||

})();
import { IStorageStrategy } from './IStorageStrategy';
import { GlobalCacheConfig } from '.';
Object.defineProperty(exports, "__esModule", { value: true });
var IStorageStrategy_1 = require("./IStorageStrategy");
var _1 = require(".");
var DOMStorageStrategy = /** @class */ (function (_super) {

@@ -18,3 +20,3 @@ __extends(DOMStorageStrategy, _super);

var _this = _super.call(this) || this;
_this.masterCacheKey = GlobalCacheConfig.globalCacheKey;
_this.masterCacheKey = _1.GlobalCacheConfig.globalCacheKey;
if (typeof localStorage == 'undefined') {

@@ -72,4 +74,4 @@ throw new Error('Platform not supported.');

return DOMStorageStrategy;
}(IStorageStrategy));
export { DOMStorageStrategy };
}(IStorageStrategy_1.IStorageStrategy));
exports.DOMStorageStrategy = DOMStorageStrategy;
//# sourceMappingURL=DOMStorageStrategy.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IAsyncStorageStrategy = /** @class */ (function () {

@@ -6,3 +8,3 @@ function IAsyncStorageStrategy() {

}());
export { IAsyncStorageStrategy };
exports.IAsyncStorageStrategy = IAsyncStorageStrategy;
//# sourceMappingURL=IAsyncStorageStrategy.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ICacheBusterConfig.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ICacheConfig.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ICachePair.js.map

@@ -1,13 +0,15 @@

import { IStorageStrategy } from './IStorageStrategy';
import { InMemoryStorageStrategy } from './InMemoryStorageStrategy';
export var DEFAULT_CACHE_RESOLVER = function (oldParams, newParams) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IStorageStrategy_1 = require("./IStorageStrategy");
exports.IStorageStrategy = IStorageStrategy_1.IStorageStrategy;
var InMemoryStorageStrategy_1 = require("./InMemoryStorageStrategy");
exports.DEFAULT_CACHE_RESOLVER = function (oldParams, newParams) {
return JSON.stringify(oldParams) === JSON.stringify(newParams);
};
export var DEFAULT_HASHER = function (parameters) { return parameters.map(function (param) { return param !== undefined ? JSON.parse(JSON.stringify(param)) : param; }); };
export var GlobalCacheConfig = {
storageStrategy: InMemoryStorageStrategy,
exports.DEFAULT_HASHER = function (parameters) { return parameters.map(function (param) { return param !== undefined ? JSON.parse(JSON.stringify(param)) : param; }); };
exports.GlobalCacheConfig = {
storageStrategy: InMemoryStorageStrategy_1.InMemoryStorageStrategy,
globalCacheKey: 'CACHE_STORAGE',
promiseImplementation: Promise
};
export { IStorageStrategy };
//# sourceMappingURL=index.js.map

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

"use strict";
var __extends = (this && this.__extends) || (function () {

@@ -11,3 +12,4 @@ var extendStatics = Object.setPrototypeOf ||

})();
import { IStorageStrategy } from './IStorageStrategy';
Object.defineProperty(exports, "__esModule", { value: true });
var IStorageStrategy_1 = require("./IStorageStrategy");
var InMemoryStorageStrategy = /** @class */ (function (_super) {

@@ -39,4 +41,4 @@ __extends(InMemoryStorageStrategy, _super);

return InMemoryStorageStrategy;
}(IStorageStrategy));
export { InMemoryStorageStrategy };
}(IStorageStrategy_1.IStorageStrategy));
exports.InMemoryStorageStrategy = InMemoryStorageStrategy;
//# sourceMappingURL=InMemoryStorageStrategy.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IObservableCacheConfig.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IStorageStrategy = /** @class */ (function () {

@@ -6,3 +8,3 @@ function IStorageStrategy() {

}());
export { IStorageStrategy };
exports.IStorageStrategy = IStorageStrategy;
//# sourceMappingURL=IStorageStrategy.js.map

@@ -1,7 +0,12 @@

export * from './cache-buster.decorator';
export * from './cacheable.decorator';
export * from './promise.cache-buster.decorator';
export * from './promise.cacheable.decorator';
export * from './common';
export * from './common/InMemoryStorageStrategy';
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./cache-buster.decorator"));
__export(require("./cacheable.decorator"));
__export(require("./promise.cache-buster.decorator"));
__export(require("./promise.cacheable.decorator"));
__export(require("./common"));
__export(require("./common/InMemoryStorageStrategy"));
//# sourceMappingURL=index.js.map

@@ -1,2 +0,4 @@

export function PCacheBuster(cacheBusterConfig) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function PCacheBuster(cacheBusterConfig) {
return function (_target, _propertyKey, propertyDescriptor) {

@@ -23,3 +25,4 @@ var oldMethod = propertyDescriptor.value;

}
exports.PCacheBuster = PCacheBuster;
;
//# sourceMappingURL=promise.cache-buster.decorator.js.map

@@ -1,4 +0,6 @@

import { empty, merge, Subject } from 'rxjs';
import { DEFAULT_CACHE_RESOLVER, GlobalCacheConfig, DEFAULT_HASHER } from './common';
export var promiseGlobalCacheBusterNotifier = new Subject();
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var common_1 = require("./common");
exports.promiseGlobalCacheBusterNotifier = new rxjs_1.Subject();
var getResponse = function (oldMethod, cacheKey, cacheConfig, context, cachePairs, parameters, pendingCachePairs, storageStrategy, promiseImplementation) {

@@ -15,5 +17,5 @@ var cacheParameters = cacheConfig.cacheHasher(parameters);

*/
if ((cacheConfig.maxAge || GlobalCacheConfig.maxAge) && _foundCachePair && _foundCachePair.created) {
if ((cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge) && _foundCachePair && _foundCachePair.created) {
if (new Date().getTime() - new Date(_foundCachePair.created).getTime() >
(cacheConfig.maxAge || GlobalCacheConfig.maxAge)) {
(cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge)) {
/**

@@ -25,3 +27,3 @@ * cache duration has expired - remove it from the cachePairs array

}
else if (cacheConfig.slidingExpiration || GlobalCacheConfig.slidingExpiration) {
else if (cacheConfig.slidingExpiration || common_1.GlobalCacheConfig.slidingExpiration) {
/**

@@ -51,6 +53,6 @@ * renew cache duration

cacheConfig.shouldCacheDecider(response)) {
if (!(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) ||
(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) === 1 ||
((cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) &&
(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) < cachePairs.length + 1)) {
if (!(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) ||
(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) === 1 ||
((cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) &&
(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) < cachePairs.length + 1)) {
storageStrategy.removeAtIndex(0, cacheKey);

@@ -61,3 +63,3 @@ }

response: response,
created: (cacheConfig.maxAge || GlobalCacheConfig.maxAge) ? new Date() : null
created: (cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge) ? new Date() : null
}, cacheKey);

@@ -92,3 +94,3 @@ }

};
export function PCacheable(cacheConfig) {
function PCacheable(cacheConfig) {
if (cacheConfig === void 0) { cacheConfig = {}; }

@@ -100,3 +102,3 @@ return function (_target, _propertyKey, propertyDescriptor) {

var storageStrategy_1 = !cacheConfig.storageStrategy
? new GlobalCacheConfig.storageStrategy()
? new common_1.GlobalCacheConfig.storageStrategy()
: new cacheConfig.storageStrategy();

@@ -109,16 +111,16 @@ var pendingCachePairs_1 = [];

*/
merge(promiseGlobalCacheBusterNotifier.asObservable(), cacheConfig.cacheBusterObserver
rxjs_1.merge(exports.promiseGlobalCacheBusterNotifier.asObservable(), cacheConfig.cacheBusterObserver
? cacheConfig.cacheBusterObserver
: empty()).subscribe(function (_) {
: rxjs_1.empty()).subscribe(function (_) {
storageStrategy_1.removeAll(cacheKey);
pendingCachePairs_1.length = 0;
});
var cacheResolver = cacheConfig.cacheResolver || GlobalCacheConfig.cacheResolver;
var cacheResolver = cacheConfig.cacheResolver || common_1.GlobalCacheConfig.cacheResolver;
cacheConfig.cacheResolver = cacheResolver
? cacheResolver
: DEFAULT_CACHE_RESOLVER;
var cacheHasher = cacheConfig.cacheHasher || GlobalCacheConfig.cacheHasher;
: common_1.DEFAULT_CACHE_RESOLVER;
var cacheHasher = cacheConfig.cacheHasher || common_1.GlobalCacheConfig.cacheHasher;
cacheConfig.cacheHasher = cacheHasher
? cacheHasher
: DEFAULT_HASHER;
: common_1.DEFAULT_HASHER;
/* use function instead of an arrow function to keep context of invocation */

@@ -131,5 +133,5 @@ propertyDescriptor.value = function () {

}
var promiseImplementation = typeof GlobalCacheConfig.promiseImplementation === 'function' && (GlobalCacheConfig.promiseImplementation !== Promise) ?
GlobalCacheConfig.promiseImplementation.call(this)
: GlobalCacheConfig.promiseImplementation;
var promiseImplementation = typeof common_1.GlobalCacheConfig.promiseImplementation === 'function' && (common_1.GlobalCacheConfig.promiseImplementation !== Promise) ?
common_1.GlobalCacheConfig.promiseImplementation.call(this)
: common_1.GlobalCacheConfig.promiseImplementation;
var cachePairs = storageStrategy_1.getAll(cacheKey);

@@ -147,3 +149,4 @@ if (!(cachePairs instanceof promiseImplementation)) {

}
exports.PCacheable = PCacheable;
;
//# sourceMappingURL=promise.cacheable.decorator.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Cat = /** @class */ (function () {

@@ -8,3 +10,3 @@ function Cat() {

}());
export { Cat };
exports.Cat = Cat;
//# sourceMappingURL=cat.js.map

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

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -43,20 +44,21 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

var _this = this;
import { combineLatest, forkJoin } from 'rxjs';
import { startWith } from 'rxjs/operators';
import { globalCacheBusterNotifier } from '../cacheable.decorator';
import { Cacheable } from '../cacheable.decorator';
import { CacheBuster } from '../cache-buster.decorator';
import { timer, Subject } from 'rxjs';
import { mapTo } from 'rxjs/operators';
import { GlobalCacheConfig } from '../common';
import { DOMStorageStrategy } from '../common/DOMStorageStrategy';
import { InMemoryStorageStrategy } from '../common/InMemoryStorageStrategy';
import { Cat } from './cat';
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var cacheable_decorator_1 = require("../cacheable.decorator");
var cacheable_decorator_2 = require("../cacheable.decorator");
var cache_buster_decorator_1 = require("../cache-buster.decorator");
var rxjs_2 = require("rxjs");
var operators_2 = require("rxjs/operators");
var common_1 = require("../common");
var DOMStorageStrategy_1 = require("../common/DOMStorageStrategy");
var InMemoryStorageStrategy_1 = require("../common/InMemoryStorageStrategy");
var cat_1 = require("./cat");
var strategies = [
null,
DOMStorageStrategy
DOMStorageStrategy_1.DOMStorageStrategy
];
strategies.forEach(function (s) {
if (s) {
GlobalCacheConfig.storageStrategy = s;
common_1.GlobalCacheConfig.storageStrategy = s;
}

@@ -67,3 +69,3 @@ describe('CacheableDecorator', function () {

beforeEach(function () {
var cacheBusterNotifier = new Subject();
var cacheBusterNotifier = new rxjs_2.Subject();
var Service = /** @class */ (function () {

@@ -73,9 +75,9 @@ function Service() {

Service.prototype.mockServiceCall = function (parameter) {
return timer(1000).pipe(mapTo({ payload: parameter }));
return rxjs_2.timer(1000).pipe(operators_2.mapTo({ payload: parameter }));
};
Service.prototype.mockSaveServiceCall = function () {
return timer(1000).pipe(mapTo('SAVED'));
return rxjs_2.timer(1000).pipe(operators_2.mapTo('SAVED'));
};
Service.prototype.mockServiceCallWithMultipleParameters = function (parameter1, parameter2) {
return timer(1000).pipe(mapTo({ payload: [parameter1, parameter2] }));
return rxjs_2.timer(1000).pipe(operators_2.mapTo({ payload: [parameter1, parameter2] }));
};

@@ -140,12 +142,12 @@ Service.prototype.getData = function (parameter) {

__decorate([
Cacheable()
cacheable_decorator_2.Cacheable()
], Service.prototype, "getData", null);
__decorate([
Cacheable()
cacheable_decorator_2.Cacheable()
], Service.prototype, "getDataWithParamsObj", null);
__decorate([
Cacheable()
cacheable_decorator_2.Cacheable()
], Service.prototype, "getDataAndReturnCachedStream", null);
__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
async: true

@@ -155,3 +157,3 @@ })

__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
maxAge: 7500

@@ -161,3 +163,3 @@ })

__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
maxAge: 7500,

@@ -168,3 +170,3 @@ slidingExpiration: true

__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
maxCacheCount: 5

@@ -174,3 +176,3 @@ })

__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
maxAge: 7500,

@@ -181,3 +183,3 @@ maxCacheCount: 5

__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
maxAge: 7500,

@@ -189,3 +191,3 @@ maxCacheCount: 5,

__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
cacheResolver: function (_oldParameters, newParameters) {

@@ -197,3 +199,3 @@ return newParameters.find(function (param) { return !!param.straightToLastCache; });

__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
cacheHasher: function (_parameters) { return _parameters[0] * 2; },

@@ -206,6 +208,6 @@ cacheResolver: function (oldParameter, newParameter) {

__decorate([
Cacheable()
cacheable_decorator_2.Cacheable()
], Service.prototype, "getWithAComplexType", null);
__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
shouldCacheDecider: function (response) {

@@ -217,3 +219,3 @@ return response.payload === 'test';

__decorate([
CacheBuster({
cache_buster_decorator_1.CacheBuster({
cacheBusterNotifier: cacheBusterNotifier

@@ -223,3 +225,3 @@ })

__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
cacheBusterObserver: cacheBusterNotifier.asObservable()

@@ -229,12 +231,12 @@ })

__decorate([
Cacheable()
cacheable_decorator_2.Cacheable()
], Service.prototype, "getDataWithUndefinedParameter", null);
__decorate([
Cacheable()
cacheable_decorator_2.Cacheable()
], Service.prototype, "getDataWithMultipleUndefinedParameters", null);
__decorate([
Cacheable({
cacheable_decorator_2.Cacheable({
maxAge: 7500,
slidingExpiration: true,
storageStrategy: InMemoryStorageStrategy
storageStrategy: InMemoryStorageStrategy_1.InMemoryStorageStrategy
})

@@ -247,3 +249,3 @@ ], Service.prototype, "getDateWithCustomStorageStrategyProvided", null);

mockServiceCallSpy = spyOn(service, 'mockServiceCall').and.callThrough();
if (GlobalCacheConfig.storageStrategy === DOMStorageStrategy) {
if (common_1.GlobalCacheConfig.storageStrategy === DOMStorageStrategy_1.DOMStorageStrategy) {
localStorage.clear();

@@ -463,3 +465,3 @@ }

*/
var cachedResponseAll = _timedStreamAsyncAwait(forkJoin(parameters.map(function (param) { return service.getDataWithMaxCacheCount(param); })));
var cachedResponseAll = _timedStreamAsyncAwait(rxjs_1.forkJoin(parameters.map(function (param) { return service.getDataWithMaxCacheCount(param); })));
expect(cachedResponseAll).toEqual([

@@ -485,3 +487,3 @@ { payload: 'test1' },

*/
var cachedResponseAll2 = _timedStreamAsyncAwait(forkJoin(newParameters.map(function (param) { return service.getDataWithMaxCacheCount(param); })), 1000);
var cachedResponseAll2 = _timedStreamAsyncAwait(rxjs_1.forkJoin(newParameters.map(function (param) { return service.getDataWithMaxCacheCount(param); })), 1000);
expect(cachedResponseAll2).toEqual([

@@ -523,3 +525,3 @@ { payload: 'test2' },

jasmine.clock().tick(1000);
var cachedResponse2 = _timedStreamAsyncAwait(forkJoin(parameters.map(function (param) {
var cachedResponse2 = _timedStreamAsyncAwait(rxjs_1.forkJoin(parameters.map(function (param) {
return service.getDataWithMaxCacheCountAndExpiration(param);

@@ -573,6 +575,6 @@ })));

jasmine.clock().tick(1);
var cachedResponse = _timedStreamAsyncAwait(combineLatest(parameters.map(function (param) {
var cachedResponse = _timedStreamAsyncAwait(rxjs_1.combineLatest(parameters.map(function (param) {
return service
.getDataWithMaxCacheCountAndSlidingExpiration(param)
.pipe(startWith(null));
.pipe(operators_1.startWith(null));
})));

@@ -626,4 +628,4 @@ /**

it('return cached data up until new parameters are passed WITH a custom GLOBAL resolver and hasher function', function () {
GlobalCacheConfig.cacheHasher = function (_parameters) { return _parameters[0] + '__wehoo'; };
GlobalCacheConfig.cacheResolver = function (oldParameter, newParameter) {
common_1.GlobalCacheConfig.cacheHasher = function (_parameters) { return _parameters[0] + '__wehoo'; };
common_1.GlobalCacheConfig.cacheResolver = function (oldParameter, newParameter) {
return newParameter === 'cached__wehoo';

@@ -635,3 +637,3 @@ };

Service.prototype.mockServiceCall = function (parameter) {
return timer(1000).pipe(mapTo({ payload: parameter }));
return rxjs_2.timer(1000).pipe(operators_2.mapTo({ payload: parameter }));
};

@@ -642,3 +644,3 @@ Service.prototype.getData = function (parameter) {

__decorate([
Cacheable()
cacheable_decorator_2.Cacheable()
], Service.prototype, "getData", null);

@@ -660,7 +662,7 @@ return Service;

expect(mockServiceCallSpy).toHaveBeenCalledTimes(5);
GlobalCacheConfig.cacheHasher = undefined;
GlobalCacheConfig.cacheResolver = undefined;
common_1.GlobalCacheConfig.cacheHasher = undefined;
common_1.GlobalCacheConfig.cacheResolver = undefined;
});
it('should call a function with a complex instance which should not be touched and passed to the original method as it is', function () {
var complexObject = new Cat();
var complexObject = new cat_1.Cat();
complexObject.name = 'Felix';

@@ -757,3 +759,3 @@ var response = _timedStreamAsyncAwait(service.getWithAComplexType(complexObject), 1000);

*/
globalCacheBusterNotifier.next();
cacheable_decorator_1.globalCacheBusterNotifier.next();
_timedStreamAsyncAwait(service.getData('test1'), 1000);

@@ -782,7 +784,7 @@ _timedStreamAsyncAwait(service.getData('test2'), 1000);

it('should work correctly with a custom storage strategy', function () {
var addSpy = spyOn(InMemoryStorageStrategy.prototype, 'add').and.callThrough();
var updateAtIndexSpy = spyOn(InMemoryStorageStrategy.prototype, 'updateAtIndex').and.callThrough();
var getAllSpy = spyOn(InMemoryStorageStrategy.prototype, 'getAll').and.callThrough();
var removeAtIndexSpy = spyOn(InMemoryStorageStrategy.prototype, 'removeAtIndex').and.callThrough();
var removeAllSpy = spyOn(InMemoryStorageStrategy.prototype, 'removeAll').and.callThrough();
var addSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'add').and.callThrough();
var updateAtIndexSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'updateAtIndex').and.callThrough();
var getAllSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'getAll').and.callThrough();
var removeAtIndexSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'removeAtIndex').and.callThrough();
var removeAllSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'removeAll').and.callThrough();
jasmine.clock().mockDate();

@@ -853,3 +855,3 @@ var asyncFreshData = _timedStreamAsyncAwait(service.getDateWithCustomStorageStrategyProvided('test'), 1000);

*/
globalCacheBusterNotifier.next();
cacheable_decorator_1.globalCacheBusterNotifier.next();
expect(addSpy).toHaveBeenCalledTimes(1);

@@ -862,4 +864,4 @@ expect(updateAtIndexSpy).toHaveBeenCalledTimes(3);

it('use the maxAge and slidingExpiration from the GlobalCacheConfig', function () {
GlobalCacheConfig.maxAge = 7500;
GlobalCacheConfig.slidingExpiration = true;
common_1.GlobalCacheConfig.maxAge = 7500;
common_1.GlobalCacheConfig.slidingExpiration = true;
jasmine.clock().mockDate();

@@ -903,7 +905,7 @@ var asyncFreshData = _timedStreamAsyncAwait(service.getData('test'), 1000);

expect(mockServiceCallSpy).toHaveBeenCalledTimes(2);
GlobalCacheConfig.maxAge = undefined;
GlobalCacheConfig.slidingExpiration;
common_1.GlobalCacheConfig.maxAge = undefined;
common_1.GlobalCacheConfig.slidingExpiration;
});
it('use the maxCacheCount from the GlobalCacheConfig', function () {
GlobalCacheConfig.maxCacheCount = 5;
common_1.GlobalCacheConfig.maxCacheCount = 5;
/**

@@ -927,3 +929,3 @@ * call the same endpoint with 5 different parameters and cache all 5 responses, based on the maxCacheCount parameter

*/
var cachedResponseAll = _timedStreamAsyncAwait(forkJoin(parameters.map(function (param) { return service.getData(param); })));
var cachedResponseAll = _timedStreamAsyncAwait(rxjs_1.forkJoin(parameters.map(function (param) { return service.getData(param); })));
expect(cachedResponseAll).toEqual([

@@ -949,3 +951,3 @@ { payload: 'test1' },

*/
var cachedResponseAll2 = _timedStreamAsyncAwait(forkJoin(newParameters.map(function (param) { return service.getData(param); })), 1000);
var cachedResponseAll2 = _timedStreamAsyncAwait(rxjs_1.forkJoin(newParameters.map(function (param) { return service.getData(param); })), 1000);
expect(cachedResponseAll2).toEqual([

@@ -975,6 +977,6 @@ { payload: 'test2' },

expect(mockServiceCallSpy).toHaveBeenCalledTimes(8);
GlobalCacheConfig.maxCacheCount = undefined;
common_1.GlobalCacheConfig.maxCacheCount = undefined;
});
it('use the maxAge from the GlobalCacheConfig', function () {
GlobalCacheConfig.maxAge = 10000;
common_1.GlobalCacheConfig.maxAge = 10000;
jasmine.clock().mockDate();

@@ -1006,3 +1008,3 @@ var asyncFreshData = _timedStreamAsyncAwait(service.getData('test'), 1000);

expect(asyncFreshDataAfterCacheBust).toEqual({ payload: 'test' });
GlobalCacheConfig.maxAge = undefined;
common_1.GlobalCacheConfig.maxAge = undefined;
});

@@ -1009,0 +1011,0 @@ });

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=service.interface.js.map

@@ -1,12 +0,7 @@

"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./cache-buster.decorator"));
__export(require("./cacheable.decorator"));
__export(require("./promise.cache-buster.decorator"));
__export(require("./promise.cacheable.decorator"));
__export(require("./common"));
__export(require("./common/InMemoryStorageStrategy"));
export * from './cache-buster.decorator';
export * from './cacheable.decorator';
export * from './promise.cache-buster.decorator';
export * from './promise.cacheable.decorator';
export * from './common';
export * from './common/InMemoryStorageStrategy';
//# sourceMappingURL=index.js.map
{
"name": "ngx-cacheable",
"version": "1.4.0-beta.1",
"version": "1.4.0-beta.2",
"description": "Promise/Observable cache decorators",
"module": "./esm5/index.js",
"esm5": "./esm5/index.js",
"es2015": "./esm2015/index.js",
"esm2015": "./esm2015/index.js",
"commonjs": "./commonjs/index.js",
"main": "./index.js",

@@ -16,5 +15,5 @@ "sideEffects": false,

"build": "rm -rf dist && tsc",
"build:esm5": "tsc --p tsconfig.esm5.json",
"build:commonjs": "tsc --p tsconfig.commonjs.json",
"build:esm2015": "tsc --p tsconfig.esm2015.json",
"build:all": "npm run build && npm run build:esm5 && npm run build:esm2015 && cp package.json ./dist && cp README.md ./dist/README.md"
"build:all": "npm run build && npm run build:commonjs && npm run build:esm2015 && cp package.json ./dist && cp README.md ./dist/README.md"
},

@@ -21,0 +20,0 @@ "repository": {

@@ -1,4 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function PCacheBuster(cacheBusterConfig) {
export function PCacheBuster(cacheBusterConfig) {
return function (_target, _propertyKey, propertyDescriptor) {

@@ -25,4 +23,3 @@ var oldMethod = propertyDescriptor.value;

}
exports.PCacheBuster = PCacheBuster;
;
//# sourceMappingURL=promise.cache-buster.decorator.js.map

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var common_1 = require("./common");
exports.promiseGlobalCacheBusterNotifier = new rxjs_1.Subject();
import { empty, merge, Subject } from 'rxjs';
import { DEFAULT_CACHE_RESOLVER, GlobalCacheConfig, DEFAULT_HASHER } from './common';
export var promiseGlobalCacheBusterNotifier = new Subject();
var getResponse = function (oldMethod, cacheKey, cacheConfig, context, cachePairs, parameters, pendingCachePairs, storageStrategy, promiseImplementation) {

@@ -17,5 +15,5 @@ var cacheParameters = cacheConfig.cacheHasher(parameters);

*/
if ((cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge) && _foundCachePair && _foundCachePair.created) {
if ((cacheConfig.maxAge || GlobalCacheConfig.maxAge) && _foundCachePair && _foundCachePair.created) {
if (new Date().getTime() - new Date(_foundCachePair.created).getTime() >
(cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge)) {
(cacheConfig.maxAge || GlobalCacheConfig.maxAge)) {
/**

@@ -27,3 +25,3 @@ * cache duration has expired - remove it from the cachePairs array

}
else if (cacheConfig.slidingExpiration || common_1.GlobalCacheConfig.slidingExpiration) {
else if (cacheConfig.slidingExpiration || GlobalCacheConfig.slidingExpiration) {
/**

@@ -53,6 +51,6 @@ * renew cache duration

cacheConfig.shouldCacheDecider(response)) {
if (!(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) ||
(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) === 1 ||
((cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) &&
(cacheConfig.maxCacheCount || common_1.GlobalCacheConfig.maxCacheCount) < cachePairs.length + 1)) {
if (!(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) ||
(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) === 1 ||
((cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) &&
(cacheConfig.maxCacheCount || GlobalCacheConfig.maxCacheCount) < cachePairs.length + 1)) {
storageStrategy.removeAtIndex(0, cacheKey);

@@ -63,3 +61,3 @@ }

response: response,
created: (cacheConfig.maxAge || common_1.GlobalCacheConfig.maxAge) ? new Date() : null
created: (cacheConfig.maxAge || GlobalCacheConfig.maxAge) ? new Date() : null
}, cacheKey);

@@ -94,3 +92,3 @@ }

};
function PCacheable(cacheConfig) {
export function PCacheable(cacheConfig) {
if (cacheConfig === void 0) { cacheConfig = {}; }

@@ -102,3 +100,3 @@ return function (_target, _propertyKey, propertyDescriptor) {

var storageStrategy_1 = !cacheConfig.storageStrategy
? new common_1.GlobalCacheConfig.storageStrategy()
? new GlobalCacheConfig.storageStrategy()
: new cacheConfig.storageStrategy();

@@ -111,16 +109,16 @@ var pendingCachePairs_1 = [];

*/
rxjs_1.merge(exports.promiseGlobalCacheBusterNotifier.asObservable(), cacheConfig.cacheBusterObserver
merge(promiseGlobalCacheBusterNotifier.asObservable(), cacheConfig.cacheBusterObserver
? cacheConfig.cacheBusterObserver
: rxjs_1.empty()).subscribe(function (_) {
: empty()).subscribe(function (_) {
storageStrategy_1.removeAll(cacheKey);
pendingCachePairs_1.length = 0;
});
var cacheResolver = cacheConfig.cacheResolver || common_1.GlobalCacheConfig.cacheResolver;
var cacheResolver = cacheConfig.cacheResolver || GlobalCacheConfig.cacheResolver;
cacheConfig.cacheResolver = cacheResolver
? cacheResolver
: common_1.DEFAULT_CACHE_RESOLVER;
var cacheHasher = cacheConfig.cacheHasher || common_1.GlobalCacheConfig.cacheHasher;
: DEFAULT_CACHE_RESOLVER;
var cacheHasher = cacheConfig.cacheHasher || GlobalCacheConfig.cacheHasher;
cacheConfig.cacheHasher = cacheHasher
? cacheHasher
: common_1.DEFAULT_HASHER;
: DEFAULT_HASHER;
/* use function instead of an arrow function to keep context of invocation */

@@ -133,5 +131,5 @@ propertyDescriptor.value = function () {

}
var promiseImplementation = typeof common_1.GlobalCacheConfig.promiseImplementation === 'function' && (common_1.GlobalCacheConfig.promiseImplementation !== Promise) ?
common_1.GlobalCacheConfig.promiseImplementation.call(this)
: common_1.GlobalCacheConfig.promiseImplementation;
var promiseImplementation = typeof GlobalCacheConfig.promiseImplementation === 'function' && (GlobalCacheConfig.promiseImplementation !== Promise) ?
GlobalCacheConfig.promiseImplementation.call(this)
: GlobalCacheConfig.promiseImplementation;
var cachePairs = storageStrategy_1.getAll(cacheKey);

@@ -149,4 +147,3 @@ if (!(cachePairs instanceof promiseImplementation)) {

}
exports.PCacheable = PCacheable;
;
//# sourceMappingURL=promise.cacheable.decorator.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Cat = /** @class */ (function () {

@@ -10,3 +8,3 @@ function Cat() {

}());
exports.Cat = Cat;
export { Cat };
//# sourceMappingURL=cat.js.map

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

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -44,21 +43,20 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var cacheable_decorator_1 = require("../cacheable.decorator");
var cacheable_decorator_2 = require("../cacheable.decorator");
var cache_buster_decorator_1 = require("../cache-buster.decorator");
var rxjs_2 = require("rxjs");
var operators_2 = require("rxjs/operators");
var common_1 = require("../common");
var DOMStorageStrategy_1 = require("../common/DOMStorageStrategy");
var InMemoryStorageStrategy_1 = require("../common/InMemoryStorageStrategy");
var cat_1 = require("./cat");
import { combineLatest, forkJoin } from 'rxjs';
import { startWith } from 'rxjs/operators';
import { globalCacheBusterNotifier } from '../cacheable.decorator';
import { Cacheable } from '../cacheable.decorator';
import { CacheBuster } from '../cache-buster.decorator';
import { timer, Subject } from 'rxjs';
import { mapTo } from 'rxjs/operators';
import { GlobalCacheConfig } from '../common';
import { DOMStorageStrategy } from '../common/DOMStorageStrategy';
import { InMemoryStorageStrategy } from '../common/InMemoryStorageStrategy';
import { Cat } from './cat';
var strategies = [
null,
DOMStorageStrategy_1.DOMStorageStrategy
DOMStorageStrategy
];
strategies.forEach(function (s) {
if (s) {
common_1.GlobalCacheConfig.storageStrategy = s;
GlobalCacheConfig.storageStrategy = s;
}

@@ -69,3 +67,3 @@ describe('CacheableDecorator', function () {

beforeEach(function () {
var cacheBusterNotifier = new rxjs_2.Subject();
var cacheBusterNotifier = new Subject();
var Service = /** @class */ (function () {

@@ -75,9 +73,9 @@ function Service() {

Service.prototype.mockServiceCall = function (parameter) {
return rxjs_2.timer(1000).pipe(operators_2.mapTo({ payload: parameter }));
return timer(1000).pipe(mapTo({ payload: parameter }));
};
Service.prototype.mockSaveServiceCall = function () {
return rxjs_2.timer(1000).pipe(operators_2.mapTo('SAVED'));
return timer(1000).pipe(mapTo('SAVED'));
};
Service.prototype.mockServiceCallWithMultipleParameters = function (parameter1, parameter2) {
return rxjs_2.timer(1000).pipe(operators_2.mapTo({ payload: [parameter1, parameter2] }));
return timer(1000).pipe(mapTo({ payload: [parameter1, parameter2] }));
};

@@ -142,12 +140,12 @@ Service.prototype.getData = function (parameter) {

__decorate([
cacheable_decorator_2.Cacheable()
Cacheable()
], Service.prototype, "getData", null);
__decorate([
cacheable_decorator_2.Cacheable()
Cacheable()
], Service.prototype, "getDataWithParamsObj", null);
__decorate([
cacheable_decorator_2.Cacheable()
Cacheable()
], Service.prototype, "getDataAndReturnCachedStream", null);
__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
async: true

@@ -157,3 +155,3 @@ })

__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
maxAge: 7500

@@ -163,3 +161,3 @@ })

__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
maxAge: 7500,

@@ -170,3 +168,3 @@ slidingExpiration: true

__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
maxCacheCount: 5

@@ -176,3 +174,3 @@ })

__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
maxAge: 7500,

@@ -183,3 +181,3 @@ maxCacheCount: 5

__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
maxAge: 7500,

@@ -191,3 +189,3 @@ maxCacheCount: 5,

__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
cacheResolver: function (_oldParameters, newParameters) {

@@ -199,3 +197,3 @@ return newParameters.find(function (param) { return !!param.straightToLastCache; });

__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
cacheHasher: function (_parameters) { return _parameters[0] * 2; },

@@ -208,6 +206,6 @@ cacheResolver: function (oldParameter, newParameter) {

__decorate([
cacheable_decorator_2.Cacheable()
Cacheable()
], Service.prototype, "getWithAComplexType", null);
__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
shouldCacheDecider: function (response) {

@@ -219,3 +217,3 @@ return response.payload === 'test';

__decorate([
cache_buster_decorator_1.CacheBuster({
CacheBuster({
cacheBusterNotifier: cacheBusterNotifier

@@ -225,3 +223,3 @@ })

__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
cacheBusterObserver: cacheBusterNotifier.asObservable()

@@ -231,12 +229,12 @@ })

__decorate([
cacheable_decorator_2.Cacheable()
Cacheable()
], Service.prototype, "getDataWithUndefinedParameter", null);
__decorate([
cacheable_decorator_2.Cacheable()
Cacheable()
], Service.prototype, "getDataWithMultipleUndefinedParameters", null);
__decorate([
cacheable_decorator_2.Cacheable({
Cacheable({
maxAge: 7500,
slidingExpiration: true,
storageStrategy: InMemoryStorageStrategy_1.InMemoryStorageStrategy
storageStrategy: InMemoryStorageStrategy
})

@@ -249,3 +247,3 @@ ], Service.prototype, "getDateWithCustomStorageStrategyProvided", null);

mockServiceCallSpy = spyOn(service, 'mockServiceCall').and.callThrough();
if (common_1.GlobalCacheConfig.storageStrategy === DOMStorageStrategy_1.DOMStorageStrategy) {
if (GlobalCacheConfig.storageStrategy === DOMStorageStrategy) {
localStorage.clear();

@@ -465,3 +463,3 @@ }

*/
var cachedResponseAll = _timedStreamAsyncAwait(rxjs_1.forkJoin(parameters.map(function (param) { return service.getDataWithMaxCacheCount(param); })));
var cachedResponseAll = _timedStreamAsyncAwait(forkJoin(parameters.map(function (param) { return service.getDataWithMaxCacheCount(param); })));
expect(cachedResponseAll).toEqual([

@@ -487,3 +485,3 @@ { payload: 'test1' },

*/
var cachedResponseAll2 = _timedStreamAsyncAwait(rxjs_1.forkJoin(newParameters.map(function (param) { return service.getDataWithMaxCacheCount(param); })), 1000);
var cachedResponseAll2 = _timedStreamAsyncAwait(forkJoin(newParameters.map(function (param) { return service.getDataWithMaxCacheCount(param); })), 1000);
expect(cachedResponseAll2).toEqual([

@@ -525,3 +523,3 @@ { payload: 'test2' },

jasmine.clock().tick(1000);
var cachedResponse2 = _timedStreamAsyncAwait(rxjs_1.forkJoin(parameters.map(function (param) {
var cachedResponse2 = _timedStreamAsyncAwait(forkJoin(parameters.map(function (param) {
return service.getDataWithMaxCacheCountAndExpiration(param);

@@ -575,6 +573,6 @@ })));

jasmine.clock().tick(1);
var cachedResponse = _timedStreamAsyncAwait(rxjs_1.combineLatest(parameters.map(function (param) {
var cachedResponse = _timedStreamAsyncAwait(combineLatest(parameters.map(function (param) {
return service
.getDataWithMaxCacheCountAndSlidingExpiration(param)
.pipe(operators_1.startWith(null));
.pipe(startWith(null));
})));

@@ -628,4 +626,4 @@ /**

it('return cached data up until new parameters are passed WITH a custom GLOBAL resolver and hasher function', function () {
common_1.GlobalCacheConfig.cacheHasher = function (_parameters) { return _parameters[0] + '__wehoo'; };
common_1.GlobalCacheConfig.cacheResolver = function (oldParameter, newParameter) {
GlobalCacheConfig.cacheHasher = function (_parameters) { return _parameters[0] + '__wehoo'; };
GlobalCacheConfig.cacheResolver = function (oldParameter, newParameter) {
return newParameter === 'cached__wehoo';

@@ -637,3 +635,3 @@ };

Service.prototype.mockServiceCall = function (parameter) {
return rxjs_2.timer(1000).pipe(operators_2.mapTo({ payload: parameter }));
return timer(1000).pipe(mapTo({ payload: parameter }));
};

@@ -644,3 +642,3 @@ Service.prototype.getData = function (parameter) {

__decorate([
cacheable_decorator_2.Cacheable()
Cacheable()
], Service.prototype, "getData", null);

@@ -662,7 +660,7 @@ return Service;

expect(mockServiceCallSpy).toHaveBeenCalledTimes(5);
common_1.GlobalCacheConfig.cacheHasher = undefined;
common_1.GlobalCacheConfig.cacheResolver = undefined;
GlobalCacheConfig.cacheHasher = undefined;
GlobalCacheConfig.cacheResolver = undefined;
});
it('should call a function with a complex instance which should not be touched and passed to the original method as it is', function () {
var complexObject = new cat_1.Cat();
var complexObject = new Cat();
complexObject.name = 'Felix';

@@ -759,3 +757,3 @@ var response = _timedStreamAsyncAwait(service.getWithAComplexType(complexObject), 1000);

*/
cacheable_decorator_1.globalCacheBusterNotifier.next();
globalCacheBusterNotifier.next();
_timedStreamAsyncAwait(service.getData('test1'), 1000);

@@ -784,7 +782,7 @@ _timedStreamAsyncAwait(service.getData('test2'), 1000);

it('should work correctly with a custom storage strategy', function () {
var addSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'add').and.callThrough();
var updateAtIndexSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'updateAtIndex').and.callThrough();
var getAllSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'getAll').and.callThrough();
var removeAtIndexSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'removeAtIndex').and.callThrough();
var removeAllSpy = spyOn(InMemoryStorageStrategy_1.InMemoryStorageStrategy.prototype, 'removeAll').and.callThrough();
var addSpy = spyOn(InMemoryStorageStrategy.prototype, 'add').and.callThrough();
var updateAtIndexSpy = spyOn(InMemoryStorageStrategy.prototype, 'updateAtIndex').and.callThrough();
var getAllSpy = spyOn(InMemoryStorageStrategy.prototype, 'getAll').and.callThrough();
var removeAtIndexSpy = spyOn(InMemoryStorageStrategy.prototype, 'removeAtIndex').and.callThrough();
var removeAllSpy = spyOn(InMemoryStorageStrategy.prototype, 'removeAll').and.callThrough();
jasmine.clock().mockDate();

@@ -855,3 +853,3 @@ var asyncFreshData = _timedStreamAsyncAwait(service.getDateWithCustomStorageStrategyProvided('test'), 1000);

*/
cacheable_decorator_1.globalCacheBusterNotifier.next();
globalCacheBusterNotifier.next();
expect(addSpy).toHaveBeenCalledTimes(1);

@@ -864,4 +862,4 @@ expect(updateAtIndexSpy).toHaveBeenCalledTimes(3);

it('use the maxAge and slidingExpiration from the GlobalCacheConfig', function () {
common_1.GlobalCacheConfig.maxAge = 7500;
common_1.GlobalCacheConfig.slidingExpiration = true;
GlobalCacheConfig.maxAge = 7500;
GlobalCacheConfig.slidingExpiration = true;
jasmine.clock().mockDate();

@@ -905,7 +903,7 @@ var asyncFreshData = _timedStreamAsyncAwait(service.getData('test'), 1000);

expect(mockServiceCallSpy).toHaveBeenCalledTimes(2);
common_1.GlobalCacheConfig.maxAge = undefined;
common_1.GlobalCacheConfig.slidingExpiration;
GlobalCacheConfig.maxAge = undefined;
GlobalCacheConfig.slidingExpiration;
});
it('use the maxCacheCount from the GlobalCacheConfig', function () {
common_1.GlobalCacheConfig.maxCacheCount = 5;
GlobalCacheConfig.maxCacheCount = 5;
/**

@@ -929,3 +927,3 @@ * call the same endpoint with 5 different parameters and cache all 5 responses, based on the maxCacheCount parameter

*/
var cachedResponseAll = _timedStreamAsyncAwait(rxjs_1.forkJoin(parameters.map(function (param) { return service.getData(param); })));
var cachedResponseAll = _timedStreamAsyncAwait(forkJoin(parameters.map(function (param) { return service.getData(param); })));
expect(cachedResponseAll).toEqual([

@@ -951,3 +949,3 @@ { payload: 'test1' },

*/
var cachedResponseAll2 = _timedStreamAsyncAwait(rxjs_1.forkJoin(newParameters.map(function (param) { return service.getData(param); })), 1000);
var cachedResponseAll2 = _timedStreamAsyncAwait(forkJoin(newParameters.map(function (param) { return service.getData(param); })), 1000);
expect(cachedResponseAll2).toEqual([

@@ -977,6 +975,6 @@ { payload: 'test2' },

expect(mockServiceCallSpy).toHaveBeenCalledTimes(8);
common_1.GlobalCacheConfig.maxCacheCount = undefined;
GlobalCacheConfig.maxCacheCount = undefined;
});
it('use the maxAge from the GlobalCacheConfig', function () {
common_1.GlobalCacheConfig.maxAge = 10000;
GlobalCacheConfig.maxAge = 10000;
jasmine.clock().mockDate();

@@ -1008,3 +1006,3 @@ var asyncFreshData = _timedStreamAsyncAwait(service.getData('test'), 1000);

expect(asyncFreshDataAfterCacheBust).toEqual({ payload: 'test' });
common_1.GlobalCacheConfig.maxAge = undefined;
GlobalCacheConfig.maxAge = undefined;
});

@@ -1011,0 +1009,0 @@ });

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=service.interface.js.map

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 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 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 not supported yet

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