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EAAO,KAEZ,EAAO,GAAO,YAAY,KAAK,iBAAiB,EAAO,GAAM,IAGzE,CAIA,OAFA,KAAK,OAAO,GAAW,EAEhB,GAAG,KAAW,GACzB,CAEA,cAAA,CAAe,GACX,IAAK,MAAM,KAAO,EACd,KAAK,iBAAiB,EAAI,GAAM,KAAM,EAE9C,CAEA,UAAA,GACI,MAAM,EAAS,gBAAgB,KAAK,QACpC,IAAK,MAAM,KAAK,OAAO,OAAO,UACnB,EAAE,SAEb,OAAO,CACX,EAGJ,OAAO,QAAU,CACb,4BAEA,cAjIkB","file":"/npm/rclone-config-builder@1.0.0/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/rclone-config-builder@1.0.0/src/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 structuredClone = require(\"@ungap/structured-clone\").default;\nconst { shellEscape } = require(\"../src/util\");\n\n/**\n * A reserved key for specifying path\n */\nconst RemotePathKey = \"@path\";\n\nclass ConfigBuilder {\n    constructor(wrappingBackends = require(\"./wrapping_backends\")) {\n        this.wrappingBackends = wrappingBackends;\n        this.config = {};\n    }\n\n    /**\n     * Resolves an unidentified remote entry to string\n     * \n     * @params remote A remote entry\n     * @params name Parent remote name (null for unknown)\n     * @params newName The specified name (null for auto-generate)\n     */\n    resolveNewRemote(remote, parent = null, newName = null) {\n        /* expected structure:\n         * remote = \"remote:test\" OR\n         * remote = {\n         *   \"type\": \"crypt\",\n         *   \"remote\": \"remote:test\",\n         * } OR\n         * remote = {\n         *   \"type\": \"crypt\",\n         *   \"remote\": \"remote:encrypted\",\n         *   \"@path\": \"hello\",\n         * }\n         * \n         * they should resolve into like: (if name is \"remote\")\n         * \"remote:test\"\n         * \"__remote_crypt_1:\"\n         * \"__remote_crypt_2:hello\"\n         */\n        if (typeof remote === \"string\") {\n            // no need to give new name\n            return remote;\n        }\n        parent = parent || \"\";\n        if (!remote.type) {\n            throw new Error(\"A remote requires \\\"type\\\" key\");\n        }\n        if (parent && newName) {\n            throw new Error(\"Conflict: children have names defined\");\n        } else if (newName) {\n            if (newName in this.config) {\n                throw new Error(`The remote name ${newName} has already been in use`);\n            }\n        } else {\n            for (let i = 1; ; i++) {\n                newName = `__${parent}_${remote.type}_${i}`;\n                if (!(newName in this.config)) {\n                    break;\n                }\n            }\n        }\n\n        remote = structuredClone(remote);\n        const subdir = remote[\"@path\"] || \"\";\n\n        // resolve backends recursively\n        if (remote.type in this.wrappingBackends) {\n            const backendInfo = this.wrappingBackends[remote.type];\n            if (backendInfo[0]) {\n                // multiple\n                for (const key of backendInfo.slice(1)) {\n                    if (!remote[key])\n                        continue;\n                    let remotes = remote[key];\n                    // no need to try to replace\n                    if (typeof remotes === \"string\")\n                        continue;\n                    const remotesIsObject = Object.prototype.toString.call(remotes) === \"[object Object]\";\n\n                    const repr = [];\n\n                    if (remote.type === \"combine\" && remotesIsObject) {\n                        /***\n                         * {\n                         *   \"path\": remote, ...\n                         * }\n                         */\n                        for (const key in remotes) {\n                            repr.push(`${key}=${this.resolveNewRemote(remotes[key], newName)}`);\n                        }\n                        // -> path=remote:blablabla/\n                    } else {\n                        if (remotesIsObject)\n                            remotes = [remotes];\n                        for (const rem of remotes) {\n                            repr.push(this.resolveNewRemote(rem, newName));\n                        }\n                    }\n\n                    // it has no problem as shellEscape only takes 1 parameter\n                    remote[key] = repr.map(shellEscape).join(\" \");\n                }\n            } else {\n                // single\n                for (const key of backendInfo.slice(1)) {\n                    if (!remote[key])\n                        continue;\n                    remote[key] = shellEscape(this.resolveNewRemote(remote[key], newName));\n                }\n            }\n        }\n\n        this.config[newName] = remote;\n\n        return `${newName}:${subdir}`;\n    }\n\n    loadRawRemotes(obj) {\n        for (const key in obj) {\n            this.resolveNewRemote(obj[key], null, key);\n        }\n    }\n\n    getRemotes() {\n        const cloned = structuredClone(this.config);\n        for (const v of Object.values(cloned)) {\n            delete v[\"@path\"];\n        }\n        return cloned;\n    }\n}\n\nmodule.exports = {\n    ConfigBuilder,\n\n    RemotePathKey,\n}\n"]}