Skip to content
File

Blob: src/worker/objects/cal-dav/types.ts

typescript149 lines
1import type { CalendarResource as RepositoryCalendarResource } from "@/worker/db/cal-dav-do/repository";
2import type { CalendarSearchFilter } from "@/worker/caldav/ical/types";
3import type { ParsedIfHeader } from "@/worker/dav/if-header";
4 
5export type CalDavErrorCode =
6 | "bad_request"
7 | "conflict"
8 | "forbidden"
9 | "method_not_allowed"
10 | "not_found"
11 | "payload_too_large"
12 | "precondition_failed";
13 
14export interface CalDavError {
15 ok: false;
16 status: number;
17 code: CalDavErrorCode;
18 message: string;
19}
20 
21export type CalendarResource = RepositoryCalendarResource;
22 
23export 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 
37export interface EnsureInitializedInput {
38 subjectId: string;
39 nowMs: number;
40}
41 
42export type CalendarListInput = EnsureInitializedInput;
43 
44export interface CalendarGetInput extends EnsureInitializedInput {
45 id: string;
46}
47 
48export 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 
57export 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 
66export interface CalendarDeleteInput extends EnsureInitializedInput {
67 id: string;
68}
69 
70export interface CalendarDeleteByNameInput extends EnsureInitializedInput {
71 name: string;
72}
73 
74export interface DescribeInput extends EnsureInitializedInput {
75 kind: "home" | "calendar" | "object";
76 calendarName?: string;
77 objectName?: string;
78 depth: "0" | "1";
79 maxResults: number;
80}
81 
82export 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 
94export interface GetCalendarObjectInput extends EnsureInitializedInput {
95 calendarName: string;
96 objectName: string;
97}
98 
99export interface DeleteCalendarObjectInput extends EnsureInitializedInput {
100 calendarName: string;
101 objectName: string;
102 ifMatch: string | null;
103 ifNoneMatch: string | null;
104 ifHeader: ParsedIfHeader;
105}
106 
107export 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 
121export type SearchFilter = CalendarSearchFilter;
122 
123export interface CalendarQueryInput extends EnsureInitializedInput {
124 calendarName: string;
125 filters: SearchFilter[];
126 maxResults: number;
127 maxRecurrenceYears: number;
128 maxRecurrenceInstances: number;
129}
130 
131export 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 
140export interface SyncCollectionInput extends EnsureInitializedInput {
141 calendarName: string;
142 token: string | null;
143 maxResults: number;
144}
145 
146export function calDavError(status: number, code: CalDavErrorCode, message: string): CalDavError {
147 return { ok: false, status, code, message };
148}