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AQ,GAC1B,MAAM,IAAI,MAAM,uBAAuB,MAGzC,OAAQ,EAAO,GAAQ,CACzB,GACD","file":"/npm/@miroculus/config@1.1.7/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@miroculus/config@1.1.7/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 fs = require('fs')\nconst path = require('path')\nconst dotenv = require('dotenv')\n\nconst isNumber = /^-?([1-9][0-9]*|0)$/\nconst booleans = ['true', 'false']\n\nconst hasOwnProperty = (obj, key) =>\n  Object.prototype.hasOwnProperty.call(obj, key)\n\n// These are the symbols used by node's inspect and assertions,\n// which should not be included when checking if an object has it as property.\n// More info: https://stackoverflow.com/questions/6511542/force-javascript-exception-error-when-reading-an-undefined-object-property#comment85913679_45322399\nconst reservedSymbols = [\n  'toJSON',\n  'valueOf',\n  'inspect',\n  Symbol.for('nodejs.util.inspect.custom'),\n  Symbol.isConcatSpreadable,\n  Symbol.toStringTag,\n  Symbol.iterator\n]\n\nconst invalidValue = (key, val) =>\n  new Error(`Invalid config value for \"${key}\": ${val}`)\n\nconst parse = (key, val, schema) => {\n  const { type, required } = schema\n\n  if (required === true) {\n    if (typeof val !== 'string') throw invalidValue(key, val)\n    if (val === '') throw invalidValue(key, val)\n    return val\n  } else {\n    if (val === undefined || val === '') {\n      if (typeof schema.default === 'function') return schema.default()\n      if (type === 'array') return schema.default || []\n      return schema.default\n    }\n    if (typeof val !== 'string') throw invalidValue(key, val)\n  }\n\n  if (type === 'string') return val\n\n  if (type === 'array') return val.split(',').map(str => str.trim())\n\n  if (type === 'number') {\n    const n = Number(val)\n    if (!isNumber.test(n)) throw invalidValue(key, val)\n    return n\n  }\n\n  if (type === 'boolean') {\n    const b = val.toLowerCase()\n    if (!booleans.includes(b)) throw invalidValue(key, val)\n    return b === 'true'\n  }\n\n  if (type === 'json') return JSON.parse(val)\n\n  throw new Error(`Invalid type \"${type}\" for \"${key}\" config`)\n}\n\nmodule.exports = (schema = {}, opts = {}) => {\n  const { fromEnvFile = true, fromProcessEnv = true, envObject = {} } = opts\n\n  const config = {}\n\n  const given = { ...envObject }\n\n  if (fromEnvFile) {\n    const dotenvPath =\n      fromEnvFile === true ? path.resolve(process.cwd(), '.env') : fromEnvFile\n\n    if (fs.existsSync(dotenvPath)) {\n      const parsed = dotenv.parse(fs.readFileSync(dotenvPath))\n      Object.assign(given, parsed)\n    }\n  }\n\n  if (fromProcessEnv) {\n    Object.assign(given, process.env)\n  }\n\n  const validationsToRun = []\n\n  Object.entries(schema).forEach(([key, schema]) => {\n    if (typeof schema === 'string') schema = { type: schema }\n\n    const val = parse(key, given[key], schema)\n\n    if (schema.validate) {\n      // Run validations after all values has been parsed so we can validate some\n      // values depending another one.\n      validationsToRun.push(() => {\n        if (typeof schema.validate === 'function') {\n          if (!schema.validate(val, key, config)) {\n            throw new Error(\n              `Value for ${key} configuration does not pass custom validation`\n            )\n          }\n        } else if (schema.validate instanceof RegExp) {\n          if (!schema.validate.test(val)) {\n            throw new Error(\n              `Value for ${key} does not validate format of regex \"${schema.validate}\"`\n            )\n          }\n        } else {\n          throw new Error(`Invalid validate value for ${key} configuration`)\n        }\n      })\n    }\n\n    if (schema.enum) {\n      if (!Array.isArray(schema.enum)) {\n        throw new Error(\n          `Invalid enum value for ${key} configuration: ${schema.enum}`\n        )\n      }\n\n      if (!schema.enum.includes(val)) {\n        throw new Error(\n          `Value for ${key} should be one of: ${schema.enum.join(', ')}`\n        )\n      }\n    }\n\n    config[key] = val\n  })\n\n  validationsToRun.forEach(validate => validate())\n\n  // This Proxy throws an error if trying to access a not configured value.\n  return new Proxy(config, {\n    get (target, prop) {\n      if (\n        !reservedSymbols.includes(prop) &&\n        !hasOwnProperty(target, prop)\n      ) {\n        throw new Error(`Invalid config key \"${prop}\"`)\n      }\n\n      return target[prop]\n    },\n\n    set (target, prop, value) {\n      if (!hasOwnProperty(target, prop)) {\n        throw new Error(`Invalid config key \"${prop}\"`)\n      }\n\n      return (target[prop] = value)\n    }\n  })\n}\n"]}