File
Blob: src/worker/objects/cal-dav/preconditions.ts
| 1 | import { calendarHref } from "@/worker/caldav/paths"; |
| 2 | import type { CalDavDoDb } from "@/worker/db/cal-dav-do/client"; |
| 3 | import { calendarSyncToken, ensureCalendar, latestChangeSeq, objectByName } from "@/worker/db/cal-dav-do/repository"; |
| 4 | import { calDavError, type CalDavError } from "@/worker/objects/cal-dav/types"; |
| 5 | import { |
| 6 | collectionWritePrecondition, |
| 7 | type CollectionConditionalInput, |
| 8 | } from "@/worker/objects/common/collection-preconditions"; |
| 9 | |
| 10 | export type CalendarConditionalInput = CollectionConditionalInput; |
| 11 | |
| 12 | export function calendarWritePrecondition( |
| 13 | db: CalDavDoDb, |
| 14 | input: CalendarConditionalInput, |
| 15 | targetHref: string, |
| 16 | targetEtag: string | null, |
| 17 | ): CalDavError | null { |
| 18 | return collectionWritePrecondition(db, input, targetHref, targetEtag, { |
| 19 | basePath: "/calendars", |
| 20 | collectionHref: calendarHref, |
| 21 | ensureCollection: ensureCalendar, |
| 22 | objectEtag: (db, calendarId, objectName) => objectByName(db, calendarId, objectName)?.etag ?? null, |
| 23 | latestChangeSeq, |
| 24 | syncToken: calendarSyncToken, |
| 25 | preconditionFailed: (message) => calDavError(412, "precondition_failed", message), |
| 26 | }); |
| 27 | } |