@convoyr/plugin-cache
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -11,14 +11,14 @@ (function (global, factory) { | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Copyright (c) Microsoft Corporation. | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
@@ -116,4 +116,12 @@ /* global Reflect, Promise */ | ||
var __createBinding = Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
}); | ||
function __exportStar(m, exports) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
} | ||
@@ -199,7 +207,13 @@ | ||
var __setModuleDefault = Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}; | ||
function __importStar(mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result.default = mod; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
@@ -383,8 +397,4 @@ } | ||
var isGetMethodAndJsonResponseType = function (_a) { | ||
var request = _a.request; | ||
return request.method === 'GET' && request.responseType === 'json'; | ||
}; | ||
function createCachePlugin(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.addCacheMetadata, addCacheMetadata = _c === void 0 ? false : _c, _d = _b.storage, storage = _d === void 0 ? new MemoryStorage({ maxSize: 100 }) : _d, _e = _b.shouldHandleRequest, shouldHandleRequest = _e === void 0 ? isGetMethodAndJsonResponseType : _e; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.addCacheMetadata, addCacheMetadata = _c === void 0 ? false : _c, _d = _b.storage, storage = _d === void 0 ? new MemoryStorage({ maxSize: 100 }) : _d, _e = _b.shouldHandleRequest, shouldHandleRequest = _e === void 0 ? core.and(core.matchMethod('GET'), core.matchResponseType('json')) : _e; | ||
return { | ||
@@ -391,0 +401,0 @@ shouldHandleRequest: shouldHandleRequest, |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@convoyr/core"),require("rxjs"),require("rxjs/operators"),require("buffer"),require("bytes"),require("lru-cache")):"function"==typeof define&&define.amd?define("@convoyr/plugin-cache",["exports","@convoyr/core","rxjs","rxjs/operators","buffer","bytes","lru-cache"],t):t(((e=e||self).convoyr=e.convoyr||{},e.convoyr["plugin-cache"]={}),e["@convoyr/core"],e.rxjs,e.rxjs.operators,e.buffer,e.bytes,e.LRU)}(this,(function(e,t,r,a,o,n,u){"use strict";n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,u=u&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u;var i=function(){return(i=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function s(e){return{createdAt:new Date(e.createdAt),response:e.response}}var c=function(){function e(e){var t=e.addCacheMetadata,r=e.storage;this._shouldAddCacheMetadata=t,this._storage=r}return e.prototype.handle=function(e){var t=this,o=e.request,n=e.next,u=this._shouldAddCacheMetadata,i=n.handle({request:o}).pipe(a.mergeMap((function(e){return r.merge(r.of(e),t._store(o,e).pipe(a.switchMapTo(r.EMPTY)))})),a.shareReplay({refCount:!0,bufferSize:1})),s=r.defer((function(){return t._load(o)})).pipe(a.map((function(e){return t._createResponseWithOptionalMetadata({response:e.response,shouldAddCacheMetadata:u,cacheMetadata:(r=e,{createdAt:r.createdAt,isFromCache:!0})});var r})),a.takeUntil(i));return r.merge(i.pipe(a.map((function(e){return t._createResponseWithOptionalMetadata({response:e,shouldAddCacheMetadata:u,cacheMetadata:{isFromCache:!1}})}))),s)},e.prototype._store=function(e,t){var a=this;return r.defer((function(){var r=a._serializeCacheKey(e),o=s({createdAt:new Date,response:t}),n=JSON.stringify(o);return a._storage.set(r,n)}))},e.prototype._load=function(e){return this._storage.get(this._serializeCacheKey(e)).pipe(a.mergeMap((function(e){if(null==e)return r.EMPTY;var t=s(JSON.parse(e));return r.of(t)})))},e.prototype._serializeCacheKey=function(e){var t=e.params,r=Object.keys(t).length>0;return JSON.stringify({u:e.url,p:r?e.params:void 0})},e.prototype._createResponseWithOptionalMetadata=function(e){var r=e.response,a=e.cacheMetadata,o=e.shouldAddCacheMetadata?{cacheMetadata:a,data:r.body}:r.body;return t.createResponse(i(i({},r),{body:o}))},e}(),d=function(){function e(e){var t=(void 0===e?{}:e).maxSize,r=void 0===t?100:t;this._lruCache=this._createLru({maxSize:r})}return e.prototype.get=function(e){var t=this;return r.defer((function(){return r.of(t._lruCache.get(e))}))},e.prototype.set=function(e,t){var a=this;return r.defer((function(){return a._lruCache.set(e,t),r.EMPTY}))},e.prototype.delete=function(e){var t=this;return r.defer((function(){return t._lruCache.del(e),r.EMPTY}))},e.prototype._createLru=function(e){var t=e.maxSize;return new u(this._createLruOptions({maxSize:t}))},e.prototype._createLruOptions=function(e){var t=e.maxSize;return"string"==typeof t?{max:n(t),length:function(e){return o.Buffer.from(e).length}}:{max:t}},e}(),p=function(e){var t=e.request;return"GET"===t.method&&"json"===t.responseType};e.MemoryStorage=d,e.createCachePlugin=function(e){var t=void 0===e?{}:e,r=t.addCacheMetadata,a=void 0!==r&&r,o=t.storage,n=void 0===o?new d({maxSize:100}):o,u=t.shouldHandleRequest;return{shouldHandleRequest:void 0===u?p:u,handler:new c({addCacheMetadata:a,storage:n})}},e.Éľa=c,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@convoyr/core"),require("rxjs"),require("rxjs/operators"),require("buffer"),require("bytes"),require("lru-cache")):"function"==typeof define&&define.amd?define("@convoyr/plugin-cache",["exports","@convoyr/core","rxjs","rxjs/operators","buffer","bytes","lru-cache"],t):t(((e=e||self).convoyr=e.convoyr||{},e.convoyr["plugin-cache"]={}),e["@convoyr/core"],e.rxjs,e.rxjs.operators,e.buffer,e.bytes,e.LRU)}(this,(function(e,t,r,a,o,n,c){"use strict";n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,c=c&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c;var i=function(){return(i=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};Object.create;Object.create;function u(e){return{createdAt:new Date(e.createdAt),response:e.response}}var s=function(){function e(e){var t=e.addCacheMetadata,r=e.storage;this._shouldAddCacheMetadata=t,this._storage=r}return e.prototype.handle=function(e){var t=this,o=e.request,n=e.next,c=this._shouldAddCacheMetadata,i=n.handle({request:o}).pipe(a.mergeMap((function(e){return r.merge(r.of(e),t._store(o,e).pipe(a.switchMapTo(r.EMPTY)))})),a.shareReplay({refCount:!0,bufferSize:1})),u=r.defer((function(){return t._load(o)})).pipe(a.map((function(e){return t._createResponseWithOptionalMetadata({response:e.response,shouldAddCacheMetadata:c,cacheMetadata:(r=e,{createdAt:r.createdAt,isFromCache:!0})});var r})),a.takeUntil(i));return r.merge(i.pipe(a.map((function(e){return t._createResponseWithOptionalMetadata({response:e,shouldAddCacheMetadata:c,cacheMetadata:{isFromCache:!1}})}))),u)},e.prototype._store=function(e,t){var a=this;return r.defer((function(){var r=a._serializeCacheKey(e),o=u({createdAt:new Date,response:t}),n=JSON.stringify(o);return a._storage.set(r,n)}))},e.prototype._load=function(e){return this._storage.get(this._serializeCacheKey(e)).pipe(a.mergeMap((function(e){if(null==e)return r.EMPTY;var t=u(JSON.parse(e));return r.of(t)})))},e.prototype._serializeCacheKey=function(e){var t=e.params,r=Object.keys(t).length>0;return JSON.stringify({u:e.url,p:r?e.params:void 0})},e.prototype._createResponseWithOptionalMetadata=function(e){var r=e.response,a=e.cacheMetadata,o=e.shouldAddCacheMetadata?{cacheMetadata:a,data:r.body}:r.body;return t.createResponse(i(i({},r),{body:o}))},e}(),d=function(){function e(e){var t=(void 0===e?{}:e).maxSize,r=void 0===t?100:t;this._lruCache=this._createLru({maxSize:r})}return e.prototype.get=function(e){var t=this;return r.defer((function(){return r.of(t._lruCache.get(e))}))},e.prototype.set=function(e,t){var a=this;return r.defer((function(){return a._lruCache.set(e,t),r.EMPTY}))},e.prototype.delete=function(e){var t=this;return r.defer((function(){return t._lruCache.del(e),r.EMPTY}))},e.prototype._createLru=function(e){var t=e.maxSize;return new c(this._createLruOptions({maxSize:t}))},e.prototype._createLruOptions=function(e){var t=e.maxSize;return"string"==typeof t?{max:n(t),length:function(e){return o.Buffer.from(e).length}}:{max:t}},e}();e.MemoryStorage=d,e.createCachePlugin=function(e){var r=void 0===e?{}:e,a=r.addCacheMetadata,o=void 0!==a&&a,n=r.storage,c=void 0===n?new d({maxSize:100}):n,i=r.shouldHandleRequest;return{shouldHandleRequest:void 0===i?t.and(t.matchMethod("GET"),t.matchResponseType("json")):i,handler:new s({addCacheMetadata:o,storage:c})}},e.Éľa=s,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=convoyr-plugin-cache.umd.min.js.map |
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.1.0](https://github.com/jscutlery/convoyr/compare/v3.0.0...v3.1.0) (2020-05-20) | ||
**Note:** Version bump only for package @convoyr/plugin-cache | ||
# [3.0.0](https://github.com/jscutlery/convoyr/compare/v2.2.0...v3.0.0) (2020-04-24) | ||
@@ -8,0 +16,0 @@ |
@@ -0,7 +1,5 @@ | ||
import { and, matchMethod, matchResponseType, } from '@convoyr/core'; | ||
import { CacheHandler } from './cache-handler'; | ||
import { MemoryStorage } from './storages/memory-storage'; | ||
export const isGetMethodAndJsonResponseType = ({ request, }) => { | ||
return request.method === 'GET' && request.responseType === 'json'; | ||
}; | ||
export function createCachePlugin({ addCacheMetadata = false, storage = new MemoryStorage({ maxSize: 100 }), shouldHandleRequest = isGetMethodAndJsonResponseType, } = {}) { | ||
export function createCachePlugin({ addCacheMetadata = false, storage = new MemoryStorage({ maxSize: 100 }), shouldHandleRequest = and(matchMethod('GET'), matchResponseType('json')), } = {}) { | ||
return { | ||
@@ -12,2 +10,2 @@ shouldHandleRequest, | ||
} | ||
//# sourceM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WdlJztcblxuZXhwb3J0IGludGVyZmFjZSBDYWNoZVBsdWdpbk9wdGlvbnMgZXh0ZW5kcyBIYW5kbGVyT3B0aW9ucyB7XG4gIHNob3VsZEhhbmRsZVJlcXVlc3Q6IFJlcXVlc3RDb25kaXRpb247XG59XG5cbmV4cG9ydCBmdW5jdGlvbiBjcmVhdGVDYWNoZVBsdWdpbih7XG4gIGFkZENhY2hlTWV0YWRhdGEgPSBmYWxzZSxcbiAgc3RvcmFnZSA9IG5ldyBNZW1vcnlTdG9yYWdlKHsgbWF4U2l6ZTogMTAwIH0pLFxuICBzaG91bGRIYW5kbGVSZXF1ZXN0ID0gYW5kKG1hdGNoTWV0aG9kKCdHRVQnKSwgbWF0Y2hSZXNwb25zZVR5cGUoJ2pzb24nKSksXG59OiBQYXJ0aWFsPENhY2hlUGx1Z2luT3B0aW9ucz4gPSB7fSkge1xuICByZXR1cm4ge1xuICAgIHNob3VsZEhhbmRsZVJlcXVlc3QsXG4gICAgaGFuZGxlcjogbmV3IENhY2hlSGFuZGxlcih7IGFkZENhY2hlTWV0YWRhdGEsIHN0b3JhZ2UgfSksXG4gIH07XG59XG4iXX0= |
@@ -0,9 +1,6 @@ | ||
import { and, matchMethod, matchResponseType, } from '@convoyr/core'; | ||
import { CacheHandler } from './cache-handler'; | ||
import { MemoryStorage } from './storages/memory-storage'; | ||
export var isGetMethodAndJsonResponseType = function (_a) { | ||
var request = _a.request; | ||
return request.method === 'GET' && request.responseType === 'json'; | ||
}; | ||
export function createCachePlugin(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.addCacheMetadata, addCacheMetadata = _c === void 0 ? false : _c, _d = _b.storage, storage = _d === void 0 ? new MemoryStorage({ maxSize: 100 }) : _d, _e = _b.shouldHandleRequest, shouldHandleRequest = _e === void 0 ? isGetMethodAndJsonResponseType : _e; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.addCacheMetadata, addCacheMetadata = _c === void 0 ? false : _c, _d = _b.storage, storage = _d === void 0 ? new MemoryStorage({ maxSize: 100 }) : _d, _e = _b.shouldHandleRequest, shouldHandleRequest = _e === void 0 ? and(matchMethod('GET'), matchResponseType('json')) : _e; | ||
return { | ||
@@ -14,2 +11,2 @@ shouldHandleRequest: shouldHandleRequest, | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLWNhY2hlLXBsdWdpbi5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0Bjb252b3lyL3BsdWdpbi1jYWNoZS8iLCJzb3VyY2VzIjpbImxpYi9jcmVhdGUtY2FjaGUtcGx1Z2luLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sRUFBRSxZQUFZLEVBQWtCLE1BQU0saUJBQWlCLENBQUM7QUFDL0QsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBTTFELE1BQU0sQ0FBQyxJQUFNLDhCQUE4QixHQUFHLFVBQUMsRUFJOUM7UUFIQyxvQkFBTztJQUlQLE9BQU8sT0FBTyxDQUFDLE1BQU0sS0FBSyxLQUFLLElBQUksT0FBTyxDQUFDLFlBQVksS0FBSyxNQUFNLENBQUM7QUFDckUsQ0FBQyxDQUFDO0FBRUYsTUFBTSxVQUFVLGlCQUFpQixDQUFDLEVBSUM7UUFKRCw0QkFJQyxFQUhqQyx3QkFBd0IsRUFBeEIsNkNBQXdCLEVBQ3hCLGVBQTZDLEVBQTdDLGtFQUE2QyxFQUM3QywyQkFBb0QsRUFBcEQseUVBQW9EO0lBRXBELE9BQU87UUFDTCxtQkFBbUIscUJBQUE7UUFDbkIsT0FBTyxFQUFFLElBQUksWUFBWSxDQUFDLEVBQUUsZ0JBQWdCLGtCQUFBLEVBQUUsT0FBTyxTQUFBLEVBQUUsQ0FBQztLQUN6RCxDQUFDO0FBQ0osQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IFJlcXVlc3RDb25kaX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lIH0gZnJvbSAnLi9zdG9yYWdlcy9tZW1vcnktc3RvcmFnZSc7XG5cbmV4cG9ydCBpbnRlcmZhY2UgQ2FjaGVQbHVnaW5PcHRpb25zIGV4dGVuZHMgSGFuZGxlck9wdGlvbnMge1xuICBzaG91bGRIYW5kbGVSZXF1ZXN0OiBSZXF1ZXN0Q29uZGl0aW9uO1xufVxuXG5leHBvcnQgZnVuY3Rpb24gY3JlYXRlQ2FjaGVQbHVnaW4oe1xuICBhZGRDYWNoZU1ldGFkYXRhID0gZmFsc2UsXG4gIHN0b3JhZ2UgPSBuZXcgTWVtb3J5U3RvcmFnZSh7IG1heFNpemU6IDEwMCB9KSxcbiAgc2hvdWxkSGFuZGxlUmVxdWVzdCA9IGFuZChtYXRjaE1ldGhvZCgnR0VUJyksIG1hdGNoUmVzcG9uc2VUeXBlKCdqc29uJykpLFxufTogUGFydGlhbDxDYWNoZVBsdWdpbk9wdGlvbnM+ID0ge30pIHtcbiAgcmV0dXJuIHtcbiAgICBzaG91bGRIYW5kbGVSZXF1ZXN0LFxuICAgIGhhbmRsZXI6IG5ldyBDYWNoZUhhbmRsZXIoeyBhZGRDYWNoZU1ldGFkYXRhLCBzdG9yYWdlIH0pLFxuICB9O1xufVxuIl19 |
@@ -1,2 +0,2 @@ | ||
import { createResponse } from '@convoyr/core'; | ||
import { createResponse, and, matchMethod, matchResponseType } from '@convoyr/core'; | ||
import { merge, of, EMPTY, defer } from 'rxjs'; | ||
@@ -146,6 +146,3 @@ import { mergeMap, switchMapTo, shareReplay, map, takeUntil } from 'rxjs/operators'; | ||
const isGetMethodAndJsonResponseType = ({ request, }) => { | ||
return request.method === 'GET' && request.responseType === 'json'; | ||
}; | ||
function createCachePlugin({ addCacheMetadata = false, storage = new MemoryStorage({ maxSize: 100 }), shouldHandleRequest = isGetMethodAndJsonResponseType, } = {}) { | ||
function createCachePlugin({ addCacheMetadata = false, storage = new MemoryStorage({ maxSize: 100 }), shouldHandleRequest = and(matchMethod('GET'), matchResponseType('json')), } = {}) { | ||
return { | ||
@@ -152,0 +149,0 @@ shouldHandleRequest, |
@@ -0,3 +1,3 @@ | ||
import { createResponse, and, matchMethod, matchResponseType } from '@convoyr/core'; | ||
import { __assign } from 'tslib'; | ||
import { createResponse } from '@convoyr/core'; | ||
import { merge, of, EMPTY, defer } from 'rxjs'; | ||
@@ -165,8 +165,4 @@ import { mergeMap, switchMapTo, shareReplay, map, takeUntil } from 'rxjs/operators'; | ||
var isGetMethodAndJsonResponseType = function (_a) { | ||
var request = _a.request; | ||
return request.method === 'GET' && request.responseType === 'json'; | ||
}; | ||
function createCachePlugin(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.addCacheMetadata, addCacheMetadata = _c === void 0 ? false : _c, _d = _b.storage, storage = _d === void 0 ? new MemoryStorage({ maxSize: 100 }) : _d, _e = _b.shouldHandleRequest, shouldHandleRequest = _e === void 0 ? isGetMethodAndJsonResponseType : _e; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.addCacheMetadata, addCacheMetadata = _c === void 0 ? false : _c, _d = _b.storage, storage = _d === void 0 ? new MemoryStorage({ maxSize: 100 }) : _d, _e = _b.shouldHandleRequest, shouldHandleRequest = _e === void 0 ? and(matchMethod('GET'), matchResponseType('json')) : _e; | ||
return { | ||
@@ -173,0 +169,0 @@ shouldHandleRequest: shouldHandleRequest, |
@@ -1,2 +0,2 @@ | ||
import { RequestCondition, ConvoyrRequest } from '@convoyr/core'; | ||
import { RequestCondition } from '@convoyr/core'; | ||
import { CacheHandler, HandlerOptions } from './cache-handler'; | ||
@@ -6,5 +6,2 @@ export interface CachePluginOptions extends HandlerOptions { | ||
} | ||
export declare const isGetMethodAndJsonResponseType: ({ request, }: { | ||
request: ConvoyrRequest<unknown>; | ||
}) => boolean; | ||
export declare function createCachePlugin({ addCacheMetadata, storage, shouldHandleRequest, }?: Partial<CachePluginOptions>): { | ||
@@ -11,0 +8,0 @@ shouldHandleRequest: RequestCondition; |
{ | ||
"name": "@convoyr/plugin-cache", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -8,5 +8,4 @@ "private": false, | ||
"peerDependencies": { | ||
"@convoyr/core": "^2.0.0", | ||
"rxjs": "^6.5.4", | ||
"tslib": "^1.10.0" | ||
"@convoyr/core": ">= 3.0.0", | ||
"rxjs": "^6.5.4" | ||
}, | ||
@@ -16,5 +15,6 @@ "dependencies": { | ||
"bytes": "^3.1.0", | ||
"lru-cache": "^5.1.1" | ||
"lru-cache": "^5.1.1", | ||
"tslib": "^1.10.0" | ||
}, | ||
"gitHead": "0adb173e1e6bb447ca5a492f6d9c78b22a6c6fc5", | ||
"gitHead": "8094232cb8ff5981b0b63706a5eb7f548a73efb4", | ||
"main": "bundles/convoyr-plugin-cache.umd.js", | ||
@@ -21,0 +21,0 @@ "module": "fesm5/convoyr-plugin-cache.js", |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
190512
0
0
1133
+ Addedtslib@^1.10.0
+ Added@convoyr/core@4.0.0(transitive)
- Removed@convoyr/core@2.2.0(transitive)