const require_chunk = require('./chunk-CZg_9w7l.cjs');
const require_fs = require('./fs-Bi2kuxAm.cjs');
const require_write = require('./write-BJfM7G1_.cjs');
const require_transformers = require('./transformers-TDFgAyi8.cjs');
let node_path = require("node:path");
node_path = require_chunk.__toESM(node_path);
let remeda = require("remeda");
remeda = require_chunk.__toESM(remeda);
let object_hash = require("object-hash");
object_hash = require_chunk.__toESM(object_hash);

//#region ../../node_modules/.pnpm/yocto-queue@1.2.1/node_modules/yocto-queue/index.js
var Node = class {
	value;
	next;
	constructor(value) {
		this.value = value;
	}
};
var Queue = class {
	#head;
	#tail;
	#size;
	constructor() {
		this.clear();
	}
	enqueue(value) {
		const node = new Node(value);
		if (this.#head) {
			this.#tail.next = node;
			this.#tail = node;
		} else {
			this.#head = node;
			this.#tail = node;
		}
		this.#size++;
	}
	dequeue() {
		const current = this.#head;
		if (!current) return;
		this.#head = this.#head.next;
		this.#size--;
		return current.value;
	}
	peek() {
		if (!this.#head) return;
		return this.#head.value;
	}
	clear() {
		this.#head = void 0;
		this.#tail = void 0;
		this.#size = 0;
	}
	get size() {
		return this.#size;
	}
	*[Symbol.iterator]() {
		let current = this.#head;
		while (current) {
			yield current.value;
			current = current.next;
		}
	}
	*drain() {
		while (this.#head) yield this.dequeue();
	}
};

//#endregion
//#region ../../node_modules/.pnpm/p-limit@7.1.1/node_modules/p-limit/index.js
function pLimit(concurrency) {
	validateConcurrency(concurrency);
	const queue = new Queue();
	let activeCount = 0;
	const resumeNext = () => {
		if (activeCount < concurrency && queue.size > 0) {
			activeCount++;
			queue.dequeue()();
		}
	};
	const next = () => {
		activeCount--;
		resumeNext();
	};
	const run = async (function_, resolve, arguments_) => {
		const result = (async () => function_(...arguments_))();
		resolve(result);
		try {
			await result;
		} catch {}
		next();
	};
	const enqueue = (function_, resolve, arguments_) => {
		new Promise((internalResolve) => {
			queue.enqueue(internalResolve);
		}).then(run.bind(void 0, function_, resolve, arguments_));
		if (activeCount < concurrency) resumeNext();
	};
	const generator = (function_, ...arguments_) => new Promise((resolve) => {
		enqueue(function_, resolve, arguments_);
	});
	Object.defineProperties(generator, {
		activeCount: { get: () => activeCount },
		pendingCount: { get: () => queue.size },
		clearQueue: { value() {
			queue.clear();
		} },
		concurrency: {
			get: () => concurrency,
			set(newConcurrency) {
				validateConcurrency(newConcurrency);
				concurrency = newConcurrency;
				queueMicrotask(() => {
					while (activeCount < concurrency && queue.size > 0) resumeNext();
				});
			}
		},
		map: { async value(array, function_) {
			const promises = array.map((value, index) => this(function_, value, index));
			return Promise.all(promises);
		} }
	});
	return generator;
}
function validateConcurrency(concurrency) {
	if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
}

//#endregion
//#region src/utils/TreeNode.ts
var TreeNode = class TreeNode {
	data;
	parent;
	children = [];
	#cachedLeaves = void 0;
	constructor(data, parent) {
		this.data = data;
		this.parent = parent;
		return this;
	}
	addChild(data) {
		const child = new TreeNode(data, this);
		if (!this.children) this.children = [];
		this.children.push(child);
		return child;
	}
	get root() {
		if (!this.parent) return this;
		return this.parent.root;
	}
	get leaves() {
		if (!this.children || this.children.length === 0) return [this];
		if (this.#cachedLeaves) return this.#cachedLeaves;
		const leaves = [];
		if (this.children) for (let i = 0, { length } = this.children; i < length; i++) leaves.push.apply(leaves, this.children[i].leaves);
		this.#cachedLeaves = leaves;
		return leaves;
	}
	forEach(callback) {
		if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
		callback(this);
		if (this.children) for (let i = 0, { length } = this.children; i < length; i++) this.children[i]?.forEach(callback);
		return this;
	}
	findDeep(predicate) {
		if (typeof predicate !== "function") throw new TypeError("find() predicate must be a function");
		return this.leaves.find(predicate);
	}
	forEachDeep(callback) {
		if (typeof callback !== "function") throw new TypeError("forEach() callback must be a function");
		this.leaves.forEach(callback);
	}
	filterDeep(callback) {
		if (typeof callback !== "function") throw new TypeError("filter() callback must be a function");
		return this.leaves.filter(callback);
	}
	mapDeep(callback) {
		if (typeof callback !== "function") throw new TypeError("map() callback must be a function");
		return this.leaves.map(callback);
	}
	static build(files, root) {
		try {
			const filteredTree = buildDirectoryTree(files, root);
			if (!filteredTree) return null;
			const treeNode = new TreeNode({
				name: filteredTree.name,
				path: filteredTree.path,
				file: filteredTree.file,
				type: FileManager.getMode(filteredTree.path)
			});
			const recurse = (node, item) => {
				const subNode = node.addChild({
					name: item.name,
					path: item.path,
					file: item.file,
					type: FileManager.getMode(item.path)
				});
				if (item.children?.length) item.children?.forEach((child) => {
					recurse(subNode, child);
				});
			};
			filteredTree.children?.forEach((child) => {
				recurse(treeNode, child);
			});
			return treeNode;
		} catch (e) {
			throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
		}
	}
};
const normalizePath = (p) => p.replace(/\\/g, "/");
function buildDirectoryTree(files, rootFolder = "") {
	const normalizedRootFolder = normalizePath(rootFolder);
	const rootPrefix = normalizedRootFolder.endsWith("/") ? normalizedRootFolder : `${normalizedRootFolder}/`;
	const filteredFiles = files.filter((file) => {
		const normalizedFilePath = normalizePath(file.path);
		return rootFolder ? normalizedFilePath.startsWith(rootPrefix) && !normalizedFilePath.endsWith(".json") : !normalizedFilePath.endsWith(".json");
	});
	if (filteredFiles.length === 0) return null;
	const root = {
		name: rootFolder || "",
		path: rootFolder || "",
		children: []
	};
	filteredFiles.forEach((file) => {
		const parts = file.path.slice(rootFolder.length).split("/");
		let currentLevel = root.children;
		let currentPath = rootFolder;
		parts.forEach((part, index) => {
			if (index !== 0) currentPath += `/${part}`;
			else currentPath += `${part}`;
			let existingNode = currentLevel.find((node) => node.name === part);
			if (!existingNode) {
				if (index === parts.length - 1) existingNode = {
					name: part,
					file,
					path: currentPath
				};
				else existingNode = {
					name: part,
					path: currentPath,
					children: []
				};
				currentLevel.push(existingNode);
			}
			if (!existingNode.file) currentLevel = existingNode.children;
		});
	});
	return root;
}

//#endregion
//#region src/BarrelManager.ts
var BarrelManager = class {
	#options;
	constructor(options = {}) {
		this.#options = options;
		return this;
	}
	getFiles({ files: generatedFiles, root }) {
		const { logger } = this.#options;
		const cachedFiles = /* @__PURE__ */ new Map();
		TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
			if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) return;
			const barrelFile = {
				path: (0, node_path.join)(treeNode.parent?.data.path, "index.ts"),
				baseName: "index.ts",
				exports: [],
				sources: []
			};
			const previousBarrelFile = cachedFiles.get(barrelFile.path);
			treeNode.leaves.forEach((item) => {
				if (!item.data.name) return;
				const sources = item.data.file?.sources || [];
				if (!sources.some((source) => source.isIndexable)) logger?.emit("warning", `No isIndexable source found(source should have a name and isIndexable):\nFile: ${JSON.stringify(item.data.file, void 0, 2)}`);
				sources.forEach((source) => {
					if (!item.data.file?.path || !source.isIndexable || !source.name) return;
					if (previousBarrelFile?.sources.some((item$1) => item$1.name === source.name && item$1.isTypeOnly === source.isTypeOnly)) return;
					if (!barrelFile.exports) barrelFile.exports = [];
					if (!!treeNode.parent?.data.path?.split?.("/")?.length) barrelFile.exports.push({
						name: [source.name],
						path: require_fs.getRelativePath(treeNode.parent?.data.path, item.data.path),
						isTypeOnly: source.isTypeOnly
					});
					else barrelFile.exports.push({
						name: [source.name],
						path: `./${item.data.file.baseName}`,
						isTypeOnly: source.isTypeOnly
					});
					barrelFile.sources.push({
						name: source.name,
						isTypeOnly: source.isTypeOnly,
						value: "",
						isExportable: false,
						isIndexable: false
					});
				});
			});
			if (previousBarrelFile) {
				previousBarrelFile.sources.push(...barrelFile.sources);
				previousBarrelFile.exports?.push(...barrelFile.exports || []);
			} else cachedFiles.set(barrelFile.path, barrelFile);
		});
		return [...cachedFiles.values()];
	}
};

//#endregion
//#region src/utils/FunctionParams.ts
var import_main$1 = /* @__PURE__ */ require_chunk.__toESM(require_transformers.require_main(), 1);
/**
* @deprecated
*/
var FunctionParams = class FunctionParams {
	#items = [];
	constructor() {
		return this;
	}
	get items() {
		return this.#items.flat();
	}
	add(item) {
		if (!item) return this;
		if (Array.isArray(item)) {
			item.filter(Boolean).forEach((it) => {
				this.#items.push(it);
			});
			return this;
		}
		this.#items.push(item);
		return this;
	}
	static #orderItems(items) {
		return (0, import_main$1.orderBy)(items.filter(Boolean), [(v) => {
			if (Array.isArray(v)) return;
			return !v.default;
		}, (v) => {
			if (Array.isArray(v)) return;
			return v.required ?? true;
		}], ["desc", "desc"]);
	}
	static #addParams(acc, item) {
		const { enabled = true, name, type, required = true,...rest } = item;
		if (!enabled) return acc;
		if (!name) {
			acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
			return acc;
		}
		const parameterName = name.startsWith("{") ? name : require_transformers.camelCase(name);
		if (type) if (required) acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
		else acc.push(`${parameterName}?: ${type}`);
		else acc.push(`${parameterName}`);
		return acc;
	}
	static toObject(items) {
		let type = [];
		let name = [];
		const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
		const required = items.every((item) => item.required) ?? true;
		items.forEach((item) => {
			name = FunctionParams.#addParams(name, {
				...item,
				type: void 0
			});
			if (items.some((item$1) => item$1.type)) type = FunctionParams.#addParams(type, item);
		});
		return {
			name: `{ ${name.join(", ")} }`,
			type: type.length ? `{ ${type.join("; ")} }` : void 0,
			enabled,
			required
		};
	}
	static toString(items) {
		return FunctionParams.#orderItems(items).reduce((acc, item) => {
			if (Array.isArray(item)) {
				if (item.length <= 0) return acc;
				const subItems = FunctionParams.#orderItems(item);
				const objectItem = FunctionParams.toObject(subItems);
				return FunctionParams.#addParams(acc, objectItem);
			}
			return FunctionParams.#addParams(acc, item);
		}, []).join(", ");
	}
	toObject() {
		const items = FunctionParams.#orderItems(this.#items).flat();
		return FunctionParams.toObject(items);
	}
	toString() {
		const items = FunctionParams.#orderItems(this.#items);
		return FunctionParams.toString(items);
	}
};

//#endregion
//#region src/utils/promise.ts
function isPromise(result) {
	return !!result && typeof result?.then === "function";
}
function isPromiseFulfilledResult(result) {
	return result.status === "fulfilled";
}
function isPromiseRejectedResult(result) {
	return result.status === "rejected";
}

//#endregion
//#region src/utils/renderTemplate.ts
function renderTemplate(template, data = void 0) {
	if (!data || !Object.keys(data).length) return template.replace(/{{(.*?)}}/g, "");
	return template.match(/{{(.*?)}}/g)?.reduce((prev, curr) => {
		const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
		if (index === void 0) return prev;
		const value = data[index];
		if (value === void 0) return prev;
		return prev.replace(curr, () => {
			if (typeof value === "boolean") return `${value.toString()}` || "false";
			return value || "";
		}).trim();
	}, template) || "";
}

//#endregion
//#region src/utils/timeout.ts
async function timeout(ms) {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve(true);
		}, ms);
	});
}

//#endregion
//#region src/utils/uniqueName.ts
function getUniqueName(originalName, data) {
	let used = data[originalName] || 0;
	if (used) {
		data[originalName] = ++used;
		originalName += used;
	}
	data[originalName] = 1;
	return originalName;
}
function setUniqueName(originalName, data) {
	let used = data[originalName] || 0;
	if (used) {
		data[originalName] = ++used;
		return originalName;
	}
	data[originalName] = 1;
	return originalName;
}

//#endregion
//#region src/utils/URLPath.ts
var URLPath = class {
	path;
	#options;
	constructor(path$1, options = {}) {
		this.path = path$1;
		this.#options = options;
		return this;
	}
	/**
	* Convert Swagger path to URLPath(syntax of Express)
	* @example /pet/{petId} => /pet/:petId
	*/
	get URL() {
		return this.toURLPath();
	}
	get isURL() {
		try {
			if (new URL(this.path)?.href) return true;
		} catch (_error) {
			return false;
		}
		return false;
	}
	/**
	* Convert Swagger path to template literals/ template strings(camelcase)
	* @example /pet/{petId} => `/pet/${petId}`
	* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
	* @example /account/userID => `/account/${userId}`
	*/
	get template() {
		return this.toTemplateString();
	}
	get object() {
		return this.toObject();
	}
	get params() {
		return this.getParams();
	}
	toObject({ type = "path", replacer, stringify } = {}) {
		const object = {
			url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
			params: this.getParams()
		};
		if (stringify) {
			if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
			if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
			return `{ url: '${object.url}' }`;
		}
		return object;
	}
	/**
	* Convert Swagger path to template literals/ template strings(camelcase)
	* @example /pet/{petId} => `/pet/${petId}`
	* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
	* @example /account/userID => `/account/${userId}`
	*/
	toTemplateString({ prefix = "", replacer } = {}) {
		const found = this.path.match(/{(\w|-)*}/g);
		let newPath = this.path.replaceAll("{", "${");
		if (found) newPath = found.reduce((prev, path$1) => {
			const pathWithoutBrackets = path$1.replaceAll("{", "").replaceAll("}", "");
			let param = require_transformers.isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : require_transformers.camelCase(pathWithoutBrackets);
			if (this.#options.casing === "camelcase") param = require_transformers.camelCase(param);
			return prev.replace(path$1, `\${${replacer ? replacer(param) : param}}`);
		}, this.path);
		return `\`${prefix}${newPath}\``;
	}
	getParams(replacer) {
		const found = this.path.match(/{(\w|-)*}/g);
		if (!found) return;
		const params = {};
		found.forEach((item) => {
			item = item.replaceAll("{", "").replaceAll("}", "");
			let param = require_transformers.isValidVarName(item) ? item : require_transformers.camelCase(item);
			if (this.#options.casing === "camelcase") param = require_transformers.camelCase(param);
			const key = replacer ? replacer(param) : param;
			params[key] = key;
		}, this.path);
		return params;
	}
	/**
	* Convert Swagger path to URLPath(syntax of Express)
	* @example /pet/{petId} => /pet/:petId
	*/
	toURLPath() {
		return this.path.replaceAll("{", ":").replaceAll("}", "");
	}
};

//#endregion
//#region src/utils/parser.ts
/**
* Generate a default banner for files created by Kubb
* @returns A string with the default banner
*/
function getDefaultBanner({ title, description, version, config }) {
	try {
		let source = "";
		if ("path" in config.input) source = node_path.default.basename(config.input.path);
		else if ("data" in config.input) source = "text content";
		let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
		if (config.output.defaultBanner === "simple") {
			banner += "*/\n";
			return banner;
		}
		if (source) banner += `* Source: ${source}\n`;
		if (title) banner += `* Title: ${title}\n`;
		if (description) {
			const formattedDescription = description.replace(/\n/gm, "\n* ");
			banner += `* Description: ${formattedDescription}\n`;
		}
		if (version) banner += `* OpenAPI spec version: ${version}\n`;
		banner += "*/\n";
		return banner;
	} catch (_error) {
		return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
	}
}
/**
* Helper to create a file with name and id set
*/
function createFile(file) {
	const extname$1 = node_path.default.extname(file.baseName);
	if (!extname$1) throw new Error(`No extname found for ${file.baseName}`);
	const source = file.sources.map((item) => item.value).join("\n\n");
	const exports$1 = file.exports?.length ? combineExports(file.exports) : [];
	const imports = file.imports?.length && source ? combineImports(file.imports, exports$1, source) : [];
	const sources = file.sources?.length ? combineSources(file.sources) : [];
	return {
		...file,
		id: (0, object_hash.default)({ path: file.path }),
		name: trimExtName$1(file.baseName),
		extname: extname$1,
		imports: imports.map(createFileImport),
		exports: exports$1.map(createFileExport),
		sources: sources.map(createFileSource),
		meta: file.meta || {}
	};
}
/**
* Helper to create a fileImport with extname set
*/
function createFileSource(source) {
	return source;
}
/**
* Helper to create a fileImport with extname set
*/
function createFileImport(imp) {
	return { ...imp };
}
/**
* Helper to create a fileExport with extname set
*/
function createFileExport(exp) {
	return { ...exp };
}
function createFileParser(parser) {
	return parser;
}
const typeScriptParser = createFileParser({ async print(file, options = { extname: ".ts" }) {
	const module$1 = await import("@kubb/parser-ts");
	const source = file.sources.map((item) => item.value).join("\n\n");
	const importNodes = file.imports.map((item) => {
		const importPath = item.root ? require_fs.getRelativePath(item.root, item.path) : item.path;
		const hasExtname = !!node_path.default.extname(importPath);
		return module$1.factory.createImportDeclaration({
			name: item.name,
			path: options.extname && hasExtname ? `${trimExtName$1(importPath)}${options.extname}` : item.root ? trimExtName$1(importPath) : importPath,
			isTypeOnly: item.isTypeOnly
		});
	}).filter(Boolean);
	const exportNodes = file.exports.map((item) => {
		const exportPath = item.path;
		const hasExtname = !!node_path.default.extname(exportPath);
		return module$1.factory.createExportDeclaration({
			name: item.name,
			path: options.extname && hasExtname ? `${trimExtName$1(item.path)}${options.extname}` : trimExtName$1(item.path),
			isTypeOnly: item.isTypeOnly,
			asAlias: item.asAlias
		});
	}).filter(Boolean);
	return [
		file.banner,
		module$1.print([...importNodes, ...exportNodes]),
		source,
		file.footer
	].join("\n");
} });
const tsxParser = createFileParser({ async print(file, options = { extname: ".tsx" }) {
	return typeScriptParser.print(file, options);
} });
const defaultParser = createFileParser({ async print(file) {
	return file.sources.map((item) => item.value).join("\n\n");
} });
const parsers = {
	".ts": typeScriptParser,
	".js": typeScriptParser,
	".jsx": tsxParser,
	".tsx": tsxParser,
	".json": defaultParser
};
async function getFileParser(extname$1) {
	if (!extname$1) return defaultParser;
	const parser = parsers[extname$1];
	if (!parser) console.warn(`[parser] No parser found for ${extname$1}, default parser will be used`);
	return parser || defaultParser;
}
function trimExtName$1(text) {
	const extname$1 = text.split(".").pop();
	return text.replace(`.${extname$1}`, "");
}

//#endregion
//#region src/utils/Cache.ts
var Cache = class {
	#buffer = /* @__PURE__ */ new Map();
	async get(key) {
		return this.#buffer.get(key) ?? null;
	}
	async set(key, value) {
		this.#buffer.set(key, value);
	}
	async delete(key) {
		this.#buffer.delete(key);
	}
	async clear() {
		this.#buffer.clear();
	}
	async keys() {
		return [...this.#buffer.keys()];
	}
	async values() {
		return [...this.#buffer.values()];
	}
	async flush() {}
};

//#endregion
//#region src/FileManager.ts
var import_main = /* @__PURE__ */ require_chunk.__toESM(require_transformers.require_main(), 1);
var FileManager = class {
	#cache = new Cache();
	#limit = pLimit(100);
	constructor() {
		return this;
	}
	async add(...files) {
		const resolvedFiles = [];
		const mergedFiles = /* @__PURE__ */ new Map();
		files.forEach((file) => {
			const existing = mergedFiles.get(file.path);
			if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
			else mergedFiles.set(file.path, file);
		});
		for (const file of mergedFiles.values()) {
			const existing = await this.#cache.get(file.path);
			const merged = existing ? mergeFile(existing, file) : file;
			const resolvedFile = createFile(merged);
			await this.#cache.set(resolvedFile.path, resolvedFile);
			await this.#cache.flush();
			resolvedFiles.push(resolvedFile);
		}
		if (files.length > 1) return resolvedFiles;
		return resolvedFiles[0];
	}
	async getByPath(path$1) {
		return this.#cache.get(path$1);
	}
	async deleteByPath(path$1) {
		await this.#cache.delete(path$1);
	}
	async clear() {
		await this.#cache.clear();
	}
	async getFiles() {
		const cachedKeys = await this.#cache.keys();
		const filesTasks = (0, import_main.orderBy)(cachedKeys, [(v) => v.length, (v) => require_fs.trimExtName(v).endsWith("index")]).map((key) => this.#limit(async () => {
			return await this.#cache.get(key);
		}));
		return (await Promise.all(filesTasks)).filter(Boolean);
	}
	async processFiles({ dryRun, root, extension, logger }) {
		const files = await this.getFiles();
		logger?.emit("progress_start", {
			id: "files",
			size: files.length,
			message: "Writing files ..."
		});
		const promises = files.map((file) => {
			return this.#limit(async () => {
				const message = file ? `Writing ${(0, node_path.relative)(root, file.path)}` : "";
				const extname$1 = extension?.[file.extname] || void 0;
				if (!dryRun) {
					const source = await getSource(file, {
						logger,
						extname: extname$1
					});
					await require_write.write(file.path, source, { sanity: false });
				}
				logger?.emit("progressed", {
					id: "files",
					message
				});
			});
		});
		await Promise.all(promises);
		logger?.emit("progress_stop", { id: "files" });
		return files;
	}
	async getBarrelFiles({ type, meta = {}, root, output, logger }) {
		if (!type || type === "propagate") return [];
		const barrelManager = new BarrelManager({ logger });
		const files = await this.getFiles();
		const pathToBuildFrom = (0, node_path.join)(root, output.path);
		if (require_fs.trimExtName(pathToBuildFrom).endsWith("index")) {
			logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
			return [];
		}
		const barrelFiles = barrelManager.getFiles({
			files,
			root: pathToBuildFrom,
			meta
		});
		if (type === "all") return barrelFiles.map((file) => {
			return {
				...file,
				exports: file.exports?.map((exportItem) => {
					return {
						...exportItem,
						name: void 0
					};
				})
			};
		});
		return barrelFiles.map((indexFile) => {
			return {
				...indexFile,
				meta
			};
		});
	}
	static getMode(path$1) {
		if (!path$1) return "split";
		return (0, node_path.extname)(path$1) ? "single" : "split";
	}
};
async function getSource(file, { logger, extname: extname$1 } = {}) {
	return (await getFileParser(file.extname)).print(file, {
		logger,
		extname: extname$1
	});
}
function mergeFile(a, b) {
	return {
		...a,
		sources: [...a.sources || [], ...b.sources || []],
		imports: [...a.imports || [], ...b.imports || []],
		exports: [...a.exports || [], ...b.exports || []]
	};
}
function combineSources(sources) {
	return (0, remeda.uniqueBy)(sources, (obj) => [
		obj.name,
		obj.isExportable,
		obj.isTypeOnly
	]);
}
function combineExports(exports$1) {
	return (0, import_main.orderBy)(exports$1, [
		(v) => !!Array.isArray(v.name),
		(v) => !v.isTypeOnly,
		(v) => v.path,
		(v) => !!v.name,
		(v) => Array.isArray(v.name) ? (0, import_main.orderBy)(v.name) : v.name
	]).reduce((prev, curr) => {
		const name = curr.name;
		const prevByPath = prev.findLast((imp) => imp.path === curr.path);
		if (prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly)) return prev;
		if (prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias) || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) return prev;
		if (!prevByPath) return [...prev, {
			...curr,
			name: Array.isArray(name) ? [...new Set(name)] : name
		}];
		if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
			prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])];
			return prev;
		}
		return [...prev, curr];
	}, []);
}
function combineImports(imports, exports$1, source) {
	return (0, import_main.orderBy)(imports, [
		(v) => !!Array.isArray(v.name),
		(v) => !v.isTypeOnly,
		(v) => v.path,
		(v) => !!v.name,
		(v) => Array.isArray(v.name) ? (0, import_main.orderBy)(v.name) : v.name
	]).reduce((prev, curr) => {
		let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
		const hasImportInSource = (importName) => {
			if (!source) return true;
			const checker = (name$1) => {
				return name$1 && source.includes(name$1);
			};
			return checker(importName) || exports$1.some(({ name: name$1 }) => Array.isArray(name$1) ? name$1.some(checker) : checker(name$1));
		};
		if (curr.path === curr.root) return prev;
		if (Array.isArray(name)) name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
		const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
		const uniquePrev = prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
		if (prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly)) return prev;
		if (uniquePrev || Array.isArray(name) && !name.length) return prev;
		if (!prevByPath) return [...prev, {
			...curr,
			name
		}];
		if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
			prevByPath.name = [...new Set([...prevByPath.name, ...name])];
			return prev;
		}
		if (!Array.isArray(name) && name && !hasImportInSource(name)) return prev;
		return [...prev, curr];
	}, []);
}

//#endregion
Object.defineProperty(exports, 'Cache', {
  enumerable: true,
  get: function () {
    return Cache;
  }
});
Object.defineProperty(exports, 'FileManager', {
  enumerable: true,
  get: function () {
    return FileManager;
  }
});
Object.defineProperty(exports, 'FunctionParams', {
  enumerable: true,
  get: function () {
    return FunctionParams;
  }
});
Object.defineProperty(exports, 'Queue', {
  enumerable: true,
  get: function () {
    return Queue;
  }
});
Object.defineProperty(exports, 'URLPath', {
  enumerable: true,
  get: function () {
    return URLPath;
  }
});
Object.defineProperty(exports, 'createFile', {
  enumerable: true,
  get: function () {
    return createFile;
  }
});
Object.defineProperty(exports, 'createFileExport', {
  enumerable: true,
  get: function () {
    return createFileExport;
  }
});
Object.defineProperty(exports, 'createFileImport', {
  enumerable: true,
  get: function () {
    return createFileImport;
  }
});
Object.defineProperty(exports, 'createFileParser', {
  enumerable: true,
  get: function () {
    return createFileParser;
  }
});
Object.defineProperty(exports, 'getDefaultBanner', {
  enumerable: true,
  get: function () {
    return getDefaultBanner;
  }
});
Object.defineProperty(exports, 'getFileParser', {
  enumerable: true,
  get: function () {
    return getFileParser;
  }
});
Object.defineProperty(exports, 'getSource', {
  enumerable: true,
  get: function () {
    return getSource;
  }
});
Object.defineProperty(exports, 'getUniqueName', {
  enumerable: true,
  get: function () {
    return getUniqueName;
  }
});
Object.defineProperty(exports, 'isPromise', {
  enumerable: true,
  get: function () {
    return isPromise;
  }
});
Object.defineProperty(exports, 'isPromiseFulfilledResult', {
  enumerable: true,
  get: function () {
    return isPromiseFulfilledResult;
  }
});
Object.defineProperty(exports, 'isPromiseRejectedResult', {
  enumerable: true,
  get: function () {
    return isPromiseRejectedResult;
  }
});
Object.defineProperty(exports, 'pLimit', {
  enumerable: true,
  get: function () {
    return pLimit;
  }
});
Object.defineProperty(exports, 'renderTemplate', {
  enumerable: true,
  get: function () {
    return renderTemplate;
  }
});
Object.defineProperty(exports, 'setUniqueName', {
  enumerable: true,
  get: function () {
    return setUniqueName;
  }
});
Object.defineProperty(exports, 'timeout', {
  enumerable: true,
  get: function () {
    return timeout;
  }
});
//# sourceMappingURL=FileManager-qDcTVN6G.cjs.map