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T,EAAQ,QAAQ,uBAAwB,KACtC,EAAQ,MAAM,mBAChB,EAAQ,QAAQ,kBAAmB,MAGrC,CACT,CAWA,SAAS,cAAe,GACtB,SAAU,GACoC,oBAA1C,OAAO,UAAU,SAAS,KAAK,KAC/B,OAAO,OAAO,EAAO,UAC3B,CAEA,MAAM,sBAAwB,gDAW9B,SAAS,iBAAkB,GACzB,IAAK,EAAO,OAAO,EAEnB,IAAI,GAAS,EACb,MAAM,EAAY,OAAO,UAAU,SAAS,KAAK,GASjD,OAPE,GAD4C,IAA1C,sBAAsB,KAAK,KAEpB,OAAO,OAAO,EAAO,WACrB,iBAAiB,EAAM,SAEvB,cAAc,IAGlB,CACT,CAEA,SAAS,WAAY,GACnB,OAA+B,IAA3B,cAAc,GACT,eAAgB,EAAS,GAC9B,EAAQ,MAAM,EAChB,EAGK,CACT,CAEA,SAAS,YAAa,GAQpB,OAJI,aAAe,cACjB,EAAI,SAAW,OAAS,EAAI,MAAM,MAAM,KAAM,GAAG,IAG5C,CACT,CAEA,eAAe,eAAgB,GAC7B,MAAM,EAAc,EAAI,MAAM,KAO9B,IAFA,EAAY,GAAwB,KAAnB,EAAY,GAAY,EAAY,GAAK,IAEnD,EAAY,OAAS,GAAG,CAC7B,MAAM,EAAW,QAAQ,EAAa,gBAEhC,QAAqB,SAAS,EAAU,SAC3C,OAAM,IAAM,OAEf,GAAI,EACF,OAAO,KAAK,MAAM,GAAc,KAGlC,EAAY,KACd,CACF,CAIA,gBAAgB,OAAO,IAAI,mBAAoB,EAE/C,OAAO,QAAU,gBACjB,OAAO,QAAQ,gBAAkB,gBACjC,OAAO,QAAQ,QAAU","file":"/npm/@fastify/autoload@6.3.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@fastify/autoload@6.3.1/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 { readFile } = require('node:fs/promises')\nconst { join, sep } = require('node:path')\nconst findPlugins = require('./lib/find-plugins')\nconst runtime = require('./lib/runtime')\nconst { pathToFileURL } = require('node:url')\n\nconst defaults = {\n  scriptPattern: /(?:(?:^.?|\\.[^d]|[^.]d|[^.][^d])\\.ts|\\.js|\\.cjs|\\.mjs|\\.cts|\\.mts)$/iu,\n  indexPattern: /^index(?:\\.ts|\\.js|\\.cjs|\\.mjs|\\.cts|\\.mts)$/iu,\n  autoHooksPattern: /^[_.]?auto_?hooks(?:\\.ts|\\.js|\\.cjs|\\.mjs|\\.cts|\\.mts)$/iu,\n  dirNameRoutePrefix: true,\n  encapsulate: true\n}\n\nconst fastifyAutoload = async function autoload (fastify, options) {\n  const packageType = await getPackageType(options.dir)\n  const opts = { ...defaults, packageType, ...options }\n  const pluginTree = await findPlugins(opts.dir, { opts })\n\n  await loadPlugins({ pluginTree, options, opts, fastify })\n}\n\nasync function loadPlugins ({ pluginTree, options, opts, fastify }) {\n  const nodes = []\n  const pluginsMeta = {}\n  for (const key in pluginTree) {\n    const node = {\n      ...pluginTree[key],\n      pluginsMeta,\n      hooksMeta: {}\n    }\n    nodes.push(node)\n\n    await Promise.all(node.plugins.map(({ file, type, prefix }) => {\n      return loadPlugin({ file, type, directoryPrefix: prefix, options: opts, log: fastify.log })\n        .then((plugin) => {\n          if (plugin) {\n            // create route parameters from prefixed folders\n            if (options.routeParams && plugin.options.prefix) {\n              plugin.options.prefix = replaceRouteParamPattern(plugin.options.prefix)\n            }\n            node.pluginsMeta[plugin.name] = plugin\n          }\n        })\n        .catch((err) => {\n          throw enrichError(err)\n        })\n    }))\n\n    await Promise.all(node.hooks.map((h) => {\n      return loadHook(h, opts)\n        .then((hookPlugin) => {\n          node.hooksMeta[h.file] = hookPlugin\n        })\n        .catch((err) => {\n          throw enrichError(err)\n        })\n    }))\n  }\n\n  for (const node of nodes) {\n    registerNode(node, fastify)\n  }\n}\n\nasync function loadPlugin ({ file, type, directoryPrefix, options, log }) {\n  const { options: overrideConfig, forceESM, encapsulate } = options\n  const importedAsModule = forceESM || type === 'module' || runtime.forceESM\n  let content\n  if (importedAsModule) {\n    content = await import(pathToFileURL(file).href)\n  } else {\n    content = require(file)\n  }\n\n  if (isPluginOrModule(importedAsModule ? content.default : content) === false) {\n    // We must have something that resembles a Fastify plugin function, or that\n    // can be converted into one, that can eventually be passed to `avvio`. If\n    // it is anything else, skip automatic loading of this item.\n    log.debug({ file }, 'skipping autoloading of file because it does not export a Fastify plugin compatible shape')\n    return\n  }\n\n  const plugin = wrapRoutes(content.default || content)\n  const pluginOptions = loadPluginOptions(content, overrideConfig)\n  const pluginMeta = plugin[Symbol.for('plugin-meta')] || {}\n\n  if (!encapsulate) {\n    plugin[Symbol.for('skip-override')] = true\n  }\n\n  if (plugin.autoload === false || content.autoload === false) {\n    log.debug({ file }, 'skipping autoload due to `autoload: false` being set')\n    return\n  }\n\n  // Reset to support overriding autoConfig for library plugins\n  if (plugin.autoConfig !== undefined) {\n    plugin.autoConfig = undefined\n  }\n\n  handlePrefixConfig({ plugin, pluginOptions, content, directoryPrefix })\n\n  return {\n    plugin,\n    filename: file,\n    name: pluginMeta.name || file,\n    dependencies: pluginMeta.dependencies,\n    options: pluginOptions,\n    registered: false\n  }\n}\n\nasync function loadHook (hook, options) {\n  let hookContent\n  if (options.forceESM || hook.type === 'module' || runtime.forceESM) {\n    hookContent = await import(pathToFileURL(hook.file).href)\n  } else {\n    hookContent = require(hook.file)\n  }\n\n  hookContent = hookContent.default || hookContent\n\n  const type = Object.prototype.toString.call(hookContent)\n  if (type === '[object AsyncFunction]' || type === '[object Function]') {\n    hookContent[Symbol.for('skip-override')] = true\n  }\n\n  return hookContent\n}\n\nfunction registerNode (node, fastify) {\n  if (node.hooks.length === 0) {\n    registerAllPlugins(fastify, node)\n  } else {\n    const composedPlugin = async function (app) {\n      // find hook functions for this prefix\n      for (const hookFile of node.hooks) {\n        const hookPlugin = node.hooksMeta[hookFile.file]\n        // encapsulate hooks at plugin level\n        app.register(hookPlugin)\n      }\n\n      registerAllPlugins(app, node)\n    }\n    fastify.register(composedPlugin)\n  }\n}\n\nfunction registerAllPlugins (app, node) {\n  const metas = Object.values(node.pluginsMeta)\n  for (const pluginFile of node.plugins) {\n    // find plugins for this prefix, based on filename stored in registerPlugins()\n    const plugin = metas.find((i) => i.filename === pluginFile.file)\n    // register plugins at fastify level\n    if (plugin) registerPlugin(app, plugin, node.pluginsMeta)\n  }\n}\n\nfunction registerPlugin (fastify, meta, allPlugins, parentPlugins = {}) {\n  const { plugin, name, options, dependencies = [] } = meta\n\n  if (parentPlugins[name]) {\n    throw new Error('Cyclic dependency')\n  }\n\n  if (meta.registered) {\n    return\n  }\n\n  parentPlugins[name] = true\n  for (const name of dependencies) {\n    if (allPlugins[name]) {\n      // we create a shallow copy of parentPlugins so we can load once the ones that are\n      // on two different dependency chains\n      registerPlugin(fastify, allPlugins[name], allPlugins, { ...parentPlugins })\n    }\n  }\n\n  fastify.register(plugin, options)\n\n  meta.registered = true\n}\n\nfunction loadPluginOptions (content, overrideConfig) {\n  const pluginConfig = (content.default?.autoConfig) || content.autoConfig || {}\n  if (typeof pluginConfig === 'function') {\n    const pluginOptions = (fastify) => ({ ...pluginConfig(fastify), ...overrideConfig })\n    pluginOptions.prefix = overrideConfig.prefix ?? pluginConfig.prefix\n\n    return pluginOptions\n  }\n\n  return { ...pluginConfig, ...overrideConfig }\n}\n\nfunction handlePrefixConfig ({ plugin, pluginOptions, content, directoryPrefix }) {\n  if (pluginOptions.prefix?.endsWith('/')) {\n    pluginOptions.prefix = pluginOptions.prefix.slice(0, -1)\n  }\n\n  let prefix\n  if (plugin.autoPrefix !== undefined) {\n    prefix = plugin.autoPrefix\n  } else if (content.autoPrefix !== undefined) {\n    prefix = content.autoPrefix\n  } else {\n    prefix = directoryPrefix\n  }\n\n  const prefixOverride = plugin.prefixOverride ?? content.prefixOverride\n  if (prefixOverride !== undefined) {\n    pluginOptions.prefix = prefixOverride\n  } else if (prefix) {\n    pluginOptions.prefix = (pluginOptions.prefix || '') + prefix.replace(/\\/+/gu, '/')\n  }\n}\n\nconst routeParamPattern = /\\/_/gu\nconst routeMixedParamPattern = /__/gu\nfunction replaceRouteParamPattern (pattern) {\n  if (pattern.match(routeMixedParamPattern)) {\n    return pattern.replace(routeMixedParamPattern, ':')\n  } else if (pattern.match(routeParamPattern)) {\n    return pattern.replace(routeParamPattern, '/:')\n  }\n\n  return pattern\n}\n\n/**\n * Used to determine if the contents of a required autoloaded file matches\n * the shape of a Fastify route configuration object.\n *\n * @param {*} input The data to check.\n *\n * @returns {boolean} True if the data represents a route configuration object.\n * False otherwise.\n */\nfunction isRouteObject (input) {\n  return !!(input &&\n      Object.prototype.toString.call(input) === '[object Object]' &&\n      Object.hasOwn(input, 'method'))\n}\n\nconst pluginOrModulePattern = /\\[object (?:AsyncFunction|Function|Module)\\]/u\n/**\n * Used to determine if the contents of a required autoloaded file is a valid\n * plugin or route configuration object. In the case of a route configuration\n * object, it will later be wrapped into a plugin.\n *\n * @param {*} input The data to check.\n *\n * @returns {boolean} True if the object can be used by the autoload system by\n * eventually passing it into `avvio`. False otherwise.\n */\nfunction isPluginOrModule (input) {\n  if (!input) return false\n\n  let result = false\n  const inputType = Object.prototype.toString.call(input)\n  if (pluginOrModulePattern.test(inputType) === true) {\n    result = true\n  } else if (Object.hasOwn(input, 'default')) {\n    result = isPluginOrModule(input.default)\n  } else {\n    result = isRouteObject(input)\n  }\n\n  return result\n}\n\nfunction wrapRoutes (content) {\n  if (isRouteObject(content) === true) {\n    return async function (fastify, opts) {\n      fastify.route(content)\n    }\n  }\n\n  return content\n}\n\nfunction enrichError (err) {\n  // Hack SyntaxError message so that we provide\n  // the line number to the user, otherwise they\n  // will be left in the cold.\n  if (err instanceof SyntaxError) {\n    err.message += ' at ' + err.stack.split('\\n', 1)[0]\n  }\n\n  return err\n}\n\nasync function getPackageType (cwd) {\n  const directories = cwd.split(sep)\n\n  /* c8 ignore start */\n  // required for paths that begin with the sep, such as linux root\n  // ignore because OS specific evaluation\n  directories[0] = directories[0] !== '' ? directories[0] : sep\n  /* c8 ignore stop */\n  while (directories.length > 0) {\n    const filePath = join(...directories, 'package.json')\n\n    const fileContents = await readFile(filePath, 'utf-8')\n      .catch(() => null)\n\n    if (fileContents) {\n      return JSON.parse(fileContents).type\n    }\n\n    directories.pop()\n  }\n}\n\n// do not create a new context, do not encapsulate\n// same as fastify-plugin\nfastifyAutoload[Symbol.for('skip-override')] = true\n\nmodule.exports = fastifyAutoload\nmodule.exports.fastifyAutoload = fastifyAutoload\nmodule.exports.default = fastifyAutoload\n"]}