pi-jar 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/tasks.ts CHANGED
@@ -11,7 +11,7 @@ export type TodoStatus = (typeof TODO_STATUSES)[number];
11
11
  export interface Todo { id: string; title: string; done: boolean; status: TodoStatus; activeForm?: string; details?: string; parentId?: string }
12
12
  /** A parent's own `status` is ignored when it has subtasks. */
13
13
  export interface TodoInput { id?: string; title: string; status: TodoStatus; activeForm?: string; details?: string; subtasks?: readonly TodoInput[] }
14
- export type TodoReplacement = Partial<Omit<TodoInput, "id">>;
14
+ export type TodoUpdate = Partial<Omit<TodoInput, "id">>;
15
15
  /** Bounds the whole list: parents plus subtasks. */
16
16
  export const MAX_TODOS = 50;
17
17
 
@@ -312,12 +312,12 @@ export class TodoStore {
312
312
  } else next.push(...inputs);
313
313
  return this.write(next);
314
314
  }
315
- /** Replace only the addressed task. Omitted fields and subtasks are preserved. */
316
- replace(id: string, replacement: TodoReplacement): string | undefined {
317
- if (!this.items.has(id)) return "replace needs a valid existing task id.";
318
- if (!replacement || typeof replacement !== "object" || Array.isArray(replacement)) return "replace needs task fields.";
319
- if ("id" in replacement && replacement.id !== id) return "Replacement id must match the addressed task.";
320
- if (!Object.keys(replacement).some((key) => ["title", "status", "activeForm", "subtasks"].includes(key))) return "replace needs at least one task field.";
315
+ /** Update only the addressed task. Omitted fields and subtasks are preserved. */
316
+ update(id: string, replacement: TodoUpdate): string | undefined {
317
+ if (!this.items.has(id)) return "update needs a valid existing task id.";
318
+ if (!replacement || typeof replacement !== "object" || Array.isArray(replacement)) return "update needs task fields.";
319
+ if ("id" in replacement && replacement.id !== id) return "Update id must match the addressed task.";
320
+ if (!Object.keys(replacement).some((key) => ["title", "status", "activeForm", "subtasks"].includes(key))) return "update needs at least one task field.";
321
321
  const next = this.snapshot();
322
322
  const target = next.flatMap((item) => [item, ...(item.subtasks ?? [])]).find((item) => item.id === id)!;
323
323
  if (this.items.get(id)?.parentId && replacement.subtasks?.length) return "Subtasks cannot have their own subtasks; nest only one level.";