#!/usr/bin/env node
import { i as resolvePackageEntryPoint, r as importModule } from "./esm-BOYGx5J1.js";
import path from "path";
//#region src/providers/packageParser.ts
function getValue(obj, path) {
	return path.split(".").reduce((acc, key) => {
		return acc && acc[key] !== void 0 ? acc[key] : void 0;
	}, obj);
}
function isPackagePath(path) {
	return typeof path === "string" && path.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 = resolvePackageEntryPoint(packageName, path.resolve(basePath));
	if (!filePath) throw new Error(`Package not found: ${packageName}. Make sure it's installed in ${basePath}`);
	let module;
	try {
		module = await 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
export { loadFromPackage as n, parsePackageProvider as r, isPackagePath as t };

//# sourceMappingURL=packageParser-DVFGAxzK.js.map