mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 00:51:20 +00:00
refactor: use switch/case in parser, move options
- Replace if/else chains with switch/case in ical-parser - Move CalendarSourceOptions to calendar-source.ts Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -8,9 +8,15 @@ import type {
|
|||||||
CalendarDAVClient,
|
CalendarDAVClient,
|
||||||
CalendarEventData,
|
CalendarEventData,
|
||||||
CalendarFeedItem,
|
CalendarFeedItem,
|
||||||
CalendarSourceOptions,
|
|
||||||
} from "./types.ts"
|
} from "./types.ts"
|
||||||
|
|
||||||
|
export interface CalendarSourceOptions {
|
||||||
|
/** Number of additional days beyond today to fetch. Default: 0 (today only). */
|
||||||
|
lookAheadDays?: number
|
||||||
|
/** Optional DAVClient instance for testing. Uses tsdav DAVClient by default. */
|
||||||
|
davClient?: CalendarDAVClient
|
||||||
|
}
|
||||||
|
|
||||||
import { CalendarKey, type CalendarContext } from "./calendar-context.ts"
|
import { CalendarKey, type CalendarContext } from "./calendar-context.ts"
|
||||||
import { parseICalEvents } from "./ical-parser.ts"
|
import { parseICalEvents } from "./ical-parser.ts"
|
||||||
|
|
||||||
|
|||||||
@@ -52,11 +52,16 @@ function parseVEvent(
|
|||||||
|
|
||||||
function parseStatus(raw: string | null): CalendarEventStatus | null {
|
function parseStatus(raw: string | null): CalendarEventStatus | null {
|
||||||
if (!raw) return null
|
if (!raw) return null
|
||||||
const lower = raw.toLowerCase()
|
switch (raw.toLowerCase()) {
|
||||||
if (lower === "confirmed") return CalendarEventStatus.Confirmed
|
case "confirmed":
|
||||||
if (lower === "tentative") return CalendarEventStatus.Tentative
|
return CalendarEventStatus.Confirmed
|
||||||
if (lower === "cancelled") return CalendarEventStatus.Cancelled
|
case "tentative":
|
||||||
return null
|
return CalendarEventStatus.Tentative
|
||||||
|
case "cancelled":
|
||||||
|
return CalendarEventStatus.Cancelled
|
||||||
|
default:
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseOrganizer(
|
function parseOrganizer(
|
||||||
@@ -97,21 +102,32 @@ function parseAttendees(properties: unknown[]): CalendarAttendee[] {
|
|||||||
|
|
||||||
function parseAttendeeRole(raw: string | null): AttendeeRole | null {
|
function parseAttendeeRole(raw: string | null): AttendeeRole | null {
|
||||||
if (!raw) return null
|
if (!raw) return null
|
||||||
const upper = raw.toUpperCase()
|
switch (raw.toUpperCase()) {
|
||||||
if (upper === "CHAIR") return AttendeeRole.Chair
|
case "CHAIR":
|
||||||
if (upper === "REQ-PARTICIPANT") return AttendeeRole.Required
|
return AttendeeRole.Chair
|
||||||
if (upper === "OPT-PARTICIPANT") return AttendeeRole.Optional
|
case "REQ-PARTICIPANT":
|
||||||
return null
|
return AttendeeRole.Required
|
||||||
|
case "OPT-PARTICIPANT":
|
||||||
|
return AttendeeRole.Optional
|
||||||
|
default:
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseAttendeeStatus(raw: string | null): AttendeeStatus | null {
|
function parseAttendeeStatus(raw: string | null): AttendeeStatus | null {
|
||||||
if (!raw) return null
|
if (!raw) return null
|
||||||
const upper = raw.toUpperCase()
|
switch (raw.toUpperCase()) {
|
||||||
if (upper === "ACCEPTED") return AttendeeStatus.Accepted
|
case "ACCEPTED":
|
||||||
if (upper === "DECLINED") return AttendeeStatus.Declined
|
return AttendeeStatus.Accepted
|
||||||
if (upper === "TENTATIVE") return AttendeeStatus.Tentative
|
case "DECLINED":
|
||||||
if (upper === "NEEDS-ACTION") return AttendeeStatus.NeedsAction
|
return AttendeeStatus.Declined
|
||||||
return null
|
case "TENTATIVE":
|
||||||
|
return AttendeeStatus.Tentative
|
||||||
|
case "NEEDS-ACTION":
|
||||||
|
return AttendeeStatus.NeedsAction
|
||||||
|
default:
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseAlarms(vevent: InstanceType<typeof ICAL.Component>): CalendarAlarm[] {
|
function parseAlarms(vevent: InstanceType<typeof ICAL.Component>): CalendarAlarm[] {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export { CalendarKey, type CalendarContext } from "./calendar-context.ts"
|
export { CalendarKey, type CalendarContext } from "./calendar-context.ts"
|
||||||
export { CalendarSource } from "./calendar-source.ts"
|
export { CalendarSource, type CalendarSourceOptions } from "./calendar-source.ts"
|
||||||
export {
|
export {
|
||||||
CalendarEventStatus,
|
CalendarEventStatus,
|
||||||
AttendeeRole,
|
AttendeeRole,
|
||||||
@@ -13,5 +13,4 @@ export {
|
|||||||
type CalendarAlarm,
|
type CalendarAlarm,
|
||||||
type CalendarEventData,
|
type CalendarEventData,
|
||||||
type CalendarFeedItem,
|
type CalendarFeedItem,
|
||||||
type CalendarSourceOptions,
|
|
||||||
} from "./types.ts"
|
} from "./types.ts"
|
||||||
|
|||||||
@@ -99,12 +99,3 @@ export interface CalendarDAVClient {
|
|||||||
}): Promise<CalendarDAVObject[]>
|
}): Promise<CalendarDAVObject[]>
|
||||||
credentials: Record<string, unknown>
|
credentials: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Source options --
|
|
||||||
|
|
||||||
export interface CalendarSourceOptions {
|
|
||||||
/** Number of additional days beyond today to fetch. Default: 0 (today only). */
|
|
||||||
lookAheadDays?: number
|
|
||||||
/** Optional DAVClient instance for testing. Uses tsdav DAVClient by default. */
|
|
||||||
davClient?: CalendarDAVClient
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user