import { a as __exportAll } from "./runner-K8XK101B.mjs";
import { r as encodeBase64, t as decodeBase64 } from "./base64-CmWvODNW.mjs";

//#region src/database/repositories/types.ts
var types_exports = /* @__PURE__ */ __exportAll({
	EmDashValidationError: () => EmDashValidationError,
	InvalidCursorError: () => InvalidCursorError,
	ScheduledNotDueError: () => ScheduledNotDueError,
	decodeCursor: () => decodeCursor,
	encodeCursor: () => encodeCursor
});
/**
* Hard cap on cursor length. Cursors we issue are short JSON-in-base64
* blobs; a real cursor is well under 200 chars. This guards against
* malicious callers passing megabyte-sized strings to force the base64
* decoder to allocate (decodeBase64 is O(N) in input size). The MCP and
* REST schemas also clamp at 2048 — this 4096 cap is a defense-in-depth
* floor inside the repository helpers.
*/
const MAX_CURSOR_LENGTH = 4096;
/** Encode a cursor from order value + id */
function encodeCursor(orderValue, id) {
	return encodeBase64(JSON.stringify({
		orderValue,
		id
	}));
}
/**
* Thrown when a pagination cursor cannot be decoded.
*
* Repository callers should let this propagate; handler catch blocks
* map it to a structured `INVALID_CURSOR` error so client pagination
* bugs surface immediately rather than silently re-fetching the first
* page.
*/
var InvalidCursorError = class extends Error {
	constructor(cursor) {
		const display = cursor.length > 50 ? `${cursor.slice(0, 47)}...` : cursor;
		super(`Invalid pagination cursor: ${display}`);
		this.name = "InvalidCursorError";
	}
};
/**
* Decode a cursor to order value + id.
*
* Throws `InvalidCursorError` if the cursor is empty, not valid base64,
* not valid JSON, or doesn't contain string `orderValue` and `id` fields.
*/
function decodeCursor(cursor) {
	if (!cursor) throw new InvalidCursorError(cursor);
	if (cursor.length > MAX_CURSOR_LENGTH) throw new InvalidCursorError(cursor);
	let parsed;
	try {
		parsed = JSON.parse(decodeBase64(cursor));
	} catch {
		throw new InvalidCursorError(cursor);
	}
	if (parsed === null || typeof parsed !== "object") throw new InvalidCursorError(cursor);
	const candidate = parsed;
	if (typeof candidate.orderValue !== "string" || typeof candidate.id !== "string") throw new InvalidCursorError(cursor);
	return {
		orderValue: candidate.orderValue,
		id: candidate.id
	};
}
var EmDashValidationError = class extends Error {
	constructor(message, details) {
		super(message);
		this.details = details;
		this.name = "EmDashValidationError";
	}
};
/**
* Thrown by `publish()` when called with `requireDue` for a row that is no
* longer due (its `scheduled_at` was cleared or pushed into the future between
* selection and publish — e.g. an editor unscheduled it). Lets the scheduled
* sweep skip the row silently rather than treating it as a publish failure.
*/
var ScheduledNotDueError = class extends Error {
	constructor(message = "Content is no longer scheduled to publish") {
		super(message);
		this.name = "ScheduledNotDueError";
	}
};

//#endregion
export { encodeCursor as a, decodeCursor as i, InvalidCursorError as n, types_exports as o, ScheduledNotDueError as r, EmDashValidationError as t };
//# sourceMappingURL=types-CuW0zWDA.mjs.map