|
| 1 | +import type { TFile } from "obsidian"; |
| 2 | +import { |
| 3 | + appHasDailyNotesPluginLoaded as dailyNotesPluginLoadedUnsafe, |
| 4 | + createDailyNote as createDailyNoteUnsafe, |
| 5 | + getAllDailyNotes as getAllDailyNotesUnsafe, |
| 6 | + getDailyNote as getDailyNoteUnsafe, |
| 7 | + getDailyNoteSettings as getDailyNoteSettingsUnsafe, |
| 8 | + getDateFromFile as getDateFromFileUnsafe, |
| 9 | +} from "obsidian-daily-notes-interface"; |
| 10 | + |
| 11 | +export interface DailyNoteSettings { |
| 12 | + folder?: string; |
| 13 | + format?: string; |
| 14 | + template?: string; |
| 15 | +} |
| 16 | + |
| 17 | +export interface DailyNoteEntry { |
| 18 | + file: TFile; |
| 19 | + date: unknown; |
| 20 | +} |
| 21 | + |
| 22 | +// The upstream package ships its own obsidian dependency, which produces a |
| 23 | +// second TFile type. Centralize the boundary here so the rest of the codebase |
| 24 | +// can stay on our local obsidian types. |
| 25 | +export function appHasDailyNotesPluginLoaded(): boolean { |
| 26 | + return Boolean(dailyNotesPluginLoadedUnsafe()); |
| 27 | +} |
| 28 | + |
| 29 | +export async function createDailyNote(date: unknown): Promise<TFile> { |
| 30 | + return (await createDailyNoteUnsafe(date as never)) as unknown as TFile; |
| 31 | +} |
| 32 | + |
| 33 | +export function getAllDailyNotes(): DailyNoteEntry[] { |
| 34 | + return getAllDailyNotesUnsafe() as unknown as DailyNoteEntry[]; |
| 35 | +} |
| 36 | + |
| 37 | +export function getDailyNote( |
| 38 | + date: unknown, |
| 39 | + dailyNotes: DailyNoteEntry[], |
| 40 | +): TFile | null { |
| 41 | + const file = getDailyNoteUnsafe( |
| 42 | + date as never, |
| 43 | + dailyNotes as never, |
| 44 | + ) as unknown as TFile | null | undefined; |
| 45 | + return file ?? null; |
| 46 | +} |
| 47 | + |
| 48 | +export function getDailyNoteSettings(): DailyNoteSettings { |
| 49 | + return getDailyNoteSettingsUnsafe() as unknown as DailyNoteSettings; |
| 50 | +} |
| 51 | + |
| 52 | +export function getDateFromFile(file: TFile, granularity?: string): any { |
| 53 | + return getDateFromFileUnsafe( |
| 54 | + file as never, |
| 55 | + granularity as never, |
| 56 | + ) as any; |
| 57 | +} |
0 commit comments