import { parseCollectionObjectPath } from "@/worker/dav/paths"; import type { ProppatchInstruction } from "@/worker/xml/dav-request"; export type { DavConditionalHeaders, DavReadResult } from "@/worker/dav/readers"; export { acceptedDavOrigins, readCollectionPropfind, readCollectionProppatch, readDavConditionalHeaders, readReportDepth, } from "@/worker/dav/readers"; export type { DavResultError } from "@/worker/dav/responses"; export { davObjectResponse, davResultError, multigetMultistatus, protectedProppatchMultistatus, proppatchMultistatus, syncCollectionMultistatus, } from "@/worker/dav/responses"; export type CollectionDavPath = | { kind: "home" } | { kind: TCollectionKind; collectionName: string } | { kind: "object"; collectionName: string; objectName: string }; export type DavDeadPropInstruction = | { kind: "set"; nsUri: string; localName: string; xmlValue: string } | { kind: "remove"; nsUri: string; localName: string }; export function parseCollectionDavPath( pathname: string, basePath: string, collectionKind: TCollectionKind, ): CollectionDavPath | null { const path = parseCollectionObjectPath(pathname, basePath); if (!path) return null; if (path.kind === "home") return path; if (path.kind === "collection") return { kind: collectionKind, collectionName: path.collectionName }; return { kind: "object", collectionName: path.collectionName, objectName: path.objectName }; } export function collectionDavHref( path: CollectionDavPath, input: { homeHref: string; collectionHref: (collectionName: string) => string; objectHref: (collectionName: string, objectName: string) => string; }, ): string { if ("objectName" in path) return input.objectHref(path.collectionName, path.objectName); if ("collectionName" in path) return input.collectionHref(path.collectionName); return input.homeHref; } export function deadPropInstructions(instructions: ProppatchInstruction[]): DavDeadPropInstruction[] { return instructions.map((instruction) => instruction.kind === "set" ? { kind: "set", ...instruction.prop, xmlValue: instruction.xmlValue } : { kind: "remove", ...instruction.prop }, ); }