{"version":3,"sources":["jsdelivr-header.js","/npm/express-exorcism@0.1.2/src/express-exorcism.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,QAAU,QAAQ,WAAW,OAAO,OAEpC,OAAS,eAET,cAAgB,CAEpB,wBAAwB,EAExB,gBAAiB,QAIjB,sBAAuB,OAEvB,yBAAyB,EAEzB,WAAY,QAGZ,iBAAiB,GASnB,OAAO,QAAW,CAAC,EAAS,KAE1B,MAAM,EAAS,OAAO,OAAO,CAAC,EAAG,cAAe,GAAc,CAAC,GAGzD,EAAS,EAAO,gBAAkB,EAAQ,SAAW,EAAQ,OA0DnE,OArBA,EAAO,WACJ,KAAK,IAEJ,EAAO,OAAS,GAAc,EAAO,GAC9B,KAGR,KAAK,IACJ,MAAO,CACL,KAAM,EACN,SA5CiB,EA4CM,EA5CQ,EA4CI,EAAO,sBA3CvC,YAAa,GAClB,MAAM,EAAQ,MAAM,UAAU,MAAM,KAAK,GACnC,EAAU,EAAM,MAChB,EAAiB,EAEvB,OAAK,GAAY,EAAQ,aAA4C,kBAA7B,EAAQ,YAAY,KAIrD,EAAO,OAAS,GAAc,MAAM,KAAM,EAAe,QAAO,SAAU,EAAK,EAAK,GACzF,KAAW,WACR,MAAM,IAEF,EAAO,0BACL,UAAsD,IAAX,IAE3B,SAAnB,IACC,EAAI,KAGuB,QAAnB,EACT,EAAI,MAEJ,EAAI,GAAgB,GACtB,IAED,OAAO,IACN,EAAK,EAAM,GAEjB,KAvBS,EAAO,OAAS,GAAc,MAAM,KAAM,EAwBrD,IA/BF,IAAuB,EAAc,CA6ChC,IAEF,SAAS,IAEJ,EAAO,yBACT,EAAO,EAAO,MAAQ,EAAO,SAG/B,EAAO,EAAO,gBAAkB,EAAO,KAAK,OAAO,GAAG,cAAgB,EAAO,KAAK,MAAM,IAAM,EAAO,OAAO,IAEzG,CAAM","file":"/npm/express-exorcism@0.1.2/src/express-exorcism.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/express-exorcism@0.1.2/src/express-exorcism.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const methods = require('methods').concat('all');\n\nconst PREFIX = '__exorcism__';\n\nconst defaultConfig = {\n  // Replace router methods (get, post, all ...) with new ones\n  replaceOriginalMethods: true,\n  // Method group name:\n  methodGroupName: 'async',\n  // Group by response variants: (send, json, jsonp, end)\n  // groupByResponseMethods: false,\n  // Default response method e.g. res.json(...)\n  defaultResponseMethod: 'json',\n  // Do not invoke any response method if result is empty string , false or null,\n  ignoreEmptyResolvedData: true,\n  // Replace following methods (default: all possible methods plus specific \"all\")\n  methodList: methods,\n  // When singletonRouter = true, exorcism will spawn wrapped instance of router\n  // instead of wrapping entire router\n  singletonRouter: false,\n  // Handle async functions\n  // handleAsync: true,\n  // Handle sync functions and check if they return promise or not\n  // handlePromises: true\n  // Catch synchronous function errors and returns to use them instead of res.send and next\n  // handleSync: false\n};\n\nmodule.exports =  (express, userConfig)=> {\n  // Mergin default and user configs\n  const config = Object.assign({}, defaultConfig, userConfig || {});\n\n  // Using client's router\n  const Router = config.singletonRouter ? express.Router() : express.Router;\n\n  // Wraps Router's method with async resolver\n  function methodWrapper(routerMethod, responseMethod) {\n    return function (...args) {\n      const args2 = Array.prototype.slice.call(args);\n      const handler = args2.pop();\n      const otherArguments = args2;\n\n      if (!handler || !handler.constructor || handler.constructor.name !== 'AsyncFunction') {\n        return Router[PREFIX + routerMethod].apply(this, args);\n      }\n\n      return Router[PREFIX + routerMethod].apply(this, otherArguments.concat(function (req, res, next) {\n        handler(...arguments)\n          .then((result) => {\n            if (\n              (config.ignoreEmptyResolvedData &&\n                (result === null || result === undefined || result === false)\n              ) ||\n              responseMethod === 'none' ||\n              !res[responseMethod]\n            ) {\n\n            } else if (responseMethod === 'end') {\n              res.end();\n            } else {\n              res[responseMethod](result);\n            }\n          })\n          .catch((error) => {\n            next(error);\n          });\n      }));\n    };\n  }\n\n  config.methodList\n    .map((methodName) => {\n      // Saving original method\n      Router[PREFIX + methodName] = Router[methodName];\n      return methodName;\n    })\n    // Making wrapped method\n    .map((methodName) => {\n      return {\n        name: methodName,\n        wrapped: methodWrapper(methodName, config.defaultResponseMethod),\n      };\n    })\n    .forEach((method) => {\n      // Replacing original methods\n      if (config.replaceOriginalMethods) {\n        Router[method.name] = method.wrapped;\n      }\n      // Filling group method\n      Router[config.methodGroupName + method.name.charAt(0).toUpperCase() + method.name.slice(1)] = method.wrapped;\n    });\n  return Router;\n};\n"]}