Skip to content
File

Blob: tests/worker/protocol/webdav/files-helpers.ts

typescript25 lines
1import { env } from "cloudflare:workers";
2 
3import type { ParsedIfHeader } from "@/worker/dav/if-header";
4import { normalizeFilesPath, type NormalizedDavPath } from "@/worker/dav/paths";
5import { createControlPlaneDb } from "@/worker/db/d1/client";
6import { getSubjectById } from "@/worker/db/d1/repository";
7 
8export function name(prefix: string): string {
9 return `${prefix}-${crypto.randomUUID()}`;
10}
11 
12export 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 
18export const emptyIfHeader: ParsedIfHeader = { lists: [] };
19 
20export 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}