import { env } from "cloudflare:workers"; import type { ParsedIfHeader } from "@/worker/dav/if-header"; import { normalizeFilesPath, type NormalizedDavPath } from "@/worker/dav/paths"; import { createControlPlaneDb } from "@/worker/db/d1/client"; import { getSubjectById } from "@/worker/db/d1/repository"; export function name(prefix: string): string { return `${prefix}-${crypto.randomUUID()}`; } export function filePath(pathname: string): NormalizedDavPath { const result = normalizeFilesPath(pathname); if (!result.ok) throw new Error(`Invalid test path: ${pathname}`); return result.path; } export const emptyIfHeader: ParsedIfHeader = { lists: [] }; export async function storageIdFor(subjectId: string): Promise { const subject = await getSubjectById(createControlPlaneDb(env.DAV_CONTROL_PLANE), subjectId); if (!subject) throw new Error(`Missing subject ${subjectId}`); return subject.storageId; }