@critical-path/svelte 0.5.4 → 0.6.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @critical-path/svelte
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e983557: Add first-class optional todo list (checklist) support to Task model and TaskEntity with helper methods (addTodo, toggleTodo, removeTodo) and updateTask helper in @critical-path/svelte.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [e983557]
12
+ - @critical-path/core@0.9.0
13
+ - @critical-path/client@0.4.4
14
+
3
15
  ## 0.5.4
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -114,6 +114,32 @@ var i = class {
114
114
  throw this.error = n, n;
115
115
  }
116
116
  }
117
+ async updateTask(e, t) {
118
+ let n = this.data.findIndex((t) => t.id === e);
119
+ if (n === -1) return this.client.updateTask(e, t);
120
+ let r = this.data[n], i = {
121
+ ...r,
122
+ ...t,
123
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
124
+ }, a = [...this.data];
125
+ a[n] = i, this.data = a;
126
+ try {
127
+ let n = await this.client.updateTask(e, t), r = this.data.findIndex((t) => t.id === e);
128
+ if (r !== -1) {
129
+ let e = [...this.data];
130
+ e[r] = n, this.data = e;
131
+ }
132
+ return n;
133
+ } catch (t) {
134
+ let n = this.data.findIndex((t) => t.id === e);
135
+ if (n !== -1) {
136
+ let e = [...this.data];
137
+ e[n] = r, this.data = e;
138
+ }
139
+ let i = t instanceof Error ? t : Error(String(t));
140
+ throw this.error = i, i;
141
+ }
142
+ }
117
143
  async updateTaskStatus(e, t) {
118
144
  let n = this.data.findIndex((t) => t.id === e);
119
145
  if (n === -1) return this.client.updateTask(e, { status: t });
@@ -9,6 +9,7 @@ export declare class TaskState {
9
9
  constructor(client: CriticalPathClient, projectId?: string | undefined);
10
10
  fetch(): Promise<void>;
11
11
  createTask(input: Omit<Task, 'id' | 'createdAt' | 'updatedAt'>): Promise<Task>;
12
+ updateTask(taskId: string, updates: Partial<Task>): Promise<Task>;
12
13
  updateTaskStatus(taskId: string, status: TaskStatus): Promise<Task>;
13
14
  deleteTask(taskId: string): Promise<boolean | undefined>;
14
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"task-state.svelte.d.ts","sourceRoot":"","sources":["../src/task-state.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE5D,qBAAa,SAAS;IAMlB,OAAO,CAAC,MAAM;IACP,SAAS,CAAC,EAAE,MAAM;IAN3B,IAAI,SAAsB;IAC1B,OAAO,UAA0B;IACjC,KAAK,eAA8B;gBAGzB,MAAM,EAAE,kBAAkB,EAC3B,SAAS,CAAC,EAAE,MAAM,YAAA;IAGrB,KAAK;IAYL,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC;IA2B9D,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAyCnD,UAAU,CAAC,MAAM,EAAE,MAAM;CAuBhC;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,kBAAkB,EAC1B,SAAS,CAAC,EAAE,MAAM,GACjB,SAAS,CAEX"}
1
+ {"version":3,"file":"task-state.svelte.d.ts","sourceRoot":"","sources":["../src/task-state.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE5D,qBAAa,SAAS;IAMlB,OAAO,CAAC,MAAM;IACP,SAAS,CAAC,EAAE,MAAM;IAN3B,IAAI,SAAsB;IAC1B,OAAO,UAA0B;IACjC,KAAK,eAA8B;gBAGzB,MAAM,EAAE,kBAAkB,EAC3B,SAAS,CAAC,EAAE,MAAM,YAAA;IAGrB,KAAK;IAYL,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC;IA2B9D,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC;IAyCjD,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAyCnD,UAAU,CAAC,MAAM,EAAE,MAAM;CAuBhC;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,kBAAkB,EAC1B,SAAS,CAAC,EAAE,MAAM,GACjB,SAAS,CAEX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@critical-path/svelte",
3
- "version": "0.5.4",
3
+ "version": "0.6.0",
4
4
  "description": "Svelte 5 Runes state and reactive integrations for Critical Path headless project management framework",
5
5
  "author": "Jack James",
6
6
  "license": "MIT",
@@ -18,8 +18,8 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@critical-path/client": "0.4.3",
22
- "@critical-path/core": "0.8.3"
21
+ "@critical-path/core": "0.9.0",
22
+ "@critical-path/client": "0.4.4"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "svelte": "^5.0.0"
package/src/index.test.ts CHANGED
@@ -131,7 +131,7 @@ describe('@critical-path/svelte Svelte 5 Runes Test Suite', () => {
131
131
  const mockClient = {
132
132
  getTasks: vi.fn().mockResolvedValue([mockTask]),
133
133
  createTask: vi.fn().mockResolvedValue(mockTask),
134
- updateTask: vi.fn().mockResolvedValue(updatedTask),
134
+ updateTask: vi.fn().mockImplementation((taskId: string, updates: Partial<Task>) => Promise.resolve({ ...mockTask, ...updates })),
135
135
  deleteTask: vi.fn().mockResolvedValue(undefined)
136
136
  } as unknown as CriticalPathClient;
137
137
 
@@ -144,6 +144,12 @@ describe('@critical-path/svelte Svelte 5 Runes Test Suite', () => {
144
144
  await taskState.updateTaskStatus('task_1', 'in_progress');
145
145
  expect(taskState.data[0].status).toBe('in_progress');
146
146
 
147
+ // Update task generic updates (e.g. todos)
148
+ await taskState.updateTask('task_1', {
149
+ todos: [{ id: 'todo_1', title: 'Checklist item', completed: true }]
150
+ });
151
+ expect(taskState.data[0].todos).toEqual([{ id: 'todo_1', title: 'Checklist item', completed: true }]);
152
+
147
153
  // Delete task
148
154
  await taskState.deleteTask('task_1');
149
155
  expect(taskState.data).toEqual([]);
@@ -51,6 +51,47 @@ export class TaskState {
51
51
  }
52
52
  }
53
53
 
54
+ async updateTask(taskId: string, updates: Partial<Task>) {
55
+ const idx = this.data.findIndex((t) => t.id === taskId);
56
+ if (idx === -1) {
57
+ return this.client.updateTask(taskId, updates);
58
+ }
59
+
60
+ const previousTask = this.data[idx];
61
+ const optimisticTask: Task = {
62
+ ...previousTask,
63
+ ...updates,
64
+ updatedAt: new Date().toISOString()
65
+ };
66
+
67
+ // Optimistically update local task
68
+ const newData = [...this.data];
69
+ newData[idx] = optimisticTask;
70
+ this.data = newData;
71
+
72
+ try {
73
+ const updated = await this.client.updateTask(taskId, updates);
74
+ const currentIdx = this.data.findIndex((t) => t.id === taskId);
75
+ if (currentIdx !== -1) {
76
+ const confirmedData = [...this.data];
77
+ confirmedData[currentIdx] = updated;
78
+ this.data = confirmedData;
79
+ }
80
+ return updated;
81
+ } catch (err) {
82
+ // Rollback to previous task on error
83
+ const rollbackIdx = this.data.findIndex((t) => t.id === taskId);
84
+ if (rollbackIdx !== -1) {
85
+ const rollbackData = [...this.data];
86
+ rollbackData[rollbackIdx] = previousTask;
87
+ this.data = rollbackData;
88
+ }
89
+ const errorObj = err instanceof Error ? err : new Error(String(err));
90
+ this.error = errorObj;
91
+ throw errorObj;
92
+ }
93
+ }
94
+
54
95
  async updateTaskStatus(taskId: string, status: TaskStatus) {
55
96
  const idx = this.data.findIndex((t) => t.id === taskId);
56
97
  if (idx === -1) {