{"version":3,"sources":["jsdelivr-header.js","/npm/@rainder/koa-router@0.0.4/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAEA,MAAM,EAAI,QAAQ,UACZ,KAAO,QAAQ,QACf,YAAc,QAAQ,iBACtB,QAAU,QAAQ,eAElB,YAAc,QAAQ,sBACtB,YAAc,QAAQ,sBACtB,aAAe,QAAQ,uBACvB,YAAc,QAAQ,sBAE5B,OAAO,QAAU,SAAU,EAAU,CAAC,GACpC,EAAU,EAAE,MAAM,CAChB,OAAQ,CACN,YAAa,YACb,UAAW,YAAY,UACvB,SAAU,YAAY,WAEvB,GAEH,MAAM,EAAM,KAAK,QAAQ,EAAQ,KAC3B,EAAS,YAAY,KAAK,GAEhC,OAAO,QAAQ,CACb,YAAY,CACV,MAAO,WAET,cACA,aAAa,EAAQ,QAIvB,YACE,MAAM,EAAM,KAAK,IAAI,MAAM,KAAK,GAC1B,EAAW,EAAI,MAAM,KACrB,EAAM,CAAE,SAAU,EAAK,QAAS,KAAK,QAAS,IAAK,KAAK,IAAK,IAAK,KAAK,KAEvE,EAAW,EAAO,SAAS,GACjC,IAAK,EACH,MAAM,IAAI,EAAQ,OAAO,UAG3B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAS,OAAQ,IAAK,CACxC,MAAM,EAAO,EAAS,MAAM,EAAG,GAAG,KAAK,KACjC,EAAa,EAAO,WAAW,GACjC,UACI,EAAW,KAAK,GAE1B,CAEA,MAAM,QAAe,EAAS,KAAK,EAAK,KAAK,QAAQ,MAErD,KAAK,KAAO,GAAU,CAAC,CACzB,GACF","file":"/npm/@rainder/koa-router@0.0.4/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@rainder/koa-router@0.0.4/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst _ = require('lodash');\nconst path = require('path');\nconst koaJsonBody = require('koa-json-body');\nconst compose = require('koa-compose');\n\nconst routeLoader = require('./lib/route-loader');\nconst jsonRequest = require('./lib/json-request');\nconst jsonResponse = require('./lib/json-response');\nconst RouterError = require('./lib/router-error');\n\nmodule.exports = function (options = {}) {\n  options = _.merge({\n    errors: {\n      constructor: RouterError,\n      not_found: RouterError.NOT_FOUND,\n      internal: RouterError.INTERNAL\n    }\n  }, options);\n\n  const DIR = path.resolve(options.dir);\n  const routes = routeLoader.load(DIR);\n\n  return compose([\n    koaJsonBody({\n      limit: 1024 * 1024 * 10\n    }),\n    jsonRequest(),\n    jsonResponse(options.errors),\n    router\n  ]);\n\n  function *router() {\n    const url = this.url.split('?')[0];\n    const urlParts = url.split('/');\n    const ctx = { endpoint: url, headers: this.headers, req: this.req, res: this.res };\n\n    const endpoint = routes.endpoint[url];\n    if (!endpoint) {\n      throw new options.errors.not_found();\n    }\n\n    for (let i = 0; i < urlParts.length; i++) {\n      const part = urlParts.slice(0, i).join('/');\n      const middleware = routes.middleware[part];\n      if (middleware) {\n        yield middleware.call(ctx);\n      }\n    }\n\n    const result = yield endpoint.call(ctx, this.request.body);\n\n    this.body = result || {};\n  }\n};\n"]}