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ourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/mongoose-schema-parser@0.2.9/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","const path = require('path')\n\nconst { parseSchema } = require('./lib/schema')\nconst { format } = require('./lib/format')\n\nconst parseSchemaFromMongoose = (mongooseInstance, formatName = 'js') => {\n  if (typeof (mongooseInstance) !== 'object' || mongooseInstance.constructor.name !== 'Mongoose') {\n    throw new TypeError('mongooseInstance should be an instance of mongoose')\n  }\n\n  const modelNames = mongooseInstance.modelNames()\n\n  const databaseSchema = modelNames.reduce((schema, modelName) => {\n    const model = mongooseInstance.model(modelName)\n\n    schema[modelName] = { schema: parseSchema(model.schema) }\n\n    return schema\n  }, {})\n\n  const outputSchema = format(databaseSchema, formatName)\n\n  return outputSchema\n}\n\nconst parseSchemaFromFiles = (filePaths, formatName = 'js') => {\n  const errors = filePaths.reduce((errArray, filePath) => {\n    try {\n      require(path.resolve(filePath))\n    } catch (e) {\n      errArray.push(`Failed to require: ${filePath}`)\n    }\n\n    return errArray\n  }, [])\n\n  const mongoose = findChildModule(module, 'Mongoose')\n\n  if (!mongoose) {\n    throw new Error('Mongoose instance cannot be found')\n  }\n\n  const schema = parseSchemaFromMongoose(mongoose, formatName)\n\n  return {\n    schema,\n    errors\n  }\n}\n\n// NOTE: keep maxDepth as low as possible to prevent maximum call stack size exceeded\nconst findChildModule = (moduleItem, name, maxDepth = 3, depth = 1) => {\n  if (depth > maxDepth) return\n\n  let foundModule\n\n  for (const child of moduleItem.children) {\n    try {\n      const childModule = require(child.id)\n      const moduleName = childModule.name || childModule.constructor.name\n\n      if (moduleName === name) {\n        return childModule\n      } else {\n        throw new Error('Module does not match')\n      }\n    } catch (e) {\n      if (child.children && child.children.length > 0) {\n        const newDepth = depth + 1\n        foundModule = findChildModule(child, name, maxDepth, newDepth)\n      }\n    }\n  }\n\n  return foundModule\n}\n\nmodule.exports = {\n  findChildModule,\n  parseSchemaFromFiles,\n  parseSchemaFromMongoose\n}\n"]}