const require_rolldown_runtime = require("./rolldown-runtime-D_mwlA32.cjs");
const require_esm = require("./esm-4Cu04ouJ.cjs");
let path = require("path");
path = require_rolldown_runtime.__toESM(path, 1);
//#region src/providers/packageParser.ts
function getValue(obj, path$2) {
	return path$2.split(".").reduce((acc, key) => {
		return acc && acc[key] !== void 0 ? acc[key] : void 0;
	}, obj);
}
function isPackagePath(path$3) {
	return typeof path$3 === "string" && path$3.startsWith("package:");
}
async function loadFromPackage(packageInstancePath, basePath) {
	const [, packageName, entityName] = packageInstancePath.split(":");
	if (!packageName || !entityName) throw new Error(`Invalid package format: ${packageInstancePath}. Expected format: package:packageName:exportedClassOrFunction`);
	const filePath = require_esm.resolvePackageEntryPoint(packageName, path.default.resolve(basePath));
	if (!filePath) throw new Error(`Package not found: ${packageName}. Make sure it's installed in ${basePath}`);
	let module;
	try {
		module = await require_esm.importModule(filePath);
	} catch (error) {
		throw new Error(`Failed to import module: ${packageName}. Error: ${error}`);
	}
	const entity = getValue(module, entityName);
	if (entity === void 0) throw new Error(`Could not find entity: ${entityName} in module: ${filePath}. Make sure the entity is exported from the package.`);
	return entity;
}
async function parsePackageProvider(providerPath, basePath, options) {
	const Provider = await loadFromPackage(providerPath, basePath);
	if (typeof Provider !== "function") throw new Error(`Provider malformed: ${providerPath} must export a provider constructor. Received: ${typeof Provider}`);
	return new Provider(options);
}
//#endregion
Object.defineProperty(exports, "isPackagePath", {
	enumerable: true,
	get: function() {
		return isPackagePath;
	}
});
Object.defineProperty(exports, "loadFromPackage", {
	enumerable: true,
	get: function() {
		return loadFromPackage;
	}
});
Object.defineProperty(exports, "parsePackageProvider", {
	enumerable: true,
	get: function() {
		return parsePackageProvider;
	}
});

//# sourceMappingURL=packageParser-BdLix4NF.cjs.map