import { c as chain, g as getProfileName, a as CredentialsProviderError } from './role-executor-C4-3bmgC.js';
import { l as loadSharedConfigFiles } from './loadSharedConfigFiles-BEZDzu24.js';

//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/config/property-provider/fromValue.js
var fromValue = (staticValue) => () => Promise.resolve(staticValue);
//#endregion
//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/config/property-provider/memoize.js
var memoize = (provider, isExpired, requiresRefresh) => {
	let resolved;
	let pending;
	let hasResult;
	let isConstant = false;
	const coalesceProvider = async () => {
		if (!pending) pending = provider();
		try {
			resolved = await pending;
			hasResult = true;
			isConstant = false;
		} finally {
			pending = void 0;
		}
		return resolved;
	};
	return async (options) => {
		if (!hasResult || options?.forceRefresh) resolved = await coalesceProvider();
		return resolved;
	};
};
//#endregion
//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/getSelectorName.js
function getSelectorName(functionString) {
	try {
		const constants = new Set(Array.from(functionString.match(/([A-Z_]){3,}/g) ?? []));
		constants.delete("CONFIG");
		constants.delete("CONFIG_PREFIX_SEPARATOR");
		constants.delete("ENV");
		return [...constants].join(", ");
	} catch (e) {
		return functionString;
	}
}
//#endregion
//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromEnv.js
var fromEnv = (envVarSelector, options) => async () => {
	try {
		const config = envVarSelector(process.env, options);
		if (config === void 0) throw new Error();
		return config;
	} catch (e) {
		throw new CredentialsProviderError(e.message || `Not found in ENV: ${getSelectorName(envVarSelector.toString())}`, { logger: options?.logger });
	}
};
//#endregion
//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromSharedConfigFiles.js
var fromSharedConfigFiles = (configSelector, { preferredFile = "config", ...init } = {}) => async () => {
	const profile = getProfileName(init);
	const { configFile, credentialsFile } = await loadSharedConfigFiles(init);
	const profileFromCredentials = credentialsFile[profile] || {};
	const profileFromConfig = configFile[profile] || {};
	const mergedProfile = preferredFile === "config" ? {
		...profileFromCredentials,
		...profileFromConfig
	} : {
		...profileFromConfig,
		...profileFromCredentials
	};
	try {
		const configValue = configSelector(mergedProfile, preferredFile === "config" ? configFile : credentialsFile);
		if (configValue === void 0) throw new Error();
		return configValue;
	} catch (e) {
		throw new CredentialsProviderError(e.message || `Not found in config files w/ profile [${profile}]: ${getSelectorName(configSelector.toString())}`, { logger: init.logger });
	}
};
//#endregion
//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/fromStatic.js
var isFunction = (func) => typeof func === "function";
var fromStatic = (defaultValue) => isFunction(defaultValue) ? async () => await defaultValue() : fromValue(defaultValue);
//#endregion
//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/config/node-config-provider/configLoader.js
var loadConfig = ({ environmentVariableSelector, configFileSelector, default: defaultValue }, configuration = {}) => {
	const { signingName, logger } = configuration;
	return memoize(chain(fromEnv(environmentVariableSelector, {
		signingName,
		logger
	}), fromSharedConfigFiles(configFileSelector, configuration), fromStatic(defaultValue)));
};
//#endregion
//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/protocols/querystring-parser/parseQueryString.js
function parseQueryString(querystring) {
	const query = {};
	querystring = querystring.replace(/^\?/, "");
	if (querystring) for (const pair of querystring.split("&")) {
		let [key, value = null] = pair.split("=");
		key = decodeURIComponent(key);
		if (value) value = decodeURIComponent(value);
		if (!(key in query)) query[key] = value;
		else if (Array.isArray(query[key])) query[key].push(value);
		else query[key] = [query[key], value];
	}
	return query;
}
//#endregion
//#region ../../node_modules/.pnpm/@smithy+core@3.24.3/node_modules/@smithy/core/dist-es/submodules/protocols/url-parser/parseUrl.js
var parseUrl = (url) => {
	if (typeof url === "string") return parseUrl(new URL(url));
	const { hostname, pathname, port, protocol, search } = url;
	let query;
	if (search) query = parseQueryString(search);
	return {
		hostname,
		port: port ? parseInt(port) : void 0,
		protocol,
		path: pathname,
		query
	};
};

export { loadConfig as l, memoize as m, parseUrl as p };
//# sourceMappingURL=parseUrl-BS2YLisE.js.map
