prisma-redis-middleware
Advanced tools
Comparing version 2.0.0-0 to 2.0.0-1
import type { CreatePrismaRedisCache, MiddlewareParams } from "./types"; | ||
export declare const createPrismaRedisCache: ({ models, defaultCacheTime, storage, excludeCacheModels, defaultExcludeCacheMethods, onError, onHit, onMiss, onDedupe, }: CreatePrismaRedisCache) => (params: MiddlewareParams, next: (params: any) => Promise<any>) => Promise<Record<string, unknown>>; | ||
export declare const createPrismaRedisCache: ({ models, defaultCacheTime, storage, excludeCacheModels, defaultExcludeCacheMethods, onError, onHit, onMiss, onDedupe, }: CreatePrismaRedisCache) => (params: MiddlewareParams, next: (params: MiddlewareParams) => Promise<any>) => Promise<Record<string, unknown>>; |
@@ -853,4 +853,4 @@ 'use strict'; | ||
ttl: cacheTime || cacheOptions.ttl, | ||
references: function references(_args, key, result) { | ||
return result ? [model + "~" + params.action + "~" + key] : null; | ||
references: function references(args, key, result) { | ||
return result ? [args.model + "~" + key] : null; | ||
} | ||
@@ -887,4 +887,4 @@ }, /*#__PURE__*/function () { | ||
cache.define(params.model, { | ||
references: function references(_args, key, result) { | ||
return result ? [params.model + "~" + params.action + "~" + key] : null; | ||
references: function references(args, key, result) { | ||
return result ? [args.model + "~" + key] : null; | ||
} | ||
@@ -930,3 +930,3 @@ }, /*#__PURE__*/function () { | ||
_context3.next = 6; | ||
return cacheFunction(params.args); | ||
return cacheFunction(params); | ||
@@ -942,3 +942,3 @@ case 6: | ||
_context3.next = 13; | ||
return next(params.args); | ||
return next(params); | ||
@@ -955,3 +955,3 @@ case 13: | ||
_context3.next = 19; | ||
return next(params.args); | ||
return next(params); | ||
@@ -958,0 +958,0 @@ case 19: |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("async-cache-dedupe");function e(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}}var n,o=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new E(n||[]);return o._invoke=function(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 c=x(a,r);if(c){if(c===l)continue;return c}}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 u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function f(){}function h(){}function p(){}var d={};c(d,o,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(_([])));y&&y!==e&&r.call(y,o)&&(d=y);var g=p.prototype=f.prototype=Object.create(d);function m(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function b(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 L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function _(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return h.prototype=p,c(g,"constructor",p),c(p,"constructor",h),h.displayName=c(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(w.prototype),c(w.prototype,i,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),c(g,a,"Generator"),c(g,o,(function(){return this})),c(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,E.prototype={constructor:E,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(L),!t)for(var e in this)"t"===e.charAt(0)&&r.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 n(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 n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.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,l):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),l},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),L(r),l}},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;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(n={exports:{}}),n.exports),i=["findUnique","findFirst","findMany","count","aggregate","groupBy","findRaw","aggregateRaw"];exports.createPrismaRedisCache=function(e){var n=e.models,a=e.defaultCacheTime,c=e.storage,u=e.excludeCacheModels,s=void 0===u?[]:u,l=e.defaultExcludeCacheMethods,f=void 0===l?[]:l,h={ttl:void 0===a?0:a,storage:void 0===c?{type:"memory"}:c,onError:e.onError,onHit:e.onHit,onMiss:e.onMiss,onDedupe:e.onDedupe},p=i.filter((function(t){return!f.includes(t)})),d=t.createCache(h);return function(){var t=r(o.mark((function t(e,i){var a,c;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(null!=p&&p.includes(e.action)&&(null==n||n.forEach((function(t){var n=t.model,c=t.cacheTime;d[n]||null!=s&&s.includes(n)||d.define(n,{ttl:c||h.ttl,references:function(t,r,o){return o?[n+"~"+e.action+"~"+r]:null}},function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i(e);case 2:return t.abrupt("return",a=t.sent);case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())})),d[e.model]||null!=s&&s.includes(e.model)||d.define(e.model,{references:function(t,r,n){return n?[e.model+"~"+e.action+"~"+r]:null}},function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i(e);case 2:return t.abrupt("return",a=t.sent);case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())),c=d[e.model],null!=s&&s.includes(e.model)||null==p||!p.includes(e.action)){t.next=17;break}return t.prev=3,t.next=6,c(e.args);case 6:a=t.sent,t.next=15;break;case 9:return t.prev=9,t.t0=t.catch(3),t.next=13,i(e.args);case 13:a=t.sent,console.error(t.t0);case 15:t.next=22;break;case 17:return t.next=19,i(e.args);case 19:return a=t.sent,t.next=22,d.invalidateAll(e.model+"~*");case 22:return t.abrupt("return",a);case 23:case"end":return t.stop()}}),t,null,[[3,9]])})));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(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}}var n,o=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new E(n||[]);return o._invoke=function(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 c=x(a,r);if(c){if(c===l)continue;return c}}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 u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function f(){}function h(){}function p(){}var d={};c(d,o,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(_([])));y&&y!==e&&r.call(y,o)&&(d=y);var g=p.prototype=f.prototype=Object.create(d);function m(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function b(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 L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function _(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return h.prototype=p,c(g,"constructor",p),c(p,"constructor",h),h.displayName=c(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(w.prototype),c(w.prototype,i,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),c(g,a,"Generator"),c(g,o,(function(){return this})),c(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=_,E.prototype={constructor:E,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(L),!t)for(var e in this)"t"===e.charAt(0)&&r.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 n(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 n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.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,l):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),l},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),L(r),l}},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;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(n={exports:{}}),n.exports),i=["findUnique","findFirst","findMany","count","aggregate","groupBy","findRaw","aggregateRaw"];exports.createPrismaRedisCache=function(e){var n=e.models,a=e.defaultCacheTime,c=e.storage,u=e.excludeCacheModels,s=void 0===u?[]:u,l=e.defaultExcludeCacheMethods,f=void 0===l?[]:l,h={ttl:void 0===a?0:a,storage:void 0===c?{type:"memory"}:c,onError:e.onError,onHit:e.onHit,onMiss:e.onMiss,onDedupe:e.onDedupe},p=i.filter((function(t){return!f.includes(t)})),d=t.createCache(h);return function(){var t=r(o.mark((function t(e,i){var a,c;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(null!=p&&p.includes(e.action)&&(null==n||n.forEach((function(t){var e=t.model,n=t.cacheTime;d[e]||null!=s&&s.includes(e)||d.define(e,{ttl:n||h.ttl,references:function(t,e,r){return r?[t.model+"~"+e]:null}},function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i(e);case 2:return t.abrupt("return",a=t.sent);case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())})),d[e.model]||null!=s&&s.includes(e.model)||d.define(e.model,{references:function(t,e,r){return r?[t.model+"~"+e]:null}},function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i(e);case 2:return t.abrupt("return",a=t.sent);case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())),c=d[e.model],null!=s&&s.includes(e.model)||null==p||!p.includes(e.action)){t.next=17;break}return t.prev=3,t.next=6,c(e);case 6:a=t.sent,t.next=15;break;case 9:return t.prev=9,t.t0=t.catch(3),t.next=13,i(e);case 13:a=t.sent,console.error(t.t0);case 15:t.next=22;break;case 17:return t.next=19,i(e);case 19:return a=t.sent,t.next=22,d.invalidateAll(e.model+"~*");case 22:return t.abrupt("return",a);case 23:case"end":return t.stop()}}),t,null,[[3,9]])})));return function(e,r){return t.apply(this,arguments)}}()}; | ||
//# sourceMappingURL=prisma-redis-middleware.cjs.production.min.js.map |
@@ -849,4 +849,4 @@ import { createCache } from 'async-cache-dedupe'; | ||
ttl: cacheTime || cacheOptions.ttl, | ||
references: function references(_args, key, result) { | ||
return result ? [model + "~" + params.action + "~" + key] : null; | ||
references: function references(args, key, result) { | ||
return result ? [args.model + "~" + key] : null; | ||
} | ||
@@ -883,4 +883,4 @@ }, /*#__PURE__*/function () { | ||
cache.define(params.model, { | ||
references: function references(_args, key, result) { | ||
return result ? [params.model + "~" + params.action + "~" + key] : null; | ||
references: function references(args, key, result) { | ||
return result ? [args.model + "~" + key] : null; | ||
} | ||
@@ -926,3 +926,3 @@ }, /*#__PURE__*/function () { | ||
_context3.next = 6; | ||
return cacheFunction(params.args); | ||
return cacheFunction(params); | ||
@@ -938,3 +938,3 @@ case 6: | ||
_context3.next = 13; | ||
return next(params.args); | ||
return next(params); | ||
@@ -951,3 +951,3 @@ case 13: | ||
_context3.next = 19; | ||
return next(params.args); | ||
return next(params); | ||
@@ -954,0 +954,0 @@ case 19: |
{ | ||
"name": "prisma-redis-middleware", | ||
"author": "A-J Roos <asjas@hey.com>", | ||
"version": "2.0.0-0", | ||
"version": "2.0.0-1", | ||
"description": "Prisma Middleware for caching results of queries in Redis", | ||
@@ -11,6 +11,2 @@ "license": "MIT", | ||
"module": "dist/prisma-redis-middleware.esm.js", | ||
"exports": { | ||
"require": "./dist/index.js", | ||
"default": "./dist/prisma-redis-middleware.esm.js" | ||
}, | ||
"files": [ | ||
@@ -40,4 +36,3 @@ "dist", | ||
"async-cache-dedupe": "1.2.2", | ||
"mnemonist": "0.39.0", | ||
"safe-stable-stringify": "2.3.1" | ||
"mnemonist": "0.39.0" | ||
}, | ||
@@ -44,0 +39,0 @@ "devDependencies": { |
@@ -35,3 +35,6 @@ import { createCache } from "async-cache-dedupe"; | ||
return async function prismaCacheMiddleware(params: MiddlewareParams, next: (params: any) => Promise<any>) { | ||
return async function prismaCacheMiddleware( | ||
params: MiddlewareParams, | ||
next: (params: MiddlewareParams) => Promise<any>, | ||
) { | ||
let result: Record<string, unknown>; | ||
@@ -49,8 +52,9 @@ | ||
ttl: cacheTime || cacheOptions.ttl, | ||
references: (_args: any, key: string, result: any) => { | ||
return result ? [`${model}~${params.action}~${key}`] : null; | ||
references: (args: any, key: string, result: any) => { | ||
return result ? [`${args.model}~${key}`] : null; | ||
}, | ||
}, | ||
async (args: any) => { | ||
async (args: MiddlewareParams) => { | ||
result = await next(args); | ||
return result; | ||
@@ -67,8 +71,9 @@ }, | ||
{ | ||
references: (_args: any, key: string, result: any) => { | ||
return result ? [`${params.model}~${params.action}~${key}`] : null; | ||
references: (args: any, key: string, result: any) => { | ||
return result ? [`${args.model}~${key}`] : null; | ||
}, | ||
}, | ||
async (args: any) => { | ||
async (args: MiddlewareParams) => { | ||
result = await next(args); | ||
return result; | ||
@@ -87,5 +92,6 @@ }, | ||
try { | ||
result = await cacheFunction(params.args); | ||
result = await cacheFunction(params); | ||
} catch (err) { | ||
result = await next(params.args); | ||
// If we fail to fetch it from the cache (network error, etc.) we will fetch it from the database | ||
result = await next(params); | ||
console.error(err); | ||
@@ -95,3 +101,3 @@ } | ||
// Get result from database for any Prisma action or model we exclude from the cache | ||
result = await next(params.args); | ||
result = await next(params); | ||
await cache.invalidateAll(`${params.model}~*`); | ||
@@ -98,0 +104,0 @@ } |
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
2
1938
261184
+ Addedsafe-stable-stringify@2.5.0(transitive)
- Removedsafe-stable-stringify@2.3.1
- Removedsafe-stable-stringify@2.3.1(transitive)