refactor(types): better type definitions

This commit is contained in:
Elian Doran 2025-02-28 19:44:32 +02:00
parent 5b9bfac1f8
commit 6f2a0f9ee1
No known key found for this signature in database
2 changed files with 6 additions and 5 deletions

View File

@ -3,9 +3,11 @@ import FNote from "../entities/fnote.js";
import froca from "../services/froca.js"; import froca from "../services/froca.js";
import FAttribute from "../entities/fattribute.js"; import FAttribute from "../entities/fattribute.js";
interface NoteDefinition { type AttributeDefinitions = { [key in `#${string}`]: string; }
interface NoteDefinition extends AttributeDefinitions {
id?: string | undefined;
title: string; title: string;
[key: string]: string;
} }
/** /**
@ -27,9 +29,8 @@ export function buildNotes(notes: NoteDefinition[]) {
const ids = []; const ids = [];
for (const noteDef of notes) { for (const noteDef of notes) {
const fakeNoteId = utils.randomString(6);
const note = new FNote(froca, { const note = new FNote(froca, {
noteId: fakeNoteId, noteId: noteDef.id ?? utils.randomString(12),
title: noteDef.title, title: noteDef.title,
type: "text", type: "text",
mime: "text/html", mime: "text/html",

View File

@ -18,7 +18,7 @@ describe("Building events", () => {
it("ignores notes with only end date", async () => { it("ignores notes with only end date", async () => {
const noteIds = buildNotes([ const noteIds = buildNotes([
{ title: "Note 1", "#endDate": "2025-05-05" }, { title: "Note 1", "#endDate": "2025-05-05" },
{ title: "Note 2", "#endDateDate": "2025-05-07" }, { title: "Note 2", "#endDateDate": "2025-05-07" }
]); ]);
const events = await CalendarView.buildEvents(noteIds); const events = await CalendarView.buildEvents(noteIds);