File
Blob: tests/worker/protocol/webdav/files-helpers.ts
| 1 | import { env } from "cloudflare:workers"; |
| 2 | |
| 3 | import type { ParsedIfHeader } from "@/worker/dav/if-header"; |
| 4 | import { normalizeFilesPath, type NormalizedDavPath } from "@/worker/dav/paths"; |
| 5 | import { createControlPlaneDb } from "@/worker/db/d1/client"; |
| 6 | import { getSubjectById } from "@/worker/db/d1/repository"; |
| 7 | |
| 8 | export function name(prefix: string): string { |
| 9 | return `${prefix}-${crypto.randomUUID()}`; |
| 10 | } |
| 11 | |
| 12 | export function filePath(pathname: string): NormalizedDavPath { |
| 13 | const result = normalizeFilesPath(pathname); |
| 14 | if (!result.ok) throw new Error(`Invalid test path: ${pathname}`); |
| 15 | return result.path; |
| 16 | } |
| 17 | |
| 18 | export const emptyIfHeader: ParsedIfHeader = { lists: [] }; |
| 19 | |
| 20 | export async function storageIdFor(subjectId: string): Promise<string> { |
| 21 | const subject = await getSubjectById(createControlPlaneDb(env.DAV_CONTROL_PLANE), subjectId); |
| 22 | if (!subject) throw new Error(`Missing subject ${subjectId}`); |
| 23 | return subject.storageId; |
| 24 | } |