prisma-redis-middleware
Advanced tools
Comparing version 4.6.0 to 4.6.1
@@ -1,3 +0,3 @@ | ||
import type { PrismaQueryAction, PrismaMutationAction } from "./types"; | ||
import type { PrismaMutationAction, PrismaQueryAction } from "./types"; | ||
export declare const defaultCacheMethods: PrismaQueryAction[]; | ||
export declare const defaultMutationMethods: PrismaMutationAction[]; |
@@ -7,129 +7,57 @@ 'use strict'; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
function _regeneratorRuntime() { | ||
_regeneratorRuntime = function () { | ||
return exports; | ||
}; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var runtime_1 = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
var runtime = (function (exports) { | ||
var Op = Object.prototype; | ||
var hasOwn = Op.hasOwnProperty; | ||
var undefined$1; // More compressible than void 0. | ||
var $Symbol = typeof Symbol === "function" ? Symbol : {}; | ||
var iteratorSymbol = $Symbol.iterator || "@@iterator"; | ||
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; | ||
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
var exports = {}, | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
defineProperty = Object.defineProperty || function (obj, key, desc) { | ||
obj[key] = desc.value; | ||
}, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
Object.defineProperty(obj, key, { | ||
return Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
return obj[key]; | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}), obj[key]; | ||
} | ||
try { | ||
// IE 8 has a broken Object.defineProperty that only works on DOM objects. | ||
define({}, ""); | ||
} catch (err) { | ||
define = function(obj, key, value) { | ||
define = function (obj, key, value) { | ||
return obj[key] = value; | ||
}; | ||
} | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; | ||
var generator = Object.create(protoGenerator.prototype); | ||
var context = new Context(tryLocsList || []); | ||
// The ._invoke method unifies the implementations of the .next, | ||
// .throw, and .return methods. | ||
generator._invoke = makeInvokeMethod(innerFn, self, context); | ||
return generator; | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return defineProperty(generator, "_invoke", { | ||
value: makeInvokeMethod(innerFn, self, context) | ||
}), generator; | ||
} | ||
exports.wrap = wrap; | ||
// Try/catch helper to minimize deoptimizations. Returns a completion | ||
// record like context.tryEntries[i].completion. This interface could | ||
// have been (and was previously) designed to take a closure to be | ||
// invoked without arguments, but in all the cases we care about we | ||
// already have an existing method we want to call, so there's no need | ||
// to create a new function object. We can even get away with assuming | ||
// the method takes exactly one argument, since that happens to be true | ||
// in every case, so we don't have to touch the arguments object. The | ||
// only additional allocation required is the completion record, which | ||
// has a stable shape and so hopefully should be cheap to allocate. | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { type: "normal", arg: fn.call(obj, arg) }; | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { type: "throw", arg: err }; | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
} | ||
} | ||
var GenStateSuspendedStart = "suspendedStart"; | ||
var GenStateSuspendedYield = "suspendedYield"; | ||
var GenStateExecuting = "executing"; | ||
var GenStateCompleted = "completed"; | ||
// Returning this object from the innerFn has the same effect as | ||
// breaking out of the dispatch switch statement. | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
// Dummy constructor functions that we use as the .constructor and | ||
// .constructor.prototype properties for functions that return Generator | ||
// objects. For full spec compliance, you may wish to configure your | ||
// minifier not to mangle the names of these two functions. | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
// This is a polyfill for %IteratorPrototype% for environments that | ||
// don't natively support it. | ||
var IteratorPrototype = {}; | ||
@@ -139,29 +67,9 @@ define(IteratorPrototype, iteratorSymbol, function () { | ||
}); | ||
var getProto = Object.getPrototypeOf; | ||
var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
if (NativeIteratorPrototype && | ||
NativeIteratorPrototype !== Op && | ||
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { | ||
// This environment has a native %IteratorPrototype%; use it instead | ||
// of the polyfill. | ||
IteratorPrototype = NativeIteratorPrototype; | ||
} | ||
var Gp = GeneratorFunctionPrototype.prototype = | ||
Generator.prototype = Object.create(IteratorPrototype); | ||
GeneratorFunction.prototype = GeneratorFunctionPrototype; | ||
define(Gp, "constructor", GeneratorFunctionPrototype); | ||
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction); | ||
GeneratorFunction.displayName = define( | ||
GeneratorFunctionPrototype, | ||
toStringTagSymbol, | ||
"GeneratorFunction" | ||
); | ||
// Helper for defining the .next, .throw, and .return methods of the | ||
// Iterator interface in terms of a single ._invoke method. | ||
var getProto = Object.getPrototypeOf, | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function(method) { | ||
define(prototype, method, function(arg) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
define(prototype, method, function (arg) { | ||
return this._invoke(method, arg); | ||
@@ -171,145 +79,41 @@ }); | ||
} | ||
exports.isGeneratorFunction = function(genFun) { | ||
var ctor = typeof genFun === "function" && genFun.constructor; | ||
return ctor | ||
? ctor === GeneratorFunction || | ||
// For the native GeneratorFunction constructor, the best we can | ||
// do is to check its .name property. | ||
(ctor.displayName || ctor.name) === "GeneratorFunction" | ||
: false; | ||
}; | ||
exports.mark = function(genFun) { | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); | ||
} else { | ||
genFun.__proto__ = GeneratorFunctionPrototype; | ||
define(genFun, toStringTagSymbol, "GeneratorFunction"); | ||
} | ||
genFun.prototype = Object.create(Gp); | ||
return genFun; | ||
}; | ||
// Within the body of any async function, `await x` is transformed to | ||
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test | ||
// `hasOwn.call(value, "__await")` to determine if the yielded value is | ||
// meant to be awaited. | ||
exports.awrap = function(arg) { | ||
return { __await: arg }; | ||
}; | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if (record.type === "throw") { | ||
reject(record.arg); | ||
} else { | ||
var result = record.arg; | ||
var value = result.value; | ||
if (value && | ||
typeof value === "object" && | ||
hasOwn.call(value, "__await")) { | ||
return PromiseImpl.resolve(value.__await).then(function(value) { | ||
invoke("next", value, resolve, reject); | ||
}, function(err) { | ||
invoke("throw", err, resolve, reject); | ||
}); | ||
} | ||
return PromiseImpl.resolve(value).then(function(unwrapped) { | ||
// When a yielded Promise is resolved, its final value becomes | ||
// the .value of the Promise<{value,done}> result for the | ||
// current iteration. | ||
result.value = unwrapped; | ||
resolve(result); | ||
}, function(error) { | ||
// If a rejected Promise was yielded, throw the rejection back | ||
// into the async generator function so it can be handled there. | ||
if ("throw" !== record.type) { | ||
var result = record.arg, | ||
value = result.value; | ||
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}) : PromiseImpl.resolve(value).then(function (unwrapped) { | ||
result.value = unwrapped, resolve(result); | ||
}, function (error) { | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
reject(record.arg); | ||
} | ||
var previousPromise; | ||
function enqueue(method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function(resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
defineProperty(this, "_invoke", { | ||
value: function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} | ||
return previousPromise = | ||
// If enqueue has been called before, then we want to wait until | ||
// all previous Promises have been resolved before calling invoke, | ||
// so that results are always delivered in the correct order. If | ||
// enqueue has not been called before, then it is important to | ||
// call invoke immediately, without waiting on a callback to fire, | ||
// so that the async generator function has the opportunity to do | ||
// any necessary setup in a predictable way. This predictability | ||
// is why the Promise constructor synchronously invokes its | ||
// executor callback, and why async functions synchronously | ||
// execute code before the first await. Since we implement simple | ||
// async functions in terms of async generators, it is especially | ||
// important to get this right, even though it requires care. | ||
previousPromise ? previousPromise.then( | ||
callInvokeWithMethodAndArg, | ||
// Avoid propagating failures to Promises returned by later | ||
// invocations of the iterator. | ||
callInvokeWithMethodAndArg | ||
) : callInvokeWithMethodAndArg(); | ||
} | ||
// Define the unified helper method that is used to implement .next, | ||
// .throw, and .return (see defineIteratorMethods). | ||
this._invoke = enqueue; | ||
}); | ||
} | ||
defineIteratorMethods(AsyncIterator.prototype); | ||
define(AsyncIterator.prototype, asyncIteratorSymbol, function () { | ||
return this; | ||
}); | ||
exports.AsyncIterator = AsyncIterator; | ||
// Note that simple async functions are implemented on top of | ||
// AsyncIterator objects; they just return a Promise for the value of | ||
// the final result produced by the iterator. | ||
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
if (PromiseImpl === void 0) PromiseImpl = Promise; | ||
var iter = new AsyncIterator( | ||
wrap(innerFn, outerFn, self, tryLocsList), | ||
PromiseImpl | ||
); | ||
return exports.isGeneratorFunction(outerFn) | ||
? iter // If outerFn is a generator, return the full iterator. | ||
: iter.next().then(function(result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}; | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = GenStateSuspendedStart; | ||
return function invoke(method, arg) { | ||
if (state === GenStateExecuting) { | ||
throw new Error("Generator is already running"); | ||
} | ||
if (state === GenStateCompleted) { | ||
if (method === "throw") { | ||
throw arg; | ||
} | ||
// Be forgiving, per 25.3.3.3.3 of the spec: | ||
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
context.method = method; | ||
context.arg = arg; | ||
while (true) { | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
@@ -323,34 +127,10 @@ if (delegate) { | ||
} | ||
if (context.method === "next") { | ||
// Setting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
context.sent = context._sent = context.arg; | ||
} else if (context.method === "throw") { | ||
if (state === GenStateSuspendedStart) { | ||
state = GenStateCompleted; | ||
throw context.arg; | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else if (context.method === "return") { | ||
context.abrupt("return", context.arg); | ||
} | ||
state = GenStateExecuting; | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if (record.type === "normal") { | ||
// If an exception is thrown from innerFn, we leave state === | ||
// GenStateExecuting and loop back for another invocation. | ||
state = context.done | ||
? GenStateCompleted | ||
: GenStateSuspendedYield; | ||
if (record.arg === ContinueSentinel) { | ||
continue; | ||
} | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
@@ -360,310 +140,125 @@ value: record.arg, | ||
}; | ||
} else if (record.type === "throw") { | ||
state = GenStateCompleted; | ||
// Dispatch the exception by looping back around to the | ||
// context.dispatchException(context.arg) call above. | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
} | ||
// Call delegate.iterator[context.method](context.arg) and handle the | ||
// result, either by returning a { value, done } result from the | ||
// delegate iterator, or by modifying context.method and context.arg, | ||
// setting context.delegate to null, and returning the ContinueSentinel. | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (method === undefined$1) { | ||
// A .throw or .return when the delegate iterator has no .throw | ||
// method always terminates the yield* loop. | ||
context.delegate = null; | ||
if (context.method === "throw") { | ||
// Note: ["return"] must be used for ES3 parsing compatibility. | ||
if (delegate.iterator["return"]) { | ||
// If the delegate iterator has a return method, give it a | ||
// chance to clean up. | ||
context.method = "return"; | ||
context.arg = undefined$1; | ||
maybeInvokeDelegate(delegate, context); | ||
if (context.method === "throw") { | ||
// If maybeInvokeDelegate(context) changed context.method from | ||
// "return" to "throw", let that override the TypeError below. | ||
return ContinueSentinel; | ||
} | ||
} | ||
context.method = "throw"; | ||
context.arg = new TypeError( | ||
"The iterator does not provide a 'throw' method"); | ||
} | ||
return ContinueSentinel; | ||
} | ||
var methodName = context.method, | ||
method = delegate.iterator[methodName]; | ||
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if (record.type === "throw") { | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
var info = record.arg; | ||
if (! info) { | ||
context.method = "throw"; | ||
context.arg = new TypeError("iterator result is not an object"); | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if (info.done) { | ||
// Assign the result of the finished delegate to the temporary | ||
// variable specified by delegate.resultName (see delegateYield). | ||
context[delegate.resultName] = info.value; | ||
// Resume execution at the desired location (see delegateYield). | ||
context.next = delegate.nextLoc; | ||
// If context.method was "throw" but the delegate handled the | ||
// exception, let the outer generator proceed normally. If | ||
// context.method was "next", forget context.arg since it has been | ||
// "consumed" by the delegate iterator. If context.method was | ||
// "return", allow the original .return call to continue in the | ||
// outer generator. | ||
if (context.method !== "return") { | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
} else { | ||
// Re-yield the result returned by the delegate method. | ||
return info; | ||
} | ||
// The delegate iterator is finished, so forget it and continue with | ||
// the outer generator. | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); | ||
} | ||
// Define Generator.prototype.{next,throw,return} in terms of the | ||
// unified ._invoke helper method. | ||
defineIteratorMethods(Gp); | ||
define(Gp, toStringTagSymbol, "Generator"); | ||
// A Generator should always return itself as the iterator object when the | ||
// @@iterator function is called on it. Some browsers' implementations of the | ||
// iterator prototype chain incorrectly implement this, causing the Generator | ||
// object to not be returned from this call. This ensures that doesn't happen. | ||
// See https://github.com/facebook/regenerator/issues/274 for more details. | ||
define(Gp, iteratorSymbol, function() { | ||
return this; | ||
}); | ||
define(Gp, "toString", function() { | ||
return "[object Generator]"; | ||
}); | ||
function pushTryEntry(locs) { | ||
var entry = { tryLoc: locs[0] }; | ||
if (1 in locs) { | ||
entry.catchLoc = locs[1]; | ||
} | ||
if (2 in locs) { | ||
entry.finallyLoc = locs[2]; | ||
entry.afterLoc = locs[3]; | ||
} | ||
this.tryEntries.push(entry); | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal"; | ||
delete record.arg; | ||
entry.completion = record; | ||
record.type = "normal", delete record.arg, entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
// The root entry object (effectively a try statement without a catch | ||
// or a finally block) gives us a place to store values thrown from | ||
// locations where there is no enclosing try statement. | ||
this.tryEntries = [{ tryLoc: "root" }]; | ||
tryLocsList.forEach(pushTryEntry, this); | ||
this.reset(true); | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); | ||
} | ||
exports.keys = function(object) { | ||
var keys = []; | ||
for (var key in object) { | ||
keys.push(key); | ||
} | ||
keys.reverse(); | ||
// Rather than returning an object with a next method, we keep | ||
// things simple and return the next function itself. | ||
return function next() { | ||
while (keys.length) { | ||
var key = keys.pop(); | ||
if (key in object) { | ||
next.value = key; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
// To avoid creating an additional object, we just hang the .value | ||
// and .done properties off the next function object itself. This | ||
// also ensures that the minifier will not anonymize the function. | ||
next.done = true; | ||
return next; | ||
}; | ||
}; | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) { | ||
return iteratorMethod.call(iterable); | ||
} | ||
if (typeof iterable.next === "function") { | ||
return iterable; | ||
} | ||
if (iteratorMethod) return iteratorMethod.call(iterable); | ||
if ("function" == typeof iterable.next) return iterable; | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, next = function next() { | ||
while (++i < iterable.length) { | ||
if (hasOwn.call(iterable, i)) { | ||
next.value = iterable[i]; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
next.value = undefined$1; | ||
next.done = true; | ||
return next; | ||
}; | ||
var i = -1, | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
// Return an iterator with no values. | ||
return { next: doneResult }; | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
exports.values = values; | ||
function doneResult() { | ||
return { value: undefined$1, done: true }; | ||
return { | ||
value: undefined, | ||
done: !0 | ||
}; | ||
} | ||
Context.prototype = { | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { | ||
value: GeneratorFunctionPrototype, | ||
configurable: !0 | ||
}), defineProperty(GeneratorFunctionPrototype, "constructor", { | ||
value: GeneratorFunction, | ||
configurable: !0 | ||
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
var ctor = "function" == typeof genFun && genFun.constructor; | ||
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
}, exports.mark = function (genFun) { | ||
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; | ||
}, exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { | ||
return this; | ||
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
void 0 === PromiseImpl && (PromiseImpl = Promise); | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { | ||
return this; | ||
}), define(Gp, "toString", function () { | ||
return "[object Generator]"; | ||
}), exports.keys = function (val) { | ||
var object = Object(val), | ||
keys = []; | ||
for (var key in object) keys.push(key); | ||
return keys.reverse(), function next() { | ||
for (; keys.length;) { | ||
var key = keys.pop(); | ||
if (key in object) return next.value = key, next.done = !1, next; | ||
} | ||
return next.done = !0, next; | ||
}; | ||
}, exports.values = values, Context.prototype = { | ||
constructor: Context, | ||
reset: function(skipTempReset) { | ||
this.prev = 0; | ||
this.next = 0; | ||
// Resetting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
this.sent = this._sent = undefined$1; | ||
this.done = false; | ||
this.delegate = null; | ||
this.method = "next"; | ||
this.arg = undefined$1; | ||
this.tryEntries.forEach(resetTryEntry); | ||
if (!skipTempReset) { | ||
for (var name in this) { | ||
// Not sure about the optimal order of these conditions: | ||
if (name.charAt(0) === "t" && | ||
hasOwn.call(this, name) && | ||
!isNaN(+name.slice(1))) { | ||
this[name] = undefined$1; | ||
} | ||
} | ||
} | ||
reset: function (skipTempReset) { | ||
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); | ||
}, | ||
stop: function() { | ||
this.done = true; | ||
var rootEntry = this.tryEntries[0]; | ||
var rootRecord = rootEntry.completion; | ||
if (rootRecord.type === "throw") { | ||
throw rootRecord.arg; | ||
} | ||
stop: function () { | ||
this.done = !0; | ||
var rootRecord = this.tryEntries[0].completion; | ||
if ("throw" === rootRecord.type) throw rootRecord.arg; | ||
return this.rval; | ||
}, | ||
dispatchException: function(exception) { | ||
if (this.done) { | ||
throw exception; | ||
} | ||
dispatchException: function (exception) { | ||
if (this.done) throw exception; | ||
var context = this; | ||
function handle(loc, caught) { | ||
record.type = "throw"; | ||
record.arg = exception; | ||
context.next = loc; | ||
if (caught) { | ||
// If the dispatched exception was caught by a catch block, | ||
// then let that catch block handle the exception normally. | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
return !! caught; | ||
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
if (entry.tryLoc === "root") { | ||
// Exception thrown outside of any try block that could handle | ||
// it, so set the completion value of the entire function to | ||
// throw the exception. | ||
return handle("end"); | ||
} | ||
var entry = this.tryEntries[i], | ||
record = entry.completion; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"); | ||
var hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} else if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} | ||
} else if (hasFinally) { | ||
if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
} else { | ||
throw new Error("try statement without catch or finally"); | ||
if (!hasFinally) throw new Error("try statement without catch or finally"); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} | ||
@@ -673,9 +268,6 @@ } | ||
}, | ||
abrupt: function(type, arg) { | ||
abrupt: function (type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && | ||
hasOwn.call(entry, "finallyLoc") && | ||
this.prev < entry.finallyLoc) { | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
@@ -685,57 +277,17 @@ break; | ||
} | ||
if (finallyEntry && | ||
(type === "break" || | ||
type === "continue") && | ||
finallyEntry.tryLoc <= arg && | ||
arg <= finallyEntry.finallyLoc) { | ||
// Ignore the finally entry if control is not jumping to a | ||
// location outside the try/catch block. | ||
finallyEntry = null; | ||
} | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
record.type = type; | ||
record.arg = arg; | ||
if (finallyEntry) { | ||
this.method = "next"; | ||
this.next = finallyEntry.finallyLoc; | ||
return ContinueSentinel; | ||
} | ||
return this.complete(record); | ||
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); | ||
}, | ||
complete: function(record, afterLoc) { | ||
if (record.type === "throw") { | ||
throw record.arg; | ||
} | ||
if (record.type === "break" || | ||
record.type === "continue") { | ||
this.next = record.arg; | ||
} else if (record.type === "return") { | ||
this.rval = this.arg = record.arg; | ||
this.method = "return"; | ||
this.next = "end"; | ||
} else if (record.type === "normal" && afterLoc) { | ||
this.next = afterLoc; | ||
} | ||
return ContinueSentinel; | ||
complete: function (record, afterLoc) { | ||
if ("throw" === record.type) throw record.arg; | ||
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; | ||
}, | ||
finish: function(finallyLoc) { | ||
finish: function (finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) { | ||
this.complete(entry.completion, entry.afterLoc); | ||
resetTryEntry(entry); | ||
return ContinueSentinel; | ||
} | ||
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; | ||
} | ||
}, | ||
"catch": function(tryLoc) { | ||
catch: function (tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
@@ -745,3 +297,3 @@ var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
if (record.type === "throw") { | ||
if ("throw" === record.type) { | ||
var thrown = record.arg; | ||
@@ -753,59 +305,43 @@ resetTryEntry(entry); | ||
} | ||
// The context.catch method must only be called with a location | ||
// argument that corresponds to a known catch block. | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function(iterable, resultName, nextLoc) { | ||
this.delegate = { | ||
delegateYield: function (iterable, resultName, nextLoc) { | ||
return this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}; | ||
if (this.method === "next") { | ||
// Deliberately forget the last sent value so that we don't | ||
// accidentally pass it on to the delegate. | ||
this.arg = undefined$1; | ||
} | ||
return ContinueSentinel; | ||
}, "next" === this.method && (this.arg = undefined), ContinueSentinel; | ||
} | ||
}; | ||
// Regardless of whether this script is executing as a CommonJS module | ||
// or not, return the runtime object so that we can declare the variable | ||
// regeneratorRuntime in the outer scope, which allows this module to be | ||
// injected easily by `bin/regenerator --include-runtime script.js`. | ||
return exports; | ||
}( | ||
// If this script is executing as a CommonJS module, use module.exports | ||
// as the regeneratorRuntime namespace. Otherwise create a new empty | ||
// object. Either way, the resulting object will be used to initialize | ||
// the regeneratorRuntime variable at the top of this file. | ||
module.exports | ||
)); | ||
try { | ||
regeneratorRuntime = runtime; | ||
} catch (accidentalStrictMode) { | ||
// This module should not be running in strict mode, so the above | ||
// assignment should always work unless something is misconfigured. Just | ||
// in case runtime.js accidentally runs in strict mode, in modern engines | ||
// we can explicitly access globalThis. In older engines we can escape | ||
// strict mode using a global Function call. This could conceivably fail | ||
// if a Content Security Policy forbids using Function, but in that case | ||
// the proper solution is to fix the accidental strict mode problem. If | ||
// you've misconfigured your bundler to force strict mode and applied a | ||
// CSP to forbid Function, and you're not willing to fix either of those | ||
// problems, please detail your unique predicament in a GitHub issue. | ||
if (typeof globalThis === "object") { | ||
globalThis.regeneratorRuntime = runtime; | ||
}, exports; | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Function("r", "regeneratorRuntime = r")(runtime); | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
}); | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
@@ -818,13 +354,13 @@ var defaultCacheMethods = ["findUnique", "findFirst", "findMany", "count", "aggregate", "groupBy", "findRaw", "aggregateRaw"]; | ||
var models = _ref.models, | ||
onDedupe = _ref.onDedupe, | ||
onError = _ref.onError, | ||
onHit = _ref.onHit, | ||
onMiss = _ref.onMiss, | ||
storage = _ref.storage, | ||
_ref$cacheTime = _ref.cacheTime, | ||
cacheTime = _ref$cacheTime === void 0 ? DEFAULT_CACHE_TIME : _ref$cacheTime, | ||
_ref$excludeModels = _ref.excludeModels, | ||
excludeModels = _ref$excludeModels === void 0 ? [] : _ref$excludeModels, | ||
_ref$excludeMethods = _ref.excludeMethods, | ||
excludeMethods = _ref$excludeMethods === void 0 ? [] : _ref$excludeMethods; | ||
onDedupe = _ref.onDedupe, | ||
onError = _ref.onError, | ||
onHit = _ref.onHit, | ||
onMiss = _ref.onMiss, | ||
storage = _ref.storage, | ||
_ref$cacheTime = _ref.cacheTime, | ||
cacheTime = _ref$cacheTime === void 0 ? DEFAULT_CACHE_TIME : _ref$cacheTime, | ||
_ref$excludeModels = _ref.excludeModels, | ||
excludeModels = _ref$excludeModels === void 0 ? [] : _ref$excludeModels, | ||
_ref$excludeMethods = _ref.excludeMethods, | ||
excludeMethods = _ref$excludeMethods === void 0 ? [] : _ref$excludeMethods; | ||
// Default options for "async-cache-dedupe" | ||
@@ -840,246 +376,196 @@ var cacheOptions = { | ||
var cache = asyncCacheDedupe.createCache(cacheOptions); | ||
var middleware = /*#__PURE__*/function () { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(params, next) { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params, next) { | ||
var result, fetchFromPrisma, excludedCacheMethods, _excludedCacheMethods, excludedCacheMethodsInModels, cacheFunction; | ||
return runtime_1.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
// This function is used by `async-cache-dedupe` to fetch data when the cache is empty | ||
fetchFromPrisma = /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(params) { | ||
return runtime_1.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", next(params)); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function fetchFromPrisma(_x3) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); // Do not cache any Prisma method specified in the defaultExcludeCacheMethods option | ||
excludedCacheMethods = defaultCacheMethods.filter(function (cacheMethod) { | ||
return excludeMethods.includes(cacheMethod); | ||
}); // Do not cache any Prisma method that has been excluded | ||
if (!(excludedCacheMethods != null && excludedCacheMethods.includes(params.action))) { | ||
// Add a cache function for each model specified in the models option | ||
models == null ? void 0 : models.forEach(function (_ref4) { | ||
var model = _ref4.model, | ||
cacheTime = _ref4.cacheTime, | ||
cacheKey = _ref4.cacheKey, | ||
excludeMethods = _ref4.excludeMethods; | ||
// Only define the cache function for a model if it doesn't exist yet and hasn't been excluded | ||
if (!cache[model] && model === params.model && !(excludeModels != null && excludeModels.includes(params.model)) && !(excludeMethods != null && excludeMethods.includes(params.action))) { | ||
cache.define(model, { | ||
references: function references(_ref5, key) { | ||
var params = _ref5.params; | ||
return [(cacheKey || params.model) + "~" + key]; | ||
}, | ||
ttl: cacheTime || cacheOptions.ttl | ||
}, /*#__PURE__*/function () { | ||
var _modelsFetch = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref6) { | ||
var cb, params; | ||
return runtime_1.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cb = _ref6.cb, params = _ref6.params; | ||
_context2.next = 3; | ||
return cb(params); | ||
case 3: | ||
result = _context2.sent; | ||
return _context2.abrupt("return", result); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
})); | ||
function modelsFetch(_x4) { | ||
return _modelsFetch.apply(this, arguments); | ||
} | ||
return modelsFetch; | ||
}()); | ||
return _regeneratorRuntime().wrap(function _callee6$(_context6) { | ||
while (1) switch (_context6.prev = _context6.next) { | ||
case 0: | ||
// This function is used by `async-cache-dedupe` to fetch data when the cache is empty | ||
fetchFromPrisma = /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) { | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", next(params)); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}); // For each defined model in `models` we check if they defined any caching methods to be excluded | ||
excludedCacheMethodsInModels = models == null ? void 0 : models.find(function (_ref7) { | ||
var model = _ref7.model, | ||
excludeMethods = _ref7.excludeMethods; | ||
return model === params.model && (excludeMethods == null ? void 0 : excludeMethods.length); | ||
}); // Do not define a cache function for any Prisma model if it already exists | ||
// Do not define the cache function for a model if it was excluded in `defaultExcludeCacheModels` | ||
// Do not define a cache function if the Prisma method was exluded in `models` | ||
if (!cache[params.model] && !(excludeModels != null && excludeModels.includes(params.model)) && !(excludedCacheMethodsInModels != null && (_excludedCacheMethods = excludedCacheMethodsInModels.excludeMethods) != null && _excludedCacheMethods.includes(params.action))) { | ||
cache.define(params.model, { | ||
references: function references(_ref8, key) { | ||
var params = _ref8.params; | ||
return [params.model + "~" + key]; | ||
} | ||
}, _callee); | ||
})); | ||
return function fetchFromPrisma(_x3) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); // Do not cache any Prisma method specified in the defaultExcludeCacheMethods option | ||
excludedCacheMethods = defaultCacheMethods.filter(function (cacheMethod) { | ||
return excludeMethods.includes(cacheMethod); | ||
}); // Do not cache any Prisma method that has been excluded | ||
if (!(excludedCacheMethods != null && excludedCacheMethods.includes(params.action))) { | ||
// Add a cache function for each model specified in the models option | ||
models == null ? void 0 : models.forEach(function (_ref4) { | ||
var model = _ref4.model, | ||
cacheTime = _ref4.cacheTime, | ||
cacheKey = _ref4.cacheKey, | ||
excludeMethods = _ref4.excludeMethods; | ||
// Only define the cache function for a model if it doesn't exist yet and hasn't been excluded | ||
if (!cache[model] && model === params.model && !(excludeModels != null && excludeModels.includes(params.model)) && !(excludeMethods != null && excludeMethods.includes(params.action))) { | ||
cache.define(model, { | ||
references: function references(_ref5, key) { | ||
var params = _ref5.params; | ||
return [(cacheKey || params.model) + "~" + key]; | ||
}, | ||
ttl: cacheTime || cacheOptions.ttl | ||
}, /*#__PURE__*/function () { | ||
var _modelFetch = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_ref9) { | ||
var _modelsFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref6) { | ||
var cb, params; | ||
return runtime_1.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
cb = _ref9.cb, params = _ref9.params; | ||
_context3.next = 3; | ||
return cb(params); | ||
case 3: | ||
result = _context3.sent; | ||
return _context3.abrupt("return", result); | ||
case 5: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cb = _ref6.cb, params = _ref6.params; | ||
_context2.next = 3; | ||
return cb(params); | ||
case 3: | ||
result = _context2.sent; | ||
return _context2.abrupt("return", result); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee3); | ||
}, _callee2); | ||
})); | ||
function modelFetch(_x5) { | ||
return _modelFetch.apply(this, arguments); | ||
function modelsFetch(_x4) { | ||
return _modelsFetch.apply(this, arguments); | ||
} | ||
return modelFetch; | ||
return modelsFetch; | ||
}()); | ||
} | ||
} // Get the cache function relating to the Prisma model | ||
cacheFunction = cache[params.model]; // Only cache the data if the Prisma model hasn't been excluded and if the Prisma method wasn't excluded either | ||
if (!(!(excludeModels != null && excludeModels.includes(params.model)) && !(excludedCacheMethods != null && excludedCacheMethods.includes(params.action)) && !(defaultMutationMethods != null && defaultMutationMethods.includes(params.action)) && typeof cacheFunction === "function")) { | ||
_context6.next = 19; | ||
break; | ||
}); | ||
// For each defined model in `models` we check if they defined any caching methods to be excluded | ||
excludedCacheMethodsInModels = models == null ? void 0 : models.find(function (_ref7) { | ||
var model = _ref7.model, | ||
excludeMethods = _ref7.excludeMethods; | ||
return model === params.model && (excludeMethods == null ? void 0 : excludeMethods.length); | ||
}); // Do not define a cache function for any Prisma model if it already exists | ||
// Do not define the cache function for a model if it was excluded in `defaultExcludeCacheModels` | ||
// Do not define a cache function if the Prisma method was exluded in `models` | ||
if (!cache[params.model] && !(excludeModels != null && excludeModels.includes(params.model)) && !(excludedCacheMethodsInModels != null && (_excludedCacheMethods = excludedCacheMethodsInModels.excludeMethods) != null && _excludedCacheMethods.includes(params.action))) { | ||
cache.define(params.model, { | ||
references: function references(_ref8, key) { | ||
var params = _ref8.params; | ||
return [params.model + "~" + key]; | ||
} | ||
}, /*#__PURE__*/function () { | ||
var _modelFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref9) { | ||
var cb, params; | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
cb = _ref9.cb, params = _ref9.params; | ||
_context3.next = 3; | ||
return cb(params); | ||
case 3: | ||
result = _context3.sent; | ||
return _context3.abrupt("return", result); | ||
case 5: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3); | ||
})); | ||
function modelFetch(_x5) { | ||
return _modelFetch.apply(this, arguments); | ||
} | ||
return modelFetch; | ||
}()); | ||
} | ||
_context6.prev = 5; | ||
_context6.next = 8; | ||
return cacheFunction({ | ||
cb: fetchFromPrisma, | ||
params: params | ||
}); | ||
case 8: | ||
result = _context6.sent; | ||
_context6.next = 17; | ||
} | ||
// Get the cache function relating to the Prisma model | ||
cacheFunction = cache[params.model]; // Only cache the data if the Prisma model hasn't been excluded and if the Prisma method wasn't excluded either | ||
if (!(!(excludeModels != null && excludeModels.includes(params.model)) && !(excludedCacheMethods != null && excludedCacheMethods.includes(params.action)) && !(defaultMutationMethods != null && defaultMutationMethods.includes(params.action)) && typeof cacheFunction === "function")) { | ||
_context6.next = 19; | ||
break; | ||
case 11: | ||
_context6.prev = 11; | ||
_context6.t0 = _context6["catch"](5); | ||
_context6.next = 15; | ||
return fetchFromPrisma(params); | ||
case 15: | ||
result = _context6.sent; | ||
console.error(_context6.t0); | ||
case 17: | ||
} | ||
_context6.prev = 5; | ||
_context6.next = 8; | ||
return cacheFunction({ | ||
cb: fetchFromPrisma, | ||
params: params | ||
}); | ||
case 8: | ||
result = _context6.sent; | ||
_context6.next = 17; | ||
break; | ||
case 11: | ||
_context6.prev = 11; | ||
_context6.t0 = _context6["catch"](5); | ||
_context6.next = 15; | ||
return fetchFromPrisma(params); | ||
case 15: | ||
result = _context6.sent; | ||
console.error(_context6.t0); | ||
case 17: | ||
_context6.next = 27; | ||
break; | ||
case 19: | ||
_context6.next = 21; | ||
return fetchFromPrisma(params); | ||
case 21: | ||
result = _context6.sent; | ||
if (!defaultMutationMethods.includes(params.action)) { | ||
_context6.next = 27; | ||
break; | ||
case 19: | ||
_context6.next = 21; | ||
return fetchFromPrisma(params); | ||
case 21: | ||
result = _context6.sent; | ||
if (!defaultMutationMethods.includes(params.action)) { | ||
_context6.next = 27; | ||
break; | ||
} | ||
_context6.next = 25; | ||
return cache.invalidateAll("*" + params.model + "~*"); | ||
case 25: | ||
_context6.next = 27; | ||
return Promise.all((models || []).filter(function (_ref10) { | ||
var model = _ref10.model; | ||
return model === params.model; | ||
}).map( /*#__PURE__*/function () { | ||
var _ref12 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(_ref11) { | ||
var invalidateRelated; | ||
return runtime_1.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
invalidateRelated = _ref11.invalidateRelated; | ||
if (!invalidateRelated) { | ||
_context5.next = 4; | ||
break; | ||
} | ||
_context5.next = 4; | ||
return Promise.all(invalidateRelated.map( /*#__PURE__*/function () { | ||
var _ref13 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(relatedModel) { | ||
return runtime_1.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return _context4.abrupt("return", cache.invalidateAll("*" + relatedModel + "~*")); | ||
case 1: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4); | ||
})); | ||
return function (_x7) { | ||
return _ref13.apply(this, arguments); | ||
}; | ||
}())); | ||
case 4: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
_context6.next = 25; | ||
return cache.invalidateAll("*" + params.model + "~*"); | ||
case 25: | ||
_context6.next = 27; | ||
return Promise.all((models || []).filter(function (_ref10) { | ||
var model = _ref10.model; | ||
return model === params.model; | ||
}).map( /*#__PURE__*/function () { | ||
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref11) { | ||
var invalidateRelated; | ||
return _regeneratorRuntime().wrap(function _callee5$(_context5) { | ||
while (1) switch (_context5.prev = _context5.next) { | ||
case 0: | ||
invalidateRelated = _ref11.invalidateRelated; | ||
if (!invalidateRelated) { | ||
_context5.next = 4; | ||
break; | ||
} | ||
} | ||
}, _callee5); | ||
})); | ||
return function (_x6) { | ||
return _ref12.apply(this, arguments); | ||
}; | ||
}())); | ||
case 27: | ||
return _context6.abrupt("return", result); | ||
case 28: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
_context5.next = 4; | ||
return Promise.all(invalidateRelated.map( /*#__PURE__*/function () { | ||
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(relatedModel) { | ||
return _regeneratorRuntime().wrap(function _callee4$(_context4) { | ||
while (1) switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return _context4.abrupt("return", cache.invalidateAll("*" + relatedModel + "~*")); | ||
case 1: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, _callee4); | ||
})); | ||
return function (_x7) { | ||
return _ref13.apply(this, arguments); | ||
}; | ||
}())); | ||
case 4: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
}, _callee5); | ||
})); | ||
return function (_x6) { | ||
return _ref12.apply(this, arguments); | ||
}; | ||
}())); | ||
case 27: | ||
return _context6.abrupt("return", result); | ||
case 28: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
}, _callee6, null, [[5, 11]]); | ||
})); | ||
return function middleware(_x, _x2) { | ||
@@ -1089,3 +575,2 @@ return _ref2.apply(this, arguments); | ||
}(); | ||
return middleware; | ||
@@ -1092,0 +577,0 @@ }; |
@@ -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(k([])));y&&y!==e&&r.call(y,o)&&(d=y);var m=p.prototype=f.prototype=Object.create(d);function g(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 k(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:_}}function _(){return{value:void 0,done:!0}}return h.prototype=p,c(m,"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(m),t},t.awrap=function(t){return{__await:t}},g(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()}))},g(m),c(m,a,"Generator"),c(m,o,(function(){return this})),c(m,"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=k,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:k(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"],a=["create","createMany","update","updateMany","upsert","delete","deleteMany","executeRawUnsafe"];exports.createPrismaRedisCache=function(e){var n=e.models,c=e.cacheTime,u=e.excludeModels,s=void 0===u?[]:u,l=e.excludeMethods,f=void 0===l?[]:l,h={onDedupe:e.onDedupe,onError:e.onError,onHit:e.onHit,onMiss:e.onMiss,storage:e.storage,ttl:void 0===c?0:c},p=t.createCache(h);return function(){var t=r(o.mark((function t(e,c){var u,l,d,v,y,m;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(l=function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",c(e));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),null!=(d=i.filter((function(t){return f.includes(t)})))&&d.includes(e.action)||(null==n||n.forEach((function(t){var n=t.model,i=t.cacheTime,a=t.cacheKey,c=t.excludeMethods;p[n]||n!==e.model||null!=s&&s.includes(e.model)||null!=c&&c.includes(e.action)||p.define(n,{references:function(t,e){return[(a||t.params.model)+"~"+e]},ttl:i||h.ttl},function(){var t=r(o.mark((function t(e){var r,n;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.cb,n=e.params,t.next=3,r(n);case 3:return t.abrupt("return",u=t.sent);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())})),y=null==n?void 0:n.find((function(t){var r=t.excludeMethods;return t.model===e.model&&(null==r?void 0:r.length)})),p[e.model]||null!=s&&s.includes(e.model)||null!=y&&null!=(v=y.excludeMethods)&&v.includes(e.action)||p.define(e.model,{references:function(t,e){return[t.params.model+"~"+e]}},function(){var t=r(o.mark((function t(e){var r,n;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.cb,n=e.params,t.next=3,r(n);case 3:return t.abrupt("return",u=t.sent);case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}())),m=p[e.model],null!=s&&s.includes(e.model)||null!=d&&d.includes(e.action)||null!=a&&a.includes(e.action)||"function"!=typeof m){t.next=19;break}return t.prev=5,t.next=8,m({cb:l,params:e});case 8:u=t.sent,t.next=17;break;case 11:return t.prev=11,t.t0=t.catch(5),t.next=15,l(e);case 15:u=t.sent,console.error(t.t0);case 17:t.next=27;break;case 19:return t.next=21,l(e);case 21:if(u=t.sent,!a.includes(e.action)){t.next=27;break}return t.next=25,p.invalidateAll("*"+e.model+"~*");case 25:return t.next=27,Promise.all((n||[]).filter((function(t){return t.model===e.model})).map(function(){var t=r(o.mark((function t(e){var n;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(n=e.invalidateRelated)){t.next=4;break}return t.next=4,Promise.all(n.map(function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",p.invalidateAll("*"+e+"~*"));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",u);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},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 |
import { createCache } from 'async-cache-dedupe'; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
function _regeneratorRuntime() { | ||
_regeneratorRuntime = function () { | ||
return exports; | ||
}; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var runtime_1 = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
var runtime = (function (exports) { | ||
var Op = Object.prototype; | ||
var hasOwn = Op.hasOwnProperty; | ||
var undefined$1; // More compressible than void 0. | ||
var $Symbol = typeof Symbol === "function" ? Symbol : {}; | ||
var iteratorSymbol = $Symbol.iterator || "@@iterator"; | ||
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; | ||
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
var exports = {}, | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
defineProperty = Object.defineProperty || function (obj, key, desc) { | ||
obj[key] = desc.value; | ||
}, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
Object.defineProperty(obj, key, { | ||
return Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
return obj[key]; | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}), obj[key]; | ||
} | ||
try { | ||
// IE 8 has a broken Object.defineProperty that only works on DOM objects. | ||
define({}, ""); | ||
} catch (err) { | ||
define = function(obj, key, value) { | ||
define = function (obj, key, value) { | ||
return obj[key] = value; | ||
}; | ||
} | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; | ||
var generator = Object.create(protoGenerator.prototype); | ||
var context = new Context(tryLocsList || []); | ||
// The ._invoke method unifies the implementations of the .next, | ||
// .throw, and .return methods. | ||
generator._invoke = makeInvokeMethod(innerFn, self, context); | ||
return generator; | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return defineProperty(generator, "_invoke", { | ||
value: makeInvokeMethod(innerFn, self, context) | ||
}), generator; | ||
} | ||
exports.wrap = wrap; | ||
// Try/catch helper to minimize deoptimizations. Returns a completion | ||
// record like context.tryEntries[i].completion. This interface could | ||
// have been (and was previously) designed to take a closure to be | ||
// invoked without arguments, but in all the cases we care about we | ||
// already have an existing method we want to call, so there's no need | ||
// to create a new function object. We can even get away with assuming | ||
// the method takes exactly one argument, since that happens to be true | ||
// in every case, so we don't have to touch the arguments object. The | ||
// only additional allocation required is the completion record, which | ||
// has a stable shape and so hopefully should be cheap to allocate. | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { type: "normal", arg: fn.call(obj, arg) }; | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { type: "throw", arg: err }; | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
} | ||
} | ||
var GenStateSuspendedStart = "suspendedStart"; | ||
var GenStateSuspendedYield = "suspendedYield"; | ||
var GenStateExecuting = "executing"; | ||
var GenStateCompleted = "completed"; | ||
// Returning this object from the innerFn has the same effect as | ||
// breaking out of the dispatch switch statement. | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
// Dummy constructor functions that we use as the .constructor and | ||
// .constructor.prototype properties for functions that return Generator | ||
// objects. For full spec compliance, you may wish to configure your | ||
// minifier not to mangle the names of these two functions. | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
// This is a polyfill for %IteratorPrototype% for environments that | ||
// don't natively support it. | ||
var IteratorPrototype = {}; | ||
@@ -134,29 +62,9 @@ define(IteratorPrototype, iteratorSymbol, function () { | ||
}); | ||
var getProto = Object.getPrototypeOf; | ||
var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
if (NativeIteratorPrototype && | ||
NativeIteratorPrototype !== Op && | ||
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { | ||
// This environment has a native %IteratorPrototype%; use it instead | ||
// of the polyfill. | ||
IteratorPrototype = NativeIteratorPrototype; | ||
} | ||
var Gp = GeneratorFunctionPrototype.prototype = | ||
Generator.prototype = Object.create(IteratorPrototype); | ||
GeneratorFunction.prototype = GeneratorFunctionPrototype; | ||
define(Gp, "constructor", GeneratorFunctionPrototype); | ||
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction); | ||
GeneratorFunction.displayName = define( | ||
GeneratorFunctionPrototype, | ||
toStringTagSymbol, | ||
"GeneratorFunction" | ||
); | ||
// Helper for defining the .next, .throw, and .return methods of the | ||
// Iterator interface in terms of a single ._invoke method. | ||
var getProto = Object.getPrototypeOf, | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function(method) { | ||
define(prototype, method, function(arg) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
define(prototype, method, function (arg) { | ||
return this._invoke(method, arg); | ||
@@ -166,145 +74,41 @@ }); | ||
} | ||
exports.isGeneratorFunction = function(genFun) { | ||
var ctor = typeof genFun === "function" && genFun.constructor; | ||
return ctor | ||
? ctor === GeneratorFunction || | ||
// For the native GeneratorFunction constructor, the best we can | ||
// do is to check its .name property. | ||
(ctor.displayName || ctor.name) === "GeneratorFunction" | ||
: false; | ||
}; | ||
exports.mark = function(genFun) { | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); | ||
} else { | ||
genFun.__proto__ = GeneratorFunctionPrototype; | ||
define(genFun, toStringTagSymbol, "GeneratorFunction"); | ||
} | ||
genFun.prototype = Object.create(Gp); | ||
return genFun; | ||
}; | ||
// Within the body of any async function, `await x` is transformed to | ||
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test | ||
// `hasOwn.call(value, "__await")` to determine if the yielded value is | ||
// meant to be awaited. | ||
exports.awrap = function(arg) { | ||
return { __await: arg }; | ||
}; | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if (record.type === "throw") { | ||
reject(record.arg); | ||
} else { | ||
var result = record.arg; | ||
var value = result.value; | ||
if (value && | ||
typeof value === "object" && | ||
hasOwn.call(value, "__await")) { | ||
return PromiseImpl.resolve(value.__await).then(function(value) { | ||
invoke("next", value, resolve, reject); | ||
}, function(err) { | ||
invoke("throw", err, resolve, reject); | ||
}); | ||
} | ||
return PromiseImpl.resolve(value).then(function(unwrapped) { | ||
// When a yielded Promise is resolved, its final value becomes | ||
// the .value of the Promise<{value,done}> result for the | ||
// current iteration. | ||
result.value = unwrapped; | ||
resolve(result); | ||
}, function(error) { | ||
// If a rejected Promise was yielded, throw the rejection back | ||
// into the async generator function so it can be handled there. | ||
if ("throw" !== record.type) { | ||
var result = record.arg, | ||
value = result.value; | ||
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}) : PromiseImpl.resolve(value).then(function (unwrapped) { | ||
result.value = unwrapped, resolve(result); | ||
}, function (error) { | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
reject(record.arg); | ||
} | ||
var previousPromise; | ||
function enqueue(method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function(resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
defineProperty(this, "_invoke", { | ||
value: function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} | ||
return previousPromise = | ||
// If enqueue has been called before, then we want to wait until | ||
// all previous Promises have been resolved before calling invoke, | ||
// so that results are always delivered in the correct order. If | ||
// enqueue has not been called before, then it is important to | ||
// call invoke immediately, without waiting on a callback to fire, | ||
// so that the async generator function has the opportunity to do | ||
// any necessary setup in a predictable way. This predictability | ||
// is why the Promise constructor synchronously invokes its | ||
// executor callback, and why async functions synchronously | ||
// execute code before the first await. Since we implement simple | ||
// async functions in terms of async generators, it is especially | ||
// important to get this right, even though it requires care. | ||
previousPromise ? previousPromise.then( | ||
callInvokeWithMethodAndArg, | ||
// Avoid propagating failures to Promises returned by later | ||
// invocations of the iterator. | ||
callInvokeWithMethodAndArg | ||
) : callInvokeWithMethodAndArg(); | ||
} | ||
// Define the unified helper method that is used to implement .next, | ||
// .throw, and .return (see defineIteratorMethods). | ||
this._invoke = enqueue; | ||
}); | ||
} | ||
defineIteratorMethods(AsyncIterator.prototype); | ||
define(AsyncIterator.prototype, asyncIteratorSymbol, function () { | ||
return this; | ||
}); | ||
exports.AsyncIterator = AsyncIterator; | ||
// Note that simple async functions are implemented on top of | ||
// AsyncIterator objects; they just return a Promise for the value of | ||
// the final result produced by the iterator. | ||
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
if (PromiseImpl === void 0) PromiseImpl = Promise; | ||
var iter = new AsyncIterator( | ||
wrap(innerFn, outerFn, self, tryLocsList), | ||
PromiseImpl | ||
); | ||
return exports.isGeneratorFunction(outerFn) | ||
? iter // If outerFn is a generator, return the full iterator. | ||
: iter.next().then(function(result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}; | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = GenStateSuspendedStart; | ||
return function invoke(method, arg) { | ||
if (state === GenStateExecuting) { | ||
throw new Error("Generator is already running"); | ||
} | ||
if (state === GenStateCompleted) { | ||
if (method === "throw") { | ||
throw arg; | ||
} | ||
// Be forgiving, per 25.3.3.3.3 of the spec: | ||
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
context.method = method; | ||
context.arg = arg; | ||
while (true) { | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
@@ -318,34 +122,10 @@ if (delegate) { | ||
} | ||
if (context.method === "next") { | ||
// Setting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
context.sent = context._sent = context.arg; | ||
} else if (context.method === "throw") { | ||
if (state === GenStateSuspendedStart) { | ||
state = GenStateCompleted; | ||
throw context.arg; | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else if (context.method === "return") { | ||
context.abrupt("return", context.arg); | ||
} | ||
state = GenStateExecuting; | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if (record.type === "normal") { | ||
// If an exception is thrown from innerFn, we leave state === | ||
// GenStateExecuting and loop back for another invocation. | ||
state = context.done | ||
? GenStateCompleted | ||
: GenStateSuspendedYield; | ||
if (record.arg === ContinueSentinel) { | ||
continue; | ||
} | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
@@ -355,310 +135,125 @@ value: record.arg, | ||
}; | ||
} else if (record.type === "throw") { | ||
state = GenStateCompleted; | ||
// Dispatch the exception by looping back around to the | ||
// context.dispatchException(context.arg) call above. | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
} | ||
// Call delegate.iterator[context.method](context.arg) and handle the | ||
// result, either by returning a { value, done } result from the | ||
// delegate iterator, or by modifying context.method and context.arg, | ||
// setting context.delegate to null, and returning the ContinueSentinel. | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (method === undefined$1) { | ||
// A .throw or .return when the delegate iterator has no .throw | ||
// method always terminates the yield* loop. | ||
context.delegate = null; | ||
if (context.method === "throw") { | ||
// Note: ["return"] must be used for ES3 parsing compatibility. | ||
if (delegate.iterator["return"]) { | ||
// If the delegate iterator has a return method, give it a | ||
// chance to clean up. | ||
context.method = "return"; | ||
context.arg = undefined$1; | ||
maybeInvokeDelegate(delegate, context); | ||
if (context.method === "throw") { | ||
// If maybeInvokeDelegate(context) changed context.method from | ||
// "return" to "throw", let that override the TypeError below. | ||
return ContinueSentinel; | ||
} | ||
} | ||
context.method = "throw"; | ||
context.arg = new TypeError( | ||
"The iterator does not provide a 'throw' method"); | ||
} | ||
return ContinueSentinel; | ||
} | ||
var methodName = context.method, | ||
method = delegate.iterator[methodName]; | ||
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if (record.type === "throw") { | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
var info = record.arg; | ||
if (! info) { | ||
context.method = "throw"; | ||
context.arg = new TypeError("iterator result is not an object"); | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if (info.done) { | ||
// Assign the result of the finished delegate to the temporary | ||
// variable specified by delegate.resultName (see delegateYield). | ||
context[delegate.resultName] = info.value; | ||
// Resume execution at the desired location (see delegateYield). | ||
context.next = delegate.nextLoc; | ||
// If context.method was "throw" but the delegate handled the | ||
// exception, let the outer generator proceed normally. If | ||
// context.method was "next", forget context.arg since it has been | ||
// "consumed" by the delegate iterator. If context.method was | ||
// "return", allow the original .return call to continue in the | ||
// outer generator. | ||
if (context.method !== "return") { | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
} else { | ||
// Re-yield the result returned by the delegate method. | ||
return info; | ||
} | ||
// The delegate iterator is finished, so forget it and continue with | ||
// the outer generator. | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); | ||
} | ||
// Define Generator.prototype.{next,throw,return} in terms of the | ||
// unified ._invoke helper method. | ||
defineIteratorMethods(Gp); | ||
define(Gp, toStringTagSymbol, "Generator"); | ||
// A Generator should always return itself as the iterator object when the | ||
// @@iterator function is called on it. Some browsers' implementations of the | ||
// iterator prototype chain incorrectly implement this, causing the Generator | ||
// object to not be returned from this call. This ensures that doesn't happen. | ||
// See https://github.com/facebook/regenerator/issues/274 for more details. | ||
define(Gp, iteratorSymbol, function() { | ||
return this; | ||
}); | ||
define(Gp, "toString", function() { | ||
return "[object Generator]"; | ||
}); | ||
function pushTryEntry(locs) { | ||
var entry = { tryLoc: locs[0] }; | ||
if (1 in locs) { | ||
entry.catchLoc = locs[1]; | ||
} | ||
if (2 in locs) { | ||
entry.finallyLoc = locs[2]; | ||
entry.afterLoc = locs[3]; | ||
} | ||
this.tryEntries.push(entry); | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal"; | ||
delete record.arg; | ||
entry.completion = record; | ||
record.type = "normal", delete record.arg, entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
// The root entry object (effectively a try statement without a catch | ||
// or a finally block) gives us a place to store values thrown from | ||
// locations where there is no enclosing try statement. | ||
this.tryEntries = [{ tryLoc: "root" }]; | ||
tryLocsList.forEach(pushTryEntry, this); | ||
this.reset(true); | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); | ||
} | ||
exports.keys = function(object) { | ||
var keys = []; | ||
for (var key in object) { | ||
keys.push(key); | ||
} | ||
keys.reverse(); | ||
// Rather than returning an object with a next method, we keep | ||
// things simple and return the next function itself. | ||
return function next() { | ||
while (keys.length) { | ||
var key = keys.pop(); | ||
if (key in object) { | ||
next.value = key; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
// To avoid creating an additional object, we just hang the .value | ||
// and .done properties off the next function object itself. This | ||
// also ensures that the minifier will not anonymize the function. | ||
next.done = true; | ||
return next; | ||
}; | ||
}; | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) { | ||
return iteratorMethod.call(iterable); | ||
} | ||
if (typeof iterable.next === "function") { | ||
return iterable; | ||
} | ||
if (iteratorMethod) return iteratorMethod.call(iterable); | ||
if ("function" == typeof iterable.next) return iterable; | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, next = function next() { | ||
while (++i < iterable.length) { | ||
if (hasOwn.call(iterable, i)) { | ||
next.value = iterable[i]; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
next.value = undefined$1; | ||
next.done = true; | ||
return next; | ||
}; | ||
var i = -1, | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
// Return an iterator with no values. | ||
return { next: doneResult }; | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
exports.values = values; | ||
function doneResult() { | ||
return { value: undefined$1, done: true }; | ||
return { | ||
value: undefined, | ||
done: !0 | ||
}; | ||
} | ||
Context.prototype = { | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { | ||
value: GeneratorFunctionPrototype, | ||
configurable: !0 | ||
}), defineProperty(GeneratorFunctionPrototype, "constructor", { | ||
value: GeneratorFunction, | ||
configurable: !0 | ||
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
var ctor = "function" == typeof genFun && genFun.constructor; | ||
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
}, exports.mark = function (genFun) { | ||
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; | ||
}, exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { | ||
return this; | ||
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
void 0 === PromiseImpl && (PromiseImpl = Promise); | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { | ||
return this; | ||
}), define(Gp, "toString", function () { | ||
return "[object Generator]"; | ||
}), exports.keys = function (val) { | ||
var object = Object(val), | ||
keys = []; | ||
for (var key in object) keys.push(key); | ||
return keys.reverse(), function next() { | ||
for (; keys.length;) { | ||
var key = keys.pop(); | ||
if (key in object) return next.value = key, next.done = !1, next; | ||
} | ||
return next.done = !0, next; | ||
}; | ||
}, exports.values = values, Context.prototype = { | ||
constructor: Context, | ||
reset: function(skipTempReset) { | ||
this.prev = 0; | ||
this.next = 0; | ||
// Resetting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
this.sent = this._sent = undefined$1; | ||
this.done = false; | ||
this.delegate = null; | ||
this.method = "next"; | ||
this.arg = undefined$1; | ||
this.tryEntries.forEach(resetTryEntry); | ||
if (!skipTempReset) { | ||
for (var name in this) { | ||
// Not sure about the optimal order of these conditions: | ||
if (name.charAt(0) === "t" && | ||
hasOwn.call(this, name) && | ||
!isNaN(+name.slice(1))) { | ||
this[name] = undefined$1; | ||
} | ||
} | ||
} | ||
reset: function (skipTempReset) { | ||
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); | ||
}, | ||
stop: function() { | ||
this.done = true; | ||
var rootEntry = this.tryEntries[0]; | ||
var rootRecord = rootEntry.completion; | ||
if (rootRecord.type === "throw") { | ||
throw rootRecord.arg; | ||
} | ||
stop: function () { | ||
this.done = !0; | ||
var rootRecord = this.tryEntries[0].completion; | ||
if ("throw" === rootRecord.type) throw rootRecord.arg; | ||
return this.rval; | ||
}, | ||
dispatchException: function(exception) { | ||
if (this.done) { | ||
throw exception; | ||
} | ||
dispatchException: function (exception) { | ||
if (this.done) throw exception; | ||
var context = this; | ||
function handle(loc, caught) { | ||
record.type = "throw"; | ||
record.arg = exception; | ||
context.next = loc; | ||
if (caught) { | ||
// If the dispatched exception was caught by a catch block, | ||
// then let that catch block handle the exception normally. | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
return !! caught; | ||
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
if (entry.tryLoc === "root") { | ||
// Exception thrown outside of any try block that could handle | ||
// it, so set the completion value of the entire function to | ||
// throw the exception. | ||
return handle("end"); | ||
} | ||
var entry = this.tryEntries[i], | ||
record = entry.completion; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"); | ||
var hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} else if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} | ||
} else if (hasFinally) { | ||
if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
} else { | ||
throw new Error("try statement without catch or finally"); | ||
if (!hasFinally) throw new Error("try statement without catch or finally"); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} | ||
@@ -668,9 +263,6 @@ } | ||
}, | ||
abrupt: function(type, arg) { | ||
abrupt: function (type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && | ||
hasOwn.call(entry, "finallyLoc") && | ||
this.prev < entry.finallyLoc) { | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
@@ -680,57 +272,17 @@ break; | ||
} | ||
if (finallyEntry && | ||
(type === "break" || | ||
type === "continue") && | ||
finallyEntry.tryLoc <= arg && | ||
arg <= finallyEntry.finallyLoc) { | ||
// Ignore the finally entry if control is not jumping to a | ||
// location outside the try/catch block. | ||
finallyEntry = null; | ||
} | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
record.type = type; | ||
record.arg = arg; | ||
if (finallyEntry) { | ||
this.method = "next"; | ||
this.next = finallyEntry.finallyLoc; | ||
return ContinueSentinel; | ||
} | ||
return this.complete(record); | ||
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); | ||
}, | ||
complete: function(record, afterLoc) { | ||
if (record.type === "throw") { | ||
throw record.arg; | ||
} | ||
if (record.type === "break" || | ||
record.type === "continue") { | ||
this.next = record.arg; | ||
} else if (record.type === "return") { | ||
this.rval = this.arg = record.arg; | ||
this.method = "return"; | ||
this.next = "end"; | ||
} else if (record.type === "normal" && afterLoc) { | ||
this.next = afterLoc; | ||
} | ||
return ContinueSentinel; | ||
complete: function (record, afterLoc) { | ||
if ("throw" === record.type) throw record.arg; | ||
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; | ||
}, | ||
finish: function(finallyLoc) { | ||
finish: function (finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) { | ||
this.complete(entry.completion, entry.afterLoc); | ||
resetTryEntry(entry); | ||
return ContinueSentinel; | ||
} | ||
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; | ||
} | ||
}, | ||
"catch": function(tryLoc) { | ||
catch: function (tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
@@ -740,3 +292,3 @@ var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
if (record.type === "throw") { | ||
if ("throw" === record.type) { | ||
var thrown = record.arg; | ||
@@ -748,59 +300,43 @@ resetTryEntry(entry); | ||
} | ||
// The context.catch method must only be called with a location | ||
// argument that corresponds to a known catch block. | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function(iterable, resultName, nextLoc) { | ||
this.delegate = { | ||
delegateYield: function (iterable, resultName, nextLoc) { | ||
return this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}; | ||
if (this.method === "next") { | ||
// Deliberately forget the last sent value so that we don't | ||
// accidentally pass it on to the delegate. | ||
this.arg = undefined$1; | ||
} | ||
return ContinueSentinel; | ||
}, "next" === this.method && (this.arg = undefined), ContinueSentinel; | ||
} | ||
}; | ||
// Regardless of whether this script is executing as a CommonJS module | ||
// or not, return the runtime object so that we can declare the variable | ||
// regeneratorRuntime in the outer scope, which allows this module to be | ||
// injected easily by `bin/regenerator --include-runtime script.js`. | ||
return exports; | ||
}( | ||
// If this script is executing as a CommonJS module, use module.exports | ||
// as the regeneratorRuntime namespace. Otherwise create a new empty | ||
// object. Either way, the resulting object will be used to initialize | ||
// the regeneratorRuntime variable at the top of this file. | ||
module.exports | ||
)); | ||
try { | ||
regeneratorRuntime = runtime; | ||
} catch (accidentalStrictMode) { | ||
// This module should not be running in strict mode, so the above | ||
// assignment should always work unless something is misconfigured. Just | ||
// in case runtime.js accidentally runs in strict mode, in modern engines | ||
// we can explicitly access globalThis. In older engines we can escape | ||
// strict mode using a global Function call. This could conceivably fail | ||
// if a Content Security Policy forbids using Function, but in that case | ||
// the proper solution is to fix the accidental strict mode problem. If | ||
// you've misconfigured your bundler to force strict mode and applied a | ||
// CSP to forbid Function, and you're not willing to fix either of those | ||
// problems, please detail your unique predicament in a GitHub issue. | ||
if (typeof globalThis === "object") { | ||
globalThis.regeneratorRuntime = runtime; | ||
}, exports; | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Function("r", "regeneratorRuntime = r")(runtime); | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
}); | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
@@ -813,13 +349,13 @@ var defaultCacheMethods = ["findUnique", "findFirst", "findMany", "count", "aggregate", "groupBy", "findRaw", "aggregateRaw"]; | ||
var models = _ref.models, | ||
onDedupe = _ref.onDedupe, | ||
onError = _ref.onError, | ||
onHit = _ref.onHit, | ||
onMiss = _ref.onMiss, | ||
storage = _ref.storage, | ||
_ref$cacheTime = _ref.cacheTime, | ||
cacheTime = _ref$cacheTime === void 0 ? DEFAULT_CACHE_TIME : _ref$cacheTime, | ||
_ref$excludeModels = _ref.excludeModels, | ||
excludeModels = _ref$excludeModels === void 0 ? [] : _ref$excludeModels, | ||
_ref$excludeMethods = _ref.excludeMethods, | ||
excludeMethods = _ref$excludeMethods === void 0 ? [] : _ref$excludeMethods; | ||
onDedupe = _ref.onDedupe, | ||
onError = _ref.onError, | ||
onHit = _ref.onHit, | ||
onMiss = _ref.onMiss, | ||
storage = _ref.storage, | ||
_ref$cacheTime = _ref.cacheTime, | ||
cacheTime = _ref$cacheTime === void 0 ? DEFAULT_CACHE_TIME : _ref$cacheTime, | ||
_ref$excludeModels = _ref.excludeModels, | ||
excludeModels = _ref$excludeModels === void 0 ? [] : _ref$excludeModels, | ||
_ref$excludeMethods = _ref.excludeMethods, | ||
excludeMethods = _ref$excludeMethods === void 0 ? [] : _ref$excludeMethods; | ||
// Default options for "async-cache-dedupe" | ||
@@ -835,246 +371,196 @@ var cacheOptions = { | ||
var cache = createCache(cacheOptions); | ||
var middleware = /*#__PURE__*/function () { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(params, next) { | ||
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params, next) { | ||
var result, fetchFromPrisma, excludedCacheMethods, _excludedCacheMethods, excludedCacheMethodsInModels, cacheFunction; | ||
return runtime_1.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
// This function is used by `async-cache-dedupe` to fetch data when the cache is empty | ||
fetchFromPrisma = /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(params) { | ||
return runtime_1.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", next(params)); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function fetchFromPrisma(_x3) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); // Do not cache any Prisma method specified in the defaultExcludeCacheMethods option | ||
excludedCacheMethods = defaultCacheMethods.filter(function (cacheMethod) { | ||
return excludeMethods.includes(cacheMethod); | ||
}); // Do not cache any Prisma method that has been excluded | ||
if (!(excludedCacheMethods != null && excludedCacheMethods.includes(params.action))) { | ||
// Add a cache function for each model specified in the models option | ||
models == null ? void 0 : models.forEach(function (_ref4) { | ||
var model = _ref4.model, | ||
cacheTime = _ref4.cacheTime, | ||
cacheKey = _ref4.cacheKey, | ||
excludeMethods = _ref4.excludeMethods; | ||
// Only define the cache function for a model if it doesn't exist yet and hasn't been excluded | ||
if (!cache[model] && model === params.model && !(excludeModels != null && excludeModels.includes(params.model)) && !(excludeMethods != null && excludeMethods.includes(params.action))) { | ||
cache.define(model, { | ||
references: function references(_ref5, key) { | ||
var params = _ref5.params; | ||
return [(cacheKey || params.model) + "~" + key]; | ||
}, | ||
ttl: cacheTime || cacheOptions.ttl | ||
}, /*#__PURE__*/function () { | ||
var _modelsFetch = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref6) { | ||
var cb, params; | ||
return runtime_1.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cb = _ref6.cb, params = _ref6.params; | ||
_context2.next = 3; | ||
return cb(params); | ||
case 3: | ||
result = _context2.sent; | ||
return _context2.abrupt("return", result); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
})); | ||
function modelsFetch(_x4) { | ||
return _modelsFetch.apply(this, arguments); | ||
} | ||
return modelsFetch; | ||
}()); | ||
return _regeneratorRuntime().wrap(function _callee6$(_context6) { | ||
while (1) switch (_context6.prev = _context6.next) { | ||
case 0: | ||
// This function is used by `async-cache-dedupe` to fetch data when the cache is empty | ||
fetchFromPrisma = /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) { | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", next(params)); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}); // For each defined model in `models` we check if they defined any caching methods to be excluded | ||
excludedCacheMethodsInModels = models == null ? void 0 : models.find(function (_ref7) { | ||
var model = _ref7.model, | ||
excludeMethods = _ref7.excludeMethods; | ||
return model === params.model && (excludeMethods == null ? void 0 : excludeMethods.length); | ||
}); // Do not define a cache function for any Prisma model if it already exists | ||
// Do not define the cache function for a model if it was excluded in `defaultExcludeCacheModels` | ||
// Do not define a cache function if the Prisma method was exluded in `models` | ||
if (!cache[params.model] && !(excludeModels != null && excludeModels.includes(params.model)) && !(excludedCacheMethodsInModels != null && (_excludedCacheMethods = excludedCacheMethodsInModels.excludeMethods) != null && _excludedCacheMethods.includes(params.action))) { | ||
cache.define(params.model, { | ||
references: function references(_ref8, key) { | ||
var params = _ref8.params; | ||
return [params.model + "~" + key]; | ||
} | ||
}, _callee); | ||
})); | ||
return function fetchFromPrisma(_x3) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); // Do not cache any Prisma method specified in the defaultExcludeCacheMethods option | ||
excludedCacheMethods = defaultCacheMethods.filter(function (cacheMethod) { | ||
return excludeMethods.includes(cacheMethod); | ||
}); // Do not cache any Prisma method that has been excluded | ||
if (!(excludedCacheMethods != null && excludedCacheMethods.includes(params.action))) { | ||
// Add a cache function for each model specified in the models option | ||
models == null ? void 0 : models.forEach(function (_ref4) { | ||
var model = _ref4.model, | ||
cacheTime = _ref4.cacheTime, | ||
cacheKey = _ref4.cacheKey, | ||
excludeMethods = _ref4.excludeMethods; | ||
// Only define the cache function for a model if it doesn't exist yet and hasn't been excluded | ||
if (!cache[model] && model === params.model && !(excludeModels != null && excludeModels.includes(params.model)) && !(excludeMethods != null && excludeMethods.includes(params.action))) { | ||
cache.define(model, { | ||
references: function references(_ref5, key) { | ||
var params = _ref5.params; | ||
return [(cacheKey || params.model) + "~" + key]; | ||
}, | ||
ttl: cacheTime || cacheOptions.ttl | ||
}, /*#__PURE__*/function () { | ||
var _modelFetch = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_ref9) { | ||
var _modelsFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref6) { | ||
var cb, params; | ||
return runtime_1.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
cb = _ref9.cb, params = _ref9.params; | ||
_context3.next = 3; | ||
return cb(params); | ||
case 3: | ||
result = _context3.sent; | ||
return _context3.abrupt("return", result); | ||
case 5: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cb = _ref6.cb, params = _ref6.params; | ||
_context2.next = 3; | ||
return cb(params); | ||
case 3: | ||
result = _context2.sent; | ||
return _context2.abrupt("return", result); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee3); | ||
}, _callee2); | ||
})); | ||
function modelFetch(_x5) { | ||
return _modelFetch.apply(this, arguments); | ||
function modelsFetch(_x4) { | ||
return _modelsFetch.apply(this, arguments); | ||
} | ||
return modelFetch; | ||
return modelsFetch; | ||
}()); | ||
} | ||
} // Get the cache function relating to the Prisma model | ||
cacheFunction = cache[params.model]; // Only cache the data if the Prisma model hasn't been excluded and if the Prisma method wasn't excluded either | ||
if (!(!(excludeModels != null && excludeModels.includes(params.model)) && !(excludedCacheMethods != null && excludedCacheMethods.includes(params.action)) && !(defaultMutationMethods != null && defaultMutationMethods.includes(params.action)) && typeof cacheFunction === "function")) { | ||
_context6.next = 19; | ||
break; | ||
}); | ||
// For each defined model in `models` we check if they defined any caching methods to be excluded | ||
excludedCacheMethodsInModels = models == null ? void 0 : models.find(function (_ref7) { | ||
var model = _ref7.model, | ||
excludeMethods = _ref7.excludeMethods; | ||
return model === params.model && (excludeMethods == null ? void 0 : excludeMethods.length); | ||
}); // Do not define a cache function for any Prisma model if it already exists | ||
// Do not define the cache function for a model if it was excluded in `defaultExcludeCacheModels` | ||
// Do not define a cache function if the Prisma method was exluded in `models` | ||
if (!cache[params.model] && !(excludeModels != null && excludeModels.includes(params.model)) && !(excludedCacheMethodsInModels != null && (_excludedCacheMethods = excludedCacheMethodsInModels.excludeMethods) != null && _excludedCacheMethods.includes(params.action))) { | ||
cache.define(params.model, { | ||
references: function references(_ref8, key) { | ||
var params = _ref8.params; | ||
return [params.model + "~" + key]; | ||
} | ||
}, /*#__PURE__*/function () { | ||
var _modelFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref9) { | ||
var cb, params; | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
cb = _ref9.cb, params = _ref9.params; | ||
_context3.next = 3; | ||
return cb(params); | ||
case 3: | ||
result = _context3.sent; | ||
return _context3.abrupt("return", result); | ||
case 5: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3); | ||
})); | ||
function modelFetch(_x5) { | ||
return _modelFetch.apply(this, arguments); | ||
} | ||
return modelFetch; | ||
}()); | ||
} | ||
_context6.prev = 5; | ||
_context6.next = 8; | ||
return cacheFunction({ | ||
cb: fetchFromPrisma, | ||
params: params | ||
}); | ||
case 8: | ||
result = _context6.sent; | ||
_context6.next = 17; | ||
} | ||
// Get the cache function relating to the Prisma model | ||
cacheFunction = cache[params.model]; // Only cache the data if the Prisma model hasn't been excluded and if the Prisma method wasn't excluded either | ||
if (!(!(excludeModels != null && excludeModels.includes(params.model)) && !(excludedCacheMethods != null && excludedCacheMethods.includes(params.action)) && !(defaultMutationMethods != null && defaultMutationMethods.includes(params.action)) && typeof cacheFunction === "function")) { | ||
_context6.next = 19; | ||
break; | ||
case 11: | ||
_context6.prev = 11; | ||
_context6.t0 = _context6["catch"](5); | ||
_context6.next = 15; | ||
return fetchFromPrisma(params); | ||
case 15: | ||
result = _context6.sent; | ||
console.error(_context6.t0); | ||
case 17: | ||
} | ||
_context6.prev = 5; | ||
_context6.next = 8; | ||
return cacheFunction({ | ||
cb: fetchFromPrisma, | ||
params: params | ||
}); | ||
case 8: | ||
result = _context6.sent; | ||
_context6.next = 17; | ||
break; | ||
case 11: | ||
_context6.prev = 11; | ||
_context6.t0 = _context6["catch"](5); | ||
_context6.next = 15; | ||
return fetchFromPrisma(params); | ||
case 15: | ||
result = _context6.sent; | ||
console.error(_context6.t0); | ||
case 17: | ||
_context6.next = 27; | ||
break; | ||
case 19: | ||
_context6.next = 21; | ||
return fetchFromPrisma(params); | ||
case 21: | ||
result = _context6.sent; | ||
if (!defaultMutationMethods.includes(params.action)) { | ||
_context6.next = 27; | ||
break; | ||
case 19: | ||
_context6.next = 21; | ||
return fetchFromPrisma(params); | ||
case 21: | ||
result = _context6.sent; | ||
if (!defaultMutationMethods.includes(params.action)) { | ||
_context6.next = 27; | ||
break; | ||
} | ||
_context6.next = 25; | ||
return cache.invalidateAll("*" + params.model + "~*"); | ||
case 25: | ||
_context6.next = 27; | ||
return Promise.all((models || []).filter(function (_ref10) { | ||
var model = _ref10.model; | ||
return model === params.model; | ||
}).map( /*#__PURE__*/function () { | ||
var _ref12 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(_ref11) { | ||
var invalidateRelated; | ||
return runtime_1.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
invalidateRelated = _ref11.invalidateRelated; | ||
if (!invalidateRelated) { | ||
_context5.next = 4; | ||
break; | ||
} | ||
_context5.next = 4; | ||
return Promise.all(invalidateRelated.map( /*#__PURE__*/function () { | ||
var _ref13 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(relatedModel) { | ||
return runtime_1.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return _context4.abrupt("return", cache.invalidateAll("*" + relatedModel + "~*")); | ||
case 1: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4); | ||
})); | ||
return function (_x7) { | ||
return _ref13.apply(this, arguments); | ||
}; | ||
}())); | ||
case 4: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
_context6.next = 25; | ||
return cache.invalidateAll("*" + params.model + "~*"); | ||
case 25: | ||
_context6.next = 27; | ||
return Promise.all((models || []).filter(function (_ref10) { | ||
var model = _ref10.model; | ||
return model === params.model; | ||
}).map( /*#__PURE__*/function () { | ||
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref11) { | ||
var invalidateRelated; | ||
return _regeneratorRuntime().wrap(function _callee5$(_context5) { | ||
while (1) switch (_context5.prev = _context5.next) { | ||
case 0: | ||
invalidateRelated = _ref11.invalidateRelated; | ||
if (!invalidateRelated) { | ||
_context5.next = 4; | ||
break; | ||
} | ||
} | ||
}, _callee5); | ||
})); | ||
return function (_x6) { | ||
return _ref12.apply(this, arguments); | ||
}; | ||
}())); | ||
case 27: | ||
return _context6.abrupt("return", result); | ||
case 28: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
_context5.next = 4; | ||
return Promise.all(invalidateRelated.map( /*#__PURE__*/function () { | ||
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(relatedModel) { | ||
return _regeneratorRuntime().wrap(function _callee4$(_context4) { | ||
while (1) switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return _context4.abrupt("return", cache.invalidateAll("*" + relatedModel + "~*")); | ||
case 1: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, _callee4); | ||
})); | ||
return function (_x7) { | ||
return _ref13.apply(this, arguments); | ||
}; | ||
}())); | ||
case 4: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
}, _callee5); | ||
})); | ||
return function (_x6) { | ||
return _ref12.apply(this, arguments); | ||
}; | ||
}())); | ||
case 27: | ||
return _context6.abrupt("return", result); | ||
case 28: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
}, _callee6, null, [[5, 11]]); | ||
})); | ||
return function middleware(_x, _x2) { | ||
@@ -1084,3 +570,2 @@ return _ref2.apply(this, arguments); | ||
}(); | ||
return middleware; | ||
@@ -1087,0 +572,0 @@ }; |
{ | ||
"name": "prisma-redis-middleware", | ||
"author": "A-J Roos <asjas@hey.com>", | ||
"version": "4.6.0", | ||
"version": "4.6.1", | ||
"description": "Prisma Middleware for caching results of queries in Redis", | ||
@@ -18,3 +18,3 @@ "license": "Hippocratic-3.0", | ||
"build": "tsdx build", | ||
"clean": "rimraf dist", | ||
"clean": "rimraf dist/ coverage/", | ||
"prepare": "tsdx build", | ||
@@ -25,8 +25,6 @@ "test": "vitest run", | ||
"check-types": "tsc", | ||
"lint": "eslint --ext .ts .", | ||
"lint-fix": "npm run lint -- --fix", | ||
"prettier": "prettier --ignore-path .eslintignore \"**/*.+(ts)\"", | ||
"prettier": "prettier --cache \"**/**/*.+(json|ts)\"", | ||
"format": "npm run prettier -- --write", | ||
"check-format": "npm run prettier -- --list-different", | ||
"validate": "npm-run-all --parallel check-types check-format lint build", | ||
"validate": "npm-run-all --parallel check-types check-format build", | ||
"size": "size-limit", | ||
@@ -36,22 +34,23 @@ "analyze": "size-limit --why" | ||
"dependencies": { | ||
"async-cache-dedupe": "1.8.0", | ||
"ioredis": "5.2.5" | ||
"async-cache-dedupe": "1.9.0", | ||
"ioredis": "5.3.1" | ||
}, | ||
"devDependencies": { | ||
"@prisma/client": "4.9.0", | ||
"@size-limit/preset-small-lib": "8.1.2", | ||
"@ianvs/prettier-plugin-sort-imports": "3.7.1", | ||
"@prisma/client": "4.10.1", | ||
"@size-limit/preset-small-lib": "8.2.4", | ||
"@types/ioredis-mock": "8.2.1", | ||
"@vitest/coverage-c8": "0.28.1", | ||
"c8": "7.12.0", | ||
"eslint-config-asjas": "2.0.3", | ||
"@vitest/coverage-c8": "0.28.5", | ||
"c8": "7.13.0", | ||
"husky": "8.0.3", | ||
"ioredis-mock": "8.2.2", | ||
"lint-staged": "13.1.0", | ||
"ioredis-mock": "8.2.6", | ||
"lint-staged": "13.1.2", | ||
"npm-run-all": "4.1.5", | ||
"prettier": "2.8.4", | ||
"rimraf": "4.1.2", | ||
"size-limit": "8.1.2", | ||
"size-limit": "8.2.4", | ||
"tsdx": "0.14.1", | ||
"tslib": "2.4.1", | ||
"typescript": "4.9.4", | ||
"vitest": "0.28.1" | ||
"tslib": "2.5.0", | ||
"typescript": "4.9.5", | ||
"vitest": "0.28.5" | ||
}, | ||
@@ -64,5 +63,2 @@ "husky": { | ||
"lint-staged": { | ||
"*.+(ts)": [ | ||
"eslint" | ||
], | ||
"**/**/*.+(ts)": [ | ||
@@ -85,3 +81,3 @@ "prettier --write", | ||
"node": "^16.x || ^18.x", | ||
"npm": "^7.x || ^8.x || ^9.0.0" | ||
"npm": "^7.x || ^8.x || ^9.x" | ||
}, | ||
@@ -88,0 +84,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
import type { PrismaQueryAction, PrismaMutationAction } from "./types"; | ||
import type { PrismaMutationAction, PrismaQueryAction } from "./types"; | ||
@@ -3,0 +3,0 @@ export const defaultCacheMethods: PrismaQueryAction[] = [ |
import { createCache } from "async-cache-dedupe"; | ||
import { defaultCacheMethods, defaultMutationMethods } from "./cacheMethods"; | ||
import type { | ||
@@ -11,4 +10,4 @@ CreatePrismaRedisCache, | ||
PrismaAction, | ||
PrismaMutationAction, | ||
PrismaQueryAction, | ||
PrismaMutationAction, | ||
Result, | ||
@@ -15,0 +14,0 @@ } from "./types"; |
import type Redis from "ioredis"; | ||
import type { Prisma } from "@prisma/client"; | ||
@@ -3,0 +4,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
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
0
137162
17
1500
+ Addedasync-cache-dedupe@1.9.0(transitive)
+ Addedioredis@5.3.1(transitive)
- Removedabstract-logging@2.0.1(transitive)
- Removedasync-cache-dedupe@1.8.0(transitive)
- Removedioredis@5.2.5(transitive)
Updatedasync-cache-dedupe@1.9.0
Updatedioredis@5.3.1