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MAAQ,EAAI,QAC/H,CAGJ,IAAK,MAAM,KAAe,EAAc,CACpC,MAAM,EAAW,KAAK,KAAK,EAAU,GACrC,IAAI,EACJ,IAEI,QAAQ,EACZ,CACA,MAAO,GACH,EAAmB,EACnB,IAC0B,UAAhB,GAAwC,qBAAb,EAAI,MACjC,IAAI,oCAAoC,QAAe,KAAK,UAAU,KAE9E,CACA,MAAO,GACH,IAAI,yBAAyB,GAAK,UACtC,CACJ,CAEA,GAAI,EAAkB,CAElB,GAAoB,UAAhB,EACA,MAEJ,MAAM,IAAI,MAAM,+BAA+B,MAAa,EAAiB,QAAQ,EAAiB,qBAAqB,KAAK,UAAU,KAC9I,CAEA,IAAI,WAAW,kBAA4B,EACrC,sBAAsB,SAAkC,KAAe,IACvE,MAEN,MAAM,EAAe,QAAQ,GAC7B,IAAI,EAAS,EAAa,SAAW,EACrC,GAAI,EAAc,CACd,MAAM,EAAW,EAAa,UAAU,eAAiB,GAAwB,oBAAoB,GAC/F,EAAyB,EAAa,KAAe,GACvD,IACA,EAAS,kBAAkB,EAAQ,EAAwB,GAEnE,CACA,EAAQ,KAAK,EACjB,CAEA,EAAQ,KAAK,CACT,IAAK,EACL,KAAM,EAAI,KACV,QAAS,EAAI,UAGjB,IAAI,EAAS,EAAE,UAAU,MAAM,KAAM,IAAI,EAAS,aAIlD,OAHI,EAAQ,UAAU,QAClB,EAAS,kBAAkB,EAAQ,EAAQ,SAAS,MAAO,EAAQ,SAAS,gBAEzE,CAAM","file":"/npm/@neo9/n9-node-conf@2.0.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@neo9/n9-node-conf@2.0.0/dist/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\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ExtendConfigKeyFormat = exports.N9ConfMergeStrategy = void 0;\nconst fs = require(\"node:fs\");\nconst AppRootDir = require(\"app-root-dir\");\nconst debug = require(\"debug\");\nconst JsYaml = require(\"js-yaml\");\nconst _ = require(\"lodash\");\nconst Path = require(\"path\");\nconst log = debug('n9-node-conf');\nvar N9ConfMergeStrategy;\n(function (N9ConfMergeStrategy) {\n    /**\n     * Merge with lodash merge (_.merge)\n     */\n    N9ConfMergeStrategy[\"V1\"] = \"v1\";\n    /**\n     * Merge with n9Conf merge customizer\n     */\n    N9ConfMergeStrategy[\"V2\"] = \"v2\";\n})(N9ConfMergeStrategy || (exports.N9ConfMergeStrategy = N9ConfMergeStrategy = {}));\nvar ExtendConfigKeyFormat;\n(function (ExtendConfigKeyFormat) {\n    ExtendConfigKeyFormat[\"DROMEDARY_CASE\"] = \"dromedary-case\";\n    ExtendConfigKeyFormat[\"PASCAL_CASE\"] = \"pascal-case\";\n    ExtendConfigKeyFormat[\"KEBAB_CASE\"] = \"kebab-case\";\n    ExtendConfigKeyFormat[\"UPPER_KEBAB_CASE\"] = \"upper-kebab-case\";\n    ExtendConfigKeyFormat[\"SNAKE_CASE\"] = \"snake_case\";\n    ExtendConfigKeyFormat[\"UPPER_SNAKE_CASE\"] = \"upper_snake_case\";\n})(ExtendConfigKeyFormat || (exports.ExtendConfigKeyFormat = ExtendConfigKeyFormat = {}));\n// Customizer method to merge sources\nfunction customizer(objValue, srcValue) {\n    if (_.isUndefined(objValue) && !_.isUndefined(srcValue))\n        return srcValue;\n    if (_.isArray(objValue) && _.isArray(srcValue))\n        return srcValue;\n    if (_.isRegExp(objValue) || _.isRegExp(srcValue))\n        return srcValue;\n    if (_.isObject(objValue) || _.isObject(srcValue)) {\n        return _.mergeWith(objValue, srcValue, customizer);\n    }\n}\nfunction getExtendConfigPath(options, confPath) {\n    if (process.env.NODE_CONF_EXTEND_ABSOLUTE_PATH)\n        return process.env.NODE_CONF_EXTEND_ABSOLUTE_PATH;\n    if (options.extendConfig?.path?.absolute)\n        return options.extendConfig.path.absolute;\n    if (options.extendConfig?.path?.relative) {\n        return Path.join(confPath, options.extendConfig.path.relative);\n    }\n    return;\n}\nfunction mergeWithStrategy(source, override1, strategy = N9ConfMergeStrategy.V2) {\n    switch (strategy) {\n        case N9ConfMergeStrategy.V1:\n            return _.merge(_.cloneDeep(source), override1);\n        case N9ConfMergeStrategy.V2:\n            return _.mergeWith(_.cloneDeep(source), override1, customizer);\n        default:\n            throw new Error(`Merge strategy unknown : ${strategy}, supported ones are : ${Object.values(N9ConfMergeStrategy).join(' ')}`);\n    }\n}\nfunction readConfigFile(path, type) {\n    log(`Load extension ${path}`);\n    switch (type) {\n        case 'json':\n            return JSON.parse(fs.readFileSync(path).toString());\n        case 'yaml':\n            return JsYaml.load(fs.readFileSync(path, 'utf8'));\n        default:\n            throw new Error(`Invalid type \"${type}\", can't read file ${path}`);\n    }\n}\nfunction loadExtendConfig(extendConfigPath, extension = Path.extname(extendConfigPath), deep = 3) {\n    let type;\n    switch (extension) {\n        case '.json':\n            type = 'json';\n            break;\n        case '.yaml':\n        case '.yml':\n            type = 'yaml';\n            break;\n        default:\n            throw new Error(`Invalid extension configuration extension \"${extension}\" for file name ${extendConfigPath}`);\n    }\n    const fileNameWithoutExtension = Path.basename(extendConfigPath, Path.extname(extendConfigPath));\n    const dir = Path.dirname(extendConfigPath);\n    const path = Path.join(dir, `${fileNameWithoutExtension}${extension}`);\n    if (fs.existsSync(path)) {\n        return {\n            fileContent: readConfigFile(path, type),\n            filePath: path,\n        };\n    }\n    if (deep > 0) {\n        // try if other types exists\n        if (extension === '.json') {\n            // load yaml\n            return loadExtendConfig(extendConfigPath, '.yaml', deep - 1);\n        }\n        if (extension === '.yaml') {\n            // load yml\n            return loadExtendConfig(extendConfigPath, '.yml', deep - 1);\n        }\n        if (extension === '.yml') {\n            // load yml\n            return loadExtendConfig(extendConfigPath, '.json', deep - 1);\n        }\n    }\n}\nfunction getConfigKeyWithFormat(format, appName) {\n    switch (format) {\n        case ExtendConfigKeyFormat.DROMEDARY_CASE:\n            return _.chain(appName).camelCase().lowerFirst().value();\n        case ExtendConfigKeyFormat.PASCAL_CASE:\n            return _.chain(appName).camelCase().upperFirst().value();\n        case ExtendConfigKeyFormat.KEBAB_CASE:\n            return _.chain(appName).kebabCase().value();\n        case ExtendConfigKeyFormat.UPPER_KEBAB_CASE:\n            return _.chain(appName).kebabCase().toUpper().value();\n        case ExtendConfigKeyFormat.SNAKE_CASE:\n            return _.chain(appName).snakeCase().value();\n        case ExtendConfigKeyFormat.UPPER_SNAKE_CASE:\n            return _.chain(appName).snakeCase().toUpper().value();\n        default:\n            throw new Error(`unknown-extend-config-key-format-${format}`);\n    }\n}\nfunction removePrefixFromString(prefixToAvoid, value) {\n    if (value.startsWith(prefixToAvoid)) {\n        return value.slice(prefixToAvoid.length);\n    }\n    return value;\n}\nfunction getExtendCongigKey(appName, options) {\n    let extendConfigKey = appName;\n    if (options.extendConfig) {\n        if (options.extendConfig.key?.name) {\n            if (options.extendConfig.key?.prefixToAvoid) {\n                log(`Setting extendConfig.key.prefixToAvoid not used.`);\n            }\n            extendConfigKey = options.extendConfig.key.name;\n        }\n        else if (options.extendConfig.key?.format) {\n            if (options.extendConfig.key.prefixToAvoid) {\n                const appNameWithoutPrefix = removePrefixFromString(options.extendConfig.key.prefixToAvoid, appName);\n                extendConfigKey = getConfigKeyWithFormat(options.extendConfig.key.format, appNameWithoutPrefix);\n            }\n            else {\n                extendConfigKey = getConfigKeyWithFormat(options.extendConfig.key.format, appName);\n            }\n        }\n    }\n    return extendConfigKey;\n}\nexports.default = (options = {}) => {\n    const rootDir = AppRootDir.get();\n    const confPath = process.env.NODE_CONF_PATH || options.path || Path.join(rootDir, 'conf');\n    const packageJsonDirPath = Path.join(options.overridePackageJsonDirPath || rootDir, 'package.json');\n    const extendConfigPath = getExtendConfigPath(options, confPath);\n    const defaultMergeStrategy = options.extendConfig?.mergeStrategy;\n    const currentEnvironment = process.env.NODE_ENV || 'development';\n    // Fetch package.json of the app\n    /* eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-var-requires, global-require */\n    const app = require(packageJsonDirPath);\n    const extendConfigKey = getExtendCongigKey(app.name, options);\n    const environments = ['application', `${currentEnvironment}`, 'local']; // Files to load\n    const sources = []; // Sources of each config file\n    let extendConfig;\n    let extendConfigFileLoadedPath;\n    if (extendConfigPath) {\n        try {\n            const loadExtendConfigResult = loadExtendConfig(extendConfigPath);\n            if (loadExtendConfigResult) {\n                extendConfig = loadExtendConfigResult.fileContent;\n                extendConfigFileLoadedPath = loadExtendConfigResult.filePath;\n            }\n        }\n        catch (err) {\n            throw new Error(`Error while loading extendable config (${err.message}) : ${extendConfigPath} ${JSON.stringify(err)} ${err.stack}`);\n        }\n    }\n    // Load each file\n    for (const environment of environments) {\n        const filePath = Path.join(confPath, environment);\n        let fileLoadingError;\n        try {\n            /* eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-var-requires, global-require */\n            require(filePath);\n        }\n        catch (err) {\n            fileLoadingError = err;\n            try {\n                if (!(environment === 'local' && err.code === 'MODULE_NOT_FOUND')) {\n                    log(`Error while loading config file '${filePath}' : ${JSON.stringify(err)}`);\n                }\n            }\n            catch (e) {\n                log(`Can't stringify error ${err?.message}`);\n            }\n        }\n        // If config file does not exists\n        if (fileLoadingError) {\n            // Ignore for local.js file\n            if (environment === 'local')\n                break;\n            // throw an error for others\n            throw new Error(`Could not load config file: ${filePath}, ${fileLoadingError.name}(${fileLoadingError.message}) details: ${JSON.stringify(fileLoadingError)}`);\n        }\n        // Load its source\n        log(`Loading ${environment} configuration${extendConfig\n            ? `extended with file ${extendConfigFileLoadedPath} key ${environment}.${extendConfigKey}`\n            : ''}`);\n        /* eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-var-requires, global-require */\n        const loadedSource = require(filePath);\n        let source = loadedSource.default || loadedSource;\n        if (extendConfig) {\n            const strategy = extendConfig.metadata?.mergeStrategy ?? defaultMergeStrategy ?? N9ConfMergeStrategy.V2;\n            const extendConfigForThisEnv = extendConfig[environment]?.[extendConfigKey];\n            if (extendConfigForThisEnv) {\n                source = mergeWithStrategy(source, extendConfigForThisEnv, strategy);\n            }\n        }\n        sources.push(source);\n    }\n    // Add env, name & version to the returned config\n    sources.push({\n        env: currentEnvironment,\n        name: app.name,\n        version: app.version,\n    });\n    // Return merged sources\n    let result = _.mergeWith.apply(null, [...sources, customizer]);\n    if (options.override?.value) {\n        result = mergeWithStrategy(result, options.override.value, options.override.mergeStrategy);\n    }\n    return result;\n};\n"]}