File
Blob: src/worker/objects/cal-dav-object.ts
| 1 | import { DurableObject } from "cloudflare:workers"; |
| 2 | |
| 3 | import { createCalDavDoDb, type CalDavDoDb } from "@/worker/db/cal-dav-do/client"; |
| 4 | import { |
| 5 | createCalendar as createCalendarOp, |
| 6 | deleteCalendarByName as deleteCalendarByNameOp, |
| 7 | deleteCalendar as deleteCalendarOp, |
| 8 | getCalendar as getCalendarOp, |
| 9 | listCalendars as listCalendarsOp, |
| 10 | updateCalendar as updateCalendarOp, |
| 11 | } from "@/worker/objects/cal-dav/calendars"; |
| 12 | import { |
| 13 | calendarMultiget as calendarMultigetOp, |
| 14 | calendarQuery as calendarQueryOp, |
| 15 | deleteObject as deleteObjectOp, |
| 16 | getObject as getObjectOp, |
| 17 | putObject as putObjectOp, |
| 18 | syncCollection as syncCollectionOp, |
| 19 | } from "@/worker/objects/cal-dav/calendar-objects"; |
| 20 | import { |
| 21 | describe as describeOp, |
| 22 | ensureInitialized as ensureInitializedOp, |
| 23 | proppatch as proppatchOp, |
| 24 | } from "@/worker/objects/cal-dav/properties"; |
| 25 | import type { |
| 26 | CalendarCreateInput, |
| 27 | CalendarDeleteByNameInput, |
| 28 | CalendarDeleteInput, |
| 29 | CalendarGetInput, |
| 30 | CalendarListInput, |
| 31 | CalendarMultigetInput, |
| 32 | CalendarQueryInput, |
| 33 | CalendarUpdateInput, |
| 34 | DeleteCalendarObjectInput, |
| 35 | DescribeInput, |
| 36 | EnsureInitializedInput, |
| 37 | GetCalendarObjectInput, |
| 38 | ProppatchInput, |
| 39 | PutCalendarObjectInput, |
| 40 | SyncCollectionInput, |
| 41 | } from "@/worker/objects/cal-dav/types"; |
| 42 | import { migrateCalDavObject } from "@/worker/objects/common/migrations"; |
| 43 | |
| 44 | export type { |
| 45 | CalDavError, |
| 46 | CalDavErrorCode, |
| 47 | CalendarCreateInput, |
| 48 | CalendarDeleteByNameInput, |
| 49 | CalendarDeleteInput, |
| 50 | CalendarGetInput, |
| 51 | CalendarListInput, |
| 52 | CalendarMultigetInput, |
| 53 | CalendarQueryInput, |
| 54 | CalendarRecord, |
| 55 | CalendarResource, |
| 56 | CalendarUpdateInput, |
| 57 | DeleteCalendarObjectInput, |
| 58 | DescribeInput, |
| 59 | EnsureInitializedInput, |
| 60 | GetCalendarObjectInput, |
| 61 | ProppatchInput, |
| 62 | PutCalendarObjectInput, |
| 63 | SearchFilter, |
| 64 | SyncCollectionInput, |
| 65 | } from "@/worker/objects/cal-dav/types"; |
| 66 | |
| 67 | export class CalDavObject extends DurableObject<Env> { |
| 68 | readonly db: CalDavDoDb; |
| 69 | |
| 70 | constructor(ctx: DurableObjectState, env: Env) { |
| 71 | super(ctx, env); |
| 72 | this.db = createCalDavDoDb(ctx.storage); |
| 73 | |
| 74 | ctx.blockConcurrencyWhile(async () => { |
| 75 | await migrateCalDavObject(this.db); |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | async ping(): Promise<{ ok: true; object: "cal-dav" }> { |
| 80 | return { ok: true, object: "cal-dav" }; |
| 81 | } |
| 82 | |
| 83 | async ensureInitialized(input: EnsureInitializedInput) { |
| 84 | return ensureInitializedOp(this.db, input); |
| 85 | } |
| 86 | |
| 87 | async listCalendars(input: CalendarListInput) { |
| 88 | return listCalendarsOp(this.db, input); |
| 89 | } |
| 90 | |
| 91 | async getCalendar(input: CalendarGetInput) { |
| 92 | return getCalendarOp(this.db, input); |
| 93 | } |
| 94 | |
| 95 | async createCalendar(input: CalendarCreateInput) { |
| 96 | return createCalendarOp(this.db, input); |
| 97 | } |
| 98 | |
| 99 | async updateCalendar(input: CalendarUpdateInput) { |
| 100 | return updateCalendarOp(this.db, input); |
| 101 | } |
| 102 | |
| 103 | async deleteCalendar(input: CalendarDeleteInput) { |
| 104 | return deleteCalendarOp(this.db, input); |
| 105 | } |
| 106 | |
| 107 | async deleteCalendarByName(input: CalendarDeleteByNameInput) { |
| 108 | return deleteCalendarByNameOp(this.db, input); |
| 109 | } |
| 110 | |
| 111 | async describe(input: DescribeInput) { |
| 112 | return describeOp(this.db, input); |
| 113 | } |
| 114 | |
| 115 | async getObject(input: GetCalendarObjectInput) { |
| 116 | return getObjectOp(this.db, input); |
| 117 | } |
| 118 | |
| 119 | async putObject(input: PutCalendarObjectInput) { |
| 120 | return putObjectOp(this.db, input); |
| 121 | } |
| 122 | |
| 123 | async deleteObject(input: DeleteCalendarObjectInput) { |
| 124 | return deleteObjectOp(this.db, input); |
| 125 | } |
| 126 | |
| 127 | async proppatch(input: ProppatchInput) { |
| 128 | return proppatchOp(this.db, input); |
| 129 | } |
| 130 | |
| 131 | async calendarQuery(input: CalendarQueryInput) { |
| 132 | return calendarQueryOp(this.db, input); |
| 133 | } |
| 134 | |
| 135 | async calendarMultiget(input: CalendarMultigetInput) { |
| 136 | return calendarMultigetOp(this.db, input); |
| 137 | } |
| 138 | |
| 139 | async syncCollection(input: SyncCollectionInput) { |
| 140 | return syncCollectionOp(this.db, input); |
| 141 | } |
| 142 | } |