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,
|
||||
CalendarEventData,
|
||||
CalendarFeedItem,
|
||||
CalendarSourceOptions,
|
||||
} 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 { parseICalEvents } from "./ical-parser.ts"
|
||||
|
||||
|
||||
@@ -52,11 +52,16 @@ function parseVEvent(
|
||||
|
||||
function parseStatus(raw: string | null): CalendarEventStatus | null {
|
||||
if (!raw) return null
|
||||
const lower = raw.toLowerCase()
|
||||
if (lower === "confirmed") return CalendarEventStatus.Confirmed
|
||||
if (lower === "tentative") return CalendarEventStatus.Tentative
|
||||
if (lower === "cancelled") return CalendarEventStatus.Cancelled
|
||||
return null
|
||||
switch (raw.toLowerCase()) {
|
||||
case "confirmed":
|
||||
return CalendarEventStatus.Confirmed
|
||||
case "tentative":
|
||||
return CalendarEventStatus.Tentative
|
||||
case "cancelled":
|
||||
return CalendarEventStatus.Cancelled
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function parseOrganizer(
|
||||
@@ -97,21 +102,32 @@ function parseAttendees(properties: unknown[]): CalendarAttendee[] {
|
||||
|
||||
function parseAttendeeRole(raw: string | null): AttendeeRole | null {
|
||||
if (!raw) return null
|
||||
const upper = raw.toUpperCase()
|
||||
if (upper === "CHAIR") return AttendeeRole.Chair
|
||||
if (upper === "REQ-PARTICIPANT") return AttendeeRole.Required
|
||||
if (upper === "OPT-PARTICIPANT") return AttendeeRole.Optional
|
||||
return null
|
||||
switch (raw.toUpperCase()) {
|
||||
case "CHAIR":
|
||||
return AttendeeRole.Chair
|
||||
case "REQ-PARTICIPANT":
|
||||
return AttendeeRole.Required
|
||||
case "OPT-PARTICIPANT":
|
||||
return AttendeeRole.Optional
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function parseAttendeeStatus(raw: string | null): AttendeeStatus | null {
|
||||
if (!raw) return null
|
||||
const upper = raw.toUpperCase()
|
||||
if (upper === "ACCEPTED") return AttendeeStatus.Accepted
|
||||
if (upper === "DECLINED") return AttendeeStatus.Declined
|
||||
if (upper === "TENTATIVE") return AttendeeStatus.Tentative
|
||||
if (upper === "NEEDS-ACTION") return AttendeeStatus.NeedsAction
|
||||
return null
|
||||
switch (raw.toUpperCase()) {
|
||||
case "ACCEPTED":
|
||||
return AttendeeStatus.Accepted
|
||||
case "DECLINED":
|
||||
return AttendeeStatus.Declined
|
||||
case "TENTATIVE":
|
||||
return AttendeeStatus.Tentative
|
||||
case "NEEDS-ACTION":
|
||||
return AttendeeStatus.NeedsAction
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function parseAlarms(vevent: InstanceType<typeof ICAL.Component>): CalendarAlarm[] {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export { CalendarKey, type CalendarContext } from "./calendar-context.ts"
|
||||
export { CalendarSource } from "./calendar-source.ts"
|
||||
export { CalendarSource, type CalendarSourceOptions } from "./calendar-source.ts"
|
||||
export {
|
||||
CalendarEventStatus,
|
||||
AttendeeRole,
|
||||
@@ -13,5 +13,4 @@ export {
|
||||
type CalendarAlarm,
|
||||
type CalendarEventData,
|
||||
type CalendarFeedItem,
|
||||
type CalendarSourceOptions,
|
||||
} from "./types.ts"
|
||||
|
||||
@@ -99,12 +99,3 @@ export interface CalendarDAVClient {
|
||||
}): Promise<CalendarDAVObject[]>
|
||||
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