File
Blob: src/worker/objects/cal-dav/types.ts
| 1 | import type { CalendarResource as RepositoryCalendarResource } from "@/worker/db/cal-dav-do/repository"; |
| 2 | import type { CalendarSearchFilter } from "@/worker/caldav/ical/types"; |
| 3 | import type { ParsedIfHeader } from "@/worker/dav/if-header"; |
| 4 | |
| 5 | export type CalDavErrorCode = |
| 6 | | "bad_request" |
| 7 | | "conflict" |
| 8 | | "forbidden" |
| 9 | | "method_not_allowed" |
| 10 | | "not_found" |
| 11 | | "payload_too_large" |
| 12 | | "precondition_failed"; |
| 13 | |
| 14 | export interface CalDavError { |
| 15 | ok: false; |
| 16 | status: number; |
| 17 | code: CalDavErrorCode; |
| 18 | message: string; |
| 19 | } |
| 20 | |
| 21 | export type CalendarResource = RepositoryCalendarResource; |
| 22 | |
| 23 | export interface CalendarRecord { |
| 24 | id: string; |
| 25 | name: string; |
| 26 | displayName: string; |
| 27 | description: string | null; |
| 28 | href: string; |
| 29 | color: string | null; |
| 30 | orderIndex: number; |
| 31 | timezoneIcal: string | null; |
| 32 | createdAtMs: number; |
| 33 | modifiedAtMs: number; |
| 34 | syncToken: string; |
| 35 | } |
| 36 | |
| 37 | export interface EnsureInitializedInput { |
| 38 | subjectId: string; |
| 39 | nowMs: number; |
| 40 | } |
| 41 | |
| 42 | export type CalendarListInput = EnsureInitializedInput; |
| 43 | |
| 44 | export interface CalendarGetInput extends EnsureInitializedInput { |
| 45 | id: string; |
| 46 | } |
| 47 | |
| 48 | export interface CalendarCreateInput extends EnsureInitializedInput { |
| 49 | name: string; |
| 50 | displayName?: string; |
| 51 | description?: string | null; |
| 52 | color?: string | null; |
| 53 | orderIndex?: number; |
| 54 | timezoneIcal?: string | null; |
| 55 | } |
| 56 | |
| 57 | export interface CalendarUpdateInput extends EnsureInitializedInput { |
| 58 | id: string; |
| 59 | displayName?: string; |
| 60 | description?: string | null; |
| 61 | color?: string | null; |
| 62 | orderIndex?: number; |
| 63 | timezoneIcal?: string | null; |
| 64 | } |
| 65 | |
| 66 | export interface CalendarDeleteInput extends EnsureInitializedInput { |
| 67 | id: string; |
| 68 | } |
| 69 | |
| 70 | export interface CalendarDeleteByNameInput extends EnsureInitializedInput { |
| 71 | name: string; |
| 72 | } |
| 73 | |
| 74 | export interface DescribeInput extends EnsureInitializedInput { |
| 75 | kind: "home" | "calendar" | "object"; |
| 76 | calendarName?: string; |
| 77 | objectName?: string; |
| 78 | depth: "0" | "1"; |
| 79 | maxResults: number; |
| 80 | } |
| 81 | |
| 82 | export interface PutCalendarObjectInput extends EnsureInitializedInput { |
| 83 | calendarName: string; |
| 84 | objectName: string; |
| 85 | body: ArrayBuffer; |
| 86 | ifMatch: string | null; |
| 87 | ifNoneMatch: string | null; |
| 88 | ifHeader: ParsedIfHeader; |
| 89 | maxBytes: number; |
| 90 | maxRecurrenceYears: number; |
| 91 | maxRecurrenceInstances: number; |
| 92 | } |
| 93 | |
| 94 | export interface GetCalendarObjectInput extends EnsureInitializedInput { |
| 95 | calendarName: string; |
| 96 | objectName: string; |
| 97 | } |
| 98 | |
| 99 | export interface DeleteCalendarObjectInput extends EnsureInitializedInput { |
| 100 | calendarName: string; |
| 101 | objectName: string; |
| 102 | ifMatch: string | null; |
| 103 | ifNoneMatch: string | null; |
| 104 | ifHeader: ParsedIfHeader; |
| 105 | } |
| 106 | |
| 107 | export interface ProppatchInput extends EnsureInitializedInput { |
| 108 | kind: "home" | "calendar" | "object"; |
| 109 | resourceId: string | null; |
| 110 | calendarName?: string; |
| 111 | objectName?: string; |
| 112 | instructions: ( |
| 113 | | { kind: "set"; nsUri: string; localName: string; xmlValue: string } |
| 114 | | { kind: "remove"; nsUri: string; localName: string } |
| 115 | )[]; |
| 116 | ifMatch: string | null; |
| 117 | ifNoneMatch: string | null; |
| 118 | ifHeader: ParsedIfHeader; |
| 119 | } |
| 120 | |
| 121 | export type SearchFilter = CalendarSearchFilter; |
| 122 | |
| 123 | export interface CalendarQueryInput extends EnsureInitializedInput { |
| 124 | calendarName: string; |
| 125 | filters: SearchFilter[]; |
| 126 | maxResults: number; |
| 127 | maxRecurrenceYears: number; |
| 128 | maxRecurrenceInstances: number; |
| 129 | } |
| 130 | |
| 131 | export interface CalendarMultigetInput extends EnsureInitializedInput { |
| 132 | calendarName: string; |
| 133 | hrefs: string[]; |
| 134 | maxResults: number; |
| 135 | // Origins (scheme + host[:port]) that absolute hrefs are allowed to use. The |
| 136 | // canonical subject host is always accepted; empty means relative-only. |
| 137 | acceptedOrigins?: string[]; |
| 138 | } |
| 139 | |
| 140 | export interface SyncCollectionInput extends EnsureInitializedInput { |
| 141 | calendarName: string; |
| 142 | token: string | null; |
| 143 | maxResults: number; |
| 144 | } |
| 145 | |
| 146 | export function calDavError(status: number, code: CalDavErrorCode, message: string): CalDavError { |
| 147 | return { ok: false, status, code, message }; |
| 148 | } |