prisma-redis-middleware
Advanced tools
Comparing version 4.7.0 to 4.8.0
import type { CreatePrismaRedisCache, Middleware } from "./types"; | ||
export declare const createPrismaRedisCache: ({ models, onDedupe, onError, onHit, onMiss, storage, cacheTime, excludeModels, excludeMethods, }: CreatePrismaRedisCache) => Middleware<any>; | ||
export declare const createPrismaRedisCache: ({ models, onDedupe, onError, onHit, onMiss, storage, cacheTime, excludeModels, excludeMethods, transformer, }: CreatePrismaRedisCache) => Middleware<any>; |
@@ -355,3 +355,4 @@ 'use strict'; | ||
_ref$excludeMethods = _ref.excludeMethods, | ||
excludeMethods = _ref$excludeMethods === void 0 ? [] : _ref$excludeMethods; | ||
excludeMethods = _ref$excludeMethods === void 0 ? [] : _ref$excludeMethods, | ||
transformer = _ref.transformer; | ||
// Default options for "async-cache-dedupe" | ||
@@ -364,3 +365,4 @@ var cacheOptions = { | ||
storage: storage, | ||
ttl: cacheTime | ||
ttl: cacheTime, | ||
transformer: transformer | ||
}; | ||
@@ -367,0 +369,0 @@ var cache = asyncCacheDedupe.createCache(cacheOptions); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("async-cache-dedupe");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var i=Object.create((e&&e.prototype instanceof d?e:d).prototype),a=new O(n||[]);return o(i,"_invoke",{value:L(t,r,a)}),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var h={};function d(){}function p(){}function v(){}var y={};l(y,a,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(j([])));g&&g!==r&&n.call(g,a)&&(y=g);var w=v.prototype=d.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var r;o(this,"_invoke",{value:function(o,i){function a(){return new e((function(r,a){!function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var l=c.arg,s=l.value;return s&&"object"==typeof s&&n.call(s,"__await")?e.resolve(s.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(s).then((function(t){l.value=t,a(l)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}(o,i,r,a)}))}return r=r?r.then(a,a):a()}})}function L(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=E(a,r);if(u){if(u===h)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function E(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,h;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function j(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return p.prototype=v,o(w,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:p,configurable:!0}),p.displayName=l(v,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,l(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(b.prototype),l(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(w),l(w,c,"Generator"),l(w,a,(function(){return this})),l(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=j,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),_(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;_(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function r(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function u(t){r(a,o,i,u,c,"next",t)}function c(t){r(a,o,i,u,c,"throw",t)}u(void 0)}))}}var o=["findUnique","findFirst","findMany","count","aggregate","groupBy","findRaw","aggregateRaw"],i=["create","createMany","update","updateMany","upsert","delete","deleteMany","executeRawUnsafe"];exports.createPrismaRedisCache=function(r){var a=r.models,u=r.cacheTime,c=r.excludeModels,l=void 0===c?[]:c,s=r.excludeMethods,f=void 0===s?[]:s,h={onDedupe:r.onDedupe,onError:r.onError,onHit:r.onHit,onMiss:r.onMiss,storage:r.storage,ttl:void 0===u?0:u},d=t.createCache(h);return function(){var t=n(e().mark((function t(r,u){var c,s,p,v,y,m;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(s=function(){var t=n(e().mark((function t(r){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",u(r));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),null!=(p=o.filter((function(t){return f.includes(t)})))&&p.includes(r.action)||(null==a||a.forEach((function(t){var o=t.model,i=t.cacheTime,a=t.cacheKey,u=t.excludeMethods;d[o]||o!==r.model||null!=l&&l.includes(r.model)||null!=u&&u.includes(r.action)||d.define(o,{references:function(t,e){return[(a||t.params.model)+"~"+e]},ttl:i||h.ttl},function(){var t=n(e().mark((function t(r){var n,o;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.cb,o=r.params,t.next=3,n(o);case 3:return t.abrupt("return",c=t.sent);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())})),y=null==a?void 0:a.find((function(t){var e=t.excludeMethods;return t.model===r.model&&(null==e?void 0:e.length)})),d[r.model]||null!=l&&l.includes(r.model)||null!=y&&null!=(v=y.excludeMethods)&&v.includes(r.action)||d.define(r.model,{references:function(t,e){return[t.params.model+"~"+e]}},function(){var t=n(e().mark((function t(r){var n,o;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.cb,o=r.params,t.next=3,n(o);case 3:return t.abrupt("return",c=t.sent);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())),m=d[r.model],null!=l&&l.includes(r.model)||null!=p&&p.includes(r.action)||null!=i&&i.includes(r.action)||"function"!=typeof m){t.next=19;break}return t.prev=5,t.next=8,m({cb:s,params:r});case 8:c=t.sent,t.next=17;break;case 11:return t.prev=11,t.t0=t.catch(5),t.next=15,s(r);case 15:c=t.sent,console.error(t.t0);case 17:t.next=27;break;case 19:return t.next=21,s(r);case 21:if(c=t.sent,!i.includes(r.action)){t.next=27;break}return t.next=25,d.invalidateAll("*"+r.model+"~*");case 25:return t.next=27,Promise.all((a||[]).filter((function(t){return t.model===r.model})).map(function(){var t=n(e().mark((function t(r){var o;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(o=r.invalidateRelated)){t.next=4;break}return t.next=4,Promise.all(o.map(function(){var t=n(e().mark((function t(r){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",d.invalidateAll("*"+r+"~*"));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 27:return t.abrupt("return",c);case 28:case"end":return t.stop()}}),t,null,[[5,11]])})));return function(e,r){return t.apply(this,arguments)}}()}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("async-cache-dedupe");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var i=Object.create((e&&e.prototype instanceof d?e:d).prototype),a=new O(n||[]);return o(i,"_invoke",{value:L(t,r,a)}),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var h={};function d(){}function p(){}function v(){}var y={};l(y,a,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(j([])));g&&g!==r&&n.call(g,a)&&(y=g);var w=v.prototype=d.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var r;o(this,"_invoke",{value:function(o,i){function a(){return new e((function(r,a){!function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var l=c.arg,s=l.value;return s&&"object"==typeof s&&n.call(s,"__await")?e.resolve(s.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(s).then((function(t){l.value=t,a(l)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}(o,i,r,a)}))}return r=r?r.then(a,a):a()}})}function L(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=E(a,r);if(u){if(u===h)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function E(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,h;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function j(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return p.prototype=v,o(w,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:p,configurable:!0}),p.displayName=l(v,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,l(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(b.prototype),l(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(w),l(w,c,"Generator"),l(w,a,(function(){return this})),l(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=j,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),_(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;_(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function r(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function u(t){r(a,o,i,u,c,"next",t)}function c(t){r(a,o,i,u,c,"throw",t)}u(void 0)}))}}var o=["findUnique","findFirst","findMany","count","aggregate","groupBy","findRaw","aggregateRaw"],i=["create","createMany","update","updateMany","upsert","delete","deleteMany","executeRawUnsafe"];exports.createPrismaRedisCache=function(r){var a=r.models,u=r.cacheTime,c=r.excludeModels,l=void 0===c?[]:c,s=r.excludeMethods,f=void 0===s?[]:s,h={onDedupe:r.onDedupe,onError:r.onError,onHit:r.onHit,onMiss:r.onMiss,storage:r.storage,ttl:void 0===u?0:u,transformer:r.transformer},d=t.createCache(h);return function(){var t=n(e().mark((function t(r,u){var c,s,p,v,y,m;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(s=function(){var t=n(e().mark((function t(r){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",u(r));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),null!=(p=o.filter((function(t){return f.includes(t)})))&&p.includes(r.action)||(null==a||a.forEach((function(t){var o=t.model,i=t.cacheTime,a=t.cacheKey,u=t.excludeMethods;d[o]||o!==r.model||null!=l&&l.includes(r.model)||null!=u&&u.includes(r.action)||d.define(o,{references:function(t,e){return[(a||t.params.model)+"~"+e]},ttl:i||h.ttl},function(){var t=n(e().mark((function t(r){var n,o;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.cb,o=r.params,t.next=3,n(o);case 3:return t.abrupt("return",c=t.sent);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())})),y=null==a?void 0:a.find((function(t){var e=t.excludeMethods;return t.model===r.model&&(null==e?void 0:e.length)})),d[r.model]||null!=l&&l.includes(r.model)||null!=y&&null!=(v=y.excludeMethods)&&v.includes(r.action)||d.define(r.model,{references:function(t,e){return[t.params.model+"~"+e]}},function(){var t=n(e().mark((function t(r){var n,o;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.cb,o=r.params,t.next=3,n(o);case 3:return t.abrupt("return",c=t.sent);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())),m=d[r.model],null!=l&&l.includes(r.model)||null!=p&&p.includes(r.action)||null!=i&&i.includes(r.action)||"function"!=typeof m){t.next=19;break}return t.prev=5,t.next=8,m({cb:s,params:r});case 8:c=t.sent,t.next=17;break;case 11:return t.prev=11,t.t0=t.catch(5),t.next=15,s(r);case 15:c=t.sent,console.error(t.t0);case 17:t.next=27;break;case 19:return t.next=21,s(r);case 21:if(c=t.sent,!i.includes(r.action)){t.next=27;break}return t.next=25,d.invalidateAll("*"+r.model+"~*");case 25:return t.next=27,Promise.all((a||[]).filter((function(t){return t.model===r.model})).map(function(){var t=n(e().mark((function t(r){var o;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(o=r.invalidateRelated)){t.next=4;break}return t.next=4,Promise.all(o.map(function(){var t=n(e().mark((function t(r){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",d.invalidateAll("*"+r+"~*"));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 27:return t.abrupt("return",c);case 28:case"end":return t.stop()}}),t,null,[[5,11]])})));return function(e,r){return t.apply(this,arguments)}}()}; | ||
//# sourceMappingURL=prisma-redis-middleware.cjs.production.min.js.map |
@@ -351,3 +351,4 @@ import { createCache } from 'async-cache-dedupe'; | ||
_ref$excludeMethods = _ref.excludeMethods, | ||
excludeMethods = _ref$excludeMethods === void 0 ? [] : _ref$excludeMethods; | ||
excludeMethods = _ref$excludeMethods === void 0 ? [] : _ref$excludeMethods, | ||
transformer = _ref.transformer; | ||
// Default options for "async-cache-dedupe" | ||
@@ -360,3 +361,4 @@ var cacheOptions = { | ||
storage: storage, | ||
ttl: cacheTime | ||
ttl: cacheTime, | ||
transformer: transformer | ||
}; | ||
@@ -363,0 +365,0 @@ var cache = createCache(cacheOptions); |
@@ -51,2 +51,6 @@ import type Redis from "ioredis"; | ||
onDedupe?: (key: string) => void; | ||
transformer?: { | ||
serialize: (data: any) => any; | ||
deserialize: (data: any) => any; | ||
}; | ||
}; |
{ | ||
"name": "prisma-redis-middleware", | ||
"author": "A-J Roos <asjas@hey.com>", | ||
"version": "4.7.0", | ||
"version": "4.8.0", | ||
"description": "Prisma Middleware for caching results of queries in Redis", | ||
@@ -32,3 +32,3 @@ "license": "Hippocratic-3.0", | ||
"dependencies": { | ||
"async-cache-dedupe": "1.10.2", | ||
"async-cache-dedupe": "1.12.0", | ||
"ioredis": "5.3.2" | ||
@@ -38,6 +38,6 @@ }, | ||
"@ianvs/prettier-plugin-sort-imports": "3.7.2", | ||
"@prisma/client": "4.13.0", | ||
"@prisma/client": "4.14.1", | ||
"@size-limit/preset-small-lib": "8.2.4", | ||
"@types/ioredis-mock": "8.2.1", | ||
"@vitest/coverage-c8": "0.30.1", | ||
"@types/ioredis-mock": "8.2.2", | ||
"@vitest/coverage-c8": "0.31.1", | ||
"c8": "7.13.0", | ||
@@ -49,8 +49,8 @@ "husky": "8.0.3", | ||
"prettier": "2.8.8", | ||
"rimraf": "5.0.0", | ||
"rimraf": "5.0.1", | ||
"size-limit": "8.2.4", | ||
"tsdx": "0.14.1", | ||
"tslib": "2.5.0", | ||
"tslib": "2.5.2", | ||
"typescript": "5.0.4", | ||
"vitest": "0.30.1" | ||
"vitest": "0.31.1" | ||
}, | ||
@@ -57,0 +57,0 @@ "husky": { |
@@ -203,2 +203,23 @@ # `prisma-redis-middleware` | ||
- `transformer`: (optional) the transformer to used to serialize and deserialize the cache entries. It must be an object | ||
with the following methods: | ||
- `serialize`: a function that receives the result of the original function and returns a serializable object. | ||
- `deserialize`: a function that receives the serialized object and returns the original result. | ||
- Default is `undefined`, so the default transformer is used. | ||
Example | ||
```js | ||
import superjson from "superjson"; | ||
createPrismaRedisCache({ | ||
transformer: { | ||
serialize: (result) => superjson.serialize(result), | ||
deserialize: (serialized) => superjson.deserialize(serialized), | ||
}, | ||
}); | ||
``` | ||
## Debugging | ||
@@ -205,0 +226,0 @@ |
@@ -27,2 +27,3 @@ import { createCache } from "async-cache-dedupe"; | ||
excludeMethods = [], | ||
transformer, | ||
}: CreatePrismaRedisCache) => { | ||
@@ -37,2 +38,3 @@ // Default options for "async-cache-dedupe" | ||
ttl: cacheTime, | ||
transformer, | ||
}; | ||
@@ -39,0 +41,0 @@ |
@@ -88,2 +88,6 @@ import type Redis from "ioredis"; | ||
onDedupe?: (key: string) => void; | ||
transformer?: { | ||
serialize: (data: any) => any; | ||
deserialize: (data: any) => any; | ||
}; | ||
}; |
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
146710
1516
232
+ Addedasync-cache-dedupe@1.12.0(transitive)
- Removedasync-cache-dedupe@1.10.2(transitive)
Updatedasync-cache-dedupe@1.12.0