//#region src/routes/api/memory/_lafs.ts
/** Build an ok envelope. */
function ok(data) {
	return {
		success: true,
		data,
		meta: { at: (/* @__PURE__ */ new Date()).toISOString() }
	};
}
/** Build an error envelope. */
function err(code, message) {
	return {
		success: false,
		error: {
			code,
			message
		},
		meta: { at: (/* @__PURE__ */ new Date()).toISOString() }
	};
}
/** Type guard: was a parse error returned? */
function isParseError(v) {
	return "_parseError" in v && typeof v._parseError === "string";
}
/**
* Parse a JSON body defensively. Returns the parsed value or a tagged
* `ParseError` carrier so callers can branch without try/catch.
*/
async function parseJsonBody(request) {
	try {
		const body = await request.json();
		if (body === null || typeof body !== "object" || Array.isArray(body)) return { _parseError: "Request body must be a JSON object" };
		return body;
	} catch {
		return { _parseError: "Invalid JSON body" };
	}
}
/** Require a non-empty string field. */
function requireString(body, key, max = 1e4) {
	const v = body[key];
	if (typeof v !== "string") return {
		ok: false,
		message: `Missing or non-string field: ${key}`
	};
	if (v.trim().length < 1) return {
		ok: false,
		message: `Field ${key} cannot be empty`
	};
	if (v.length > max) return {
		ok: false,
		message: `Field ${key} exceeds ${max} chars`
	};
	return {
		ok: true,
		value: v
	};
}
/** Optional string field. */
function optionalString(body, key) {
	const v = body[key];
	if (typeof v !== "string") return void 0;
	const trimmed = v.trim();
	return trimmed.length > 0 ? trimmed : void 0;
}
/** Optional string array. */
function optionalStringArray(body, key) {
	const v = body[key];
	if (!Array.isArray(v)) return void 0;
	const clean = v.filter((s) => typeof s === "string" && s.trim().length > 0).map((s) => s.trim());
	return clean.length > 0 ? clean : void 0;
}
/** Optional number in [0..1]. */
function optionalUnit(body, key) {
	const v = body[key];
	if (typeof v !== "number" || !Number.isFinite(v)) return void 0;
	return Math.max(0, Math.min(1, v));
}
/** Optional boolean. */
function optionalBool(body, key) {
	const v = body[key];
	if (typeof v !== "boolean") return void 0;
	return v;
}
/** Generate a short id suffix. */
function shortId() {
	if (typeof crypto !== "undefined" && "randomUUID" in crypto) return crypto.randomUUID().replace(/-/g, "").slice(0, 12);
	return Math.random().toString(36).slice(2, 14);
}

export { optionalStringArray as a, optionalString as b, optionalUnit as c, optionalBool as d, err as e, isParseError as i, ok as o, parseJsonBody as p, requireString as r, shortId as s };
//# sourceMappingURL=_lafs-C3_fBF_X.js.map
