import { aS as resolveDefaultMigrateTarget, a0 as ensureReleaseMigrated, a4 as formatForDisplay, M as MigrationError, H as createLogger } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, e as errorResponse, k as jsonResponse } from './helpers-kzwksNq1.js';
import './chunk-CLZ62Ad-.js';
import 'node:module';
import './provider-constants-DPrj3yBX.js';
import './dist-DOFcG0Zp.js';
import 'node:fs';
import 'node:path';
import 'buffer';
import 'fs';
import 'path';
import 'node:child_process';
import 'node:url';
import 'node:crypto';
import 'events';
import 'node:events';
import 'node:stream';
import 'node:string_decoder';
import 'assert';
import 'zlib';
import 'node:assert';
import 'node:fs/promises';
import 'node:os';
import './endpoints-UdQGgKsR.js';

//#region src/routes/admin/migrate-preview/+server.ts
var logger = createLogger("migrate-preview");
/**
* Preview (#497): show the copy-only release migrations an upgrade to <tag>
* WOULD run, before the user applies it. Routes through
* `ensureReleaseMigrated({ dryRun: true })`, which logs `[dry-run]` lines and
* writes nothing. The same preview the CLI's `migrate --dry-run --to` surfaces.
*/
var POST = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	let body;
	try {
		body = await event.request.json();
	} catch {
		body = {};
	}
	const requested = typeof body.tag === "string" ? body.tag.trim() : "";
	if (requested && !/^[a-zA-Z0-9._\-]+$/.test(requested)) return errorResponse(400, "invalid_tag", "Tag must be alphanumeric with . _ or - only", {}, requestId);
	const state = getState();
	let targetVersion = requested;
	if (!targetVersion || requested.toLowerCase() === "latest") try {
		targetVersion = await resolveDefaultMigrateTarget(state);
	} catch (e) {
		return errorResponse(502, "resolve_failed", `Could not resolve the latest version to preview: ${e instanceof Error ? e.message : String(e)}`, {}, requestId);
	}
	const lines = [];
	try {
		const report = ensureReleaseMigrated({
			homeDir: state.homeDir,
			targetVersion,
			dryRun: true,
			log: (m) => lines.push(m)
		});
		logger.info("migrate preview computed", {
			requestId,
			targetVersion,
			applied: report.applied.length
		});
		return jsonResponse(200, {
			ok: true,
			targetVersion: formatForDisplay(targetVersion),
			applied: report.applied,
			lines,
			notes: report.notes
		}, requestId);
	} catch (e) {
		if (e instanceof MigrationError) return errorResponse(500, "preview_failed", e.message, { guidance: e.guidance }, requestId);
		return errorResponse(500, "preview_failed", e instanceof Error ? e.message : String(e), {}, requestId);
	}
};

export { POST };
//# sourceMappingURL=_server.ts-BcyD4FAK.js.map
