File
Blob: src/worker/objects/card-dav/preconditions.ts
| 1 | import { addressbookHref } from "@/worker/carddav/paths"; |
| 2 | import type { CardDavDoDb } from "@/worker/db/card-dav-do/client"; |
| 3 | import { addressSyncToken, ensureAddressbook, latestChangeSeq, objectByName } from "@/worker/db/card-dav-do/repository"; |
| 4 | import { cardDavError, type CardDavError } from "@/worker/objects/card-dav/types"; |
| 5 | import { |
| 6 | collectionWritePrecondition, |
| 7 | type CollectionConditionalInput, |
| 8 | } from "@/worker/objects/common/collection-preconditions"; |
| 9 | |
| 10 | export type AddressConditionalInput = CollectionConditionalInput; |
| 11 | |
| 12 | export function addressWritePrecondition( |
| 13 | db: CardDavDoDb, |
| 14 | input: AddressConditionalInput, |
| 15 | targetHref: string, |
| 16 | targetEtag: string | null, |
| 17 | ): CardDavError | null { |
| 18 | return collectionWritePrecondition(db, input, targetHref, targetEtag, { |
| 19 | basePath: "/addressbooks", |
| 20 | collectionHref: addressbookHref, |
| 21 | ensureCollection: ensureAddressbook, |
| 22 | objectEtag: (db, bookId, objectName) => objectByName(db, bookId, objectName)?.etag ?? null, |
| 23 | latestChangeSeq, |
| 24 | syncToken: addressSyncToken, |
| 25 | preconditionFailed: (message) => cardDavError(412, "precondition_failed", message), |
| 26 | }); |
| 27 | } |