From 70ea17dc28e72dd8d270fad20af520ef925c6ceb Mon Sep 17 00:00:00 2001 From: Sascha Reuter Date: Fri, 28 Nov 2025 01:06:23 +1100 Subject: [PATCH] add created timestamp and expose timestamps in toJson - parse `ct` field from API as `created` timestamp - add `createdAt` getter that converts to absolute Date - make `lastModifiedAt` return undefined when not available (fixes root node) - include `createdAt`, `lastModifiedAt`, `completedAt` in `toJson()` output - fix root-level node creation (send "None" instead of "Root" as parentid) --- src/document.ts | 19 +++++++++++++++---- src/export.ts | 3 +++ src/schema.ts | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/document.ts b/src/document.ts index 47a25d1..8ae4f82 100644 --- a/src/document.ts +++ b/src/document.ts @@ -276,9 +276,20 @@ export class List { return this.data.note || ""; } - /** Date of last change */ - public get lastModifiedAt(): Date { - return this.#companion.getRealTimestamp(this.data.lastModified); + /** Date of creation, or undefined if not available */ + public get createdAt(): Date | undefined { + if (this.data.created !== undefined) { + return this.#companion.getRealTimestamp(this.data.created); + } + return undefined; + } + + /** Date of last change, or undefined if not available */ + public get lastModifiedAt(): Date | undefined { + if (this.data.lastModified !== undefined) { + return this.#companion.getRealTimestamp(this.data.lastModified); + } + return undefined; } /** Date of completion, or undefined if not completed */ @@ -413,7 +424,7 @@ export class List { this.itemIds.splice(priority, 0, newId); - const parentid = this.id === "home" ? ROOT : this.id; + const parentid = this.id === ROOT ? "None" : this.id; this.#companion.addOperation(this.data.treeId, { type: "create", diff --git a/src/export.ts b/src/export.ts index 4700bb5..4412d5b 100644 --- a/src/export.ts +++ b/src/export.ts @@ -70,6 +70,9 @@ export function toJson(list: List): any { name: list.name, note: list.note, isCompleted: list.isCompleted, + createdAt: list.createdAt?.toISOString(), + lastModifiedAt: list.lastModifiedAt?.toISOString(), + completedAt: list.completedAt?.toISOString(), items: list.items.map((sublist) => toJson(sublist)), }; } diff --git a/src/schema.ts b/src/schema.ts index 32fc923..92a80aa 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -61,6 +61,7 @@ export const TreeDataSchema = z.object({ prnt: z.string().or(z.null()), pr: z.number(), cp: z.number().optional(), + ct: z.number().optional(), lm: z.number(), metadata: z.object({ mirror: z.object({ @@ -76,6 +77,7 @@ export const TreeDataSchema = z.object({ parentId: i.prnt !== null ? i.prnt : ROOT, priority: i.pr, completed: i.cp, + created: i.ct, lastModified: i.lm, originalId: i.metadata?.mirror?.originalId, isMirrorRoot: i.metadata?.mirror?.isMirrorRoot === true,