@critical-path/svelte 0.5.3 → 0.5.4
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 +6 -0
- package/dist/activity-state.svelte.d.ts.map +1 -1
- package/dist/attachment-state.svelte.d.ts.map +1 -1
- package/dist/comment-state.svelte.d.ts.map +1 -1
- package/dist/index.js +24 -12
- package/package.json +1 -1
- package/src/activity-state.svelte.ts +6 -2
- package/src/attachment-state.svelte.ts +3 -1
- package/src/comment-state.svelte.ts +3 -1
- package/src/index.test.ts +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activity-state.svelte.d.ts","sourceRoot":"","sources":["../src/activity-state.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE/D,MAAM,WAAW,8BAA+B,SAAQ,OAAO;IAC7D,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,OAAO,EAAE,8BAA8B,EAAE,CAAC;CAC3C;AAED,qBAAa,iBAAiB;IA6ChB,OAAO,CAAC,MAAM;IAA6B,MAAM,CAAC,EAAE,MAAM;IA5CtE,QAAQ,YAAyB;IACjC,WAAW,eAA4B;IACvC,OAAO,UAA0B;IACjC,KAAK,eAA8B;IAEnC,OAAO,mCAiCJ;IAEH,qBAAqB,eAElB;gBAEiB,MAAM,EAAE,kBAAkB,EAAS,MAAM,CAAC,EAAE,MAAM,YAAA;IAEhE,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM;IAwBrB,UAAU,CACd,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC,EACjE,gBAAgB,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,G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MAAM;IAaxB,gBAAgB,CAAC,EAAE,EAAE,MAAM;CAYlC;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,kBAAkB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAEtG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment-state.svelte.d.ts","sourceRoot":"","sources":["../src/attachment-state.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,eAAe;IAKd,OAAO,CAAC,MAAM;IAA6B,MAAM,CAAC,EAAE,gBAAgB;IAJhF,IAAI,eAA4B;IAChC,OAAO,UAA0B;IACjC,KAAK,eAA8B;gBAEf,MAAM,EAAE,kBAAkB,EAAS,MAAM,CAAC,EAAE,gBAAgB,YAAA;IAE1E,KAAK,CAAC,MAAM,CAAC,EAAE,gBAAgB;IAe/B,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC;IAY1E,gBAAgB,CAAC,EAAE,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"attachment-state.svelte.d.ts","sourceRoot":"","sources":["../src/attachment-state.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,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,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAYnD,aAAa,CAAC,EAAE,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"comment-state.svelte.d.ts","sourceRoot":"","sources":["../src/comment-state.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,WAAW,eAAgB,SAAQ,OAAO;IAC9C,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B;AAED,qBAAa,YAAY;IAyBX,OAAO,CAAC,MAAM;IAA6B,MAAM,CAAC,EAAE,MAAM;IAxBtE,IAAI,YAAyB;IAC7B,OAAO,UAA0B;IACjC,KAAK,eAA8B;IAEnC,OAAO,oBAkBJ;gBAEiB,MAAM,EAAE,kBAAkB,EAAS,MAAM,CAAC,EAAE,MAAM,YAAA;IAEhE,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM;IAkBrB,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC;IAe5E,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAYnD,aAAa,CAAC,EAAE,EAAE,MAAM;CAY/B;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAE5F"}
|
package/dist/index.js
CHANGED
|
@@ -311,11 +311,14 @@ var c = class {
|
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
async deleteComment(e) {
|
|
314
|
+
let t = this.data;
|
|
315
|
+
this.data = this.data.filter((t) => t.id !== e);
|
|
314
316
|
try {
|
|
315
|
-
await this.client.deleteComment(e)
|
|
317
|
+
await this.client.deleteComment(e);
|
|
316
318
|
} catch (e) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
+
this.data = t;
|
|
320
|
+
let n = e instanceof Error ? e : Error(String(e));
|
|
321
|
+
throw this.error = n, n;
|
|
319
322
|
}
|
|
320
323
|
}
|
|
321
324
|
};
|
|
@@ -371,11 +374,14 @@ var u = class {
|
|
|
371
374
|
}
|
|
372
375
|
}
|
|
373
376
|
async deleteAttachment(e) {
|
|
377
|
+
let t = this.data;
|
|
378
|
+
this.data = this.data.filter((t) => t.id !== e);
|
|
374
379
|
try {
|
|
375
|
-
await this.client.deleteAttachment(e)
|
|
380
|
+
await this.client.deleteAttachment(e);
|
|
376
381
|
} catch (e) {
|
|
377
|
-
|
|
378
|
-
|
|
382
|
+
this.data = t;
|
|
383
|
+
let n = e instanceof Error ? e : Error(String(e));
|
|
384
|
+
throw this.error = n, n;
|
|
379
385
|
}
|
|
380
386
|
}
|
|
381
387
|
};
|
|
@@ -495,19 +501,25 @@ var f = class {
|
|
|
495
501
|
}
|
|
496
502
|
}
|
|
497
503
|
async deleteComment(e) {
|
|
504
|
+
let t = this.comments;
|
|
505
|
+
this.comments = this.comments.filter((t) => t.id !== e);
|
|
498
506
|
try {
|
|
499
|
-
await this.client.deleteComment(e)
|
|
507
|
+
await this.client.deleteComment(e);
|
|
500
508
|
} catch (e) {
|
|
501
|
-
|
|
502
|
-
|
|
509
|
+
this.comments = t;
|
|
510
|
+
let n = e instanceof Error ? e : Error(String(e));
|
|
511
|
+
throw this.error = n, n;
|
|
503
512
|
}
|
|
504
513
|
}
|
|
505
514
|
async deleteAttachment(e) {
|
|
515
|
+
let t = this.attachments;
|
|
516
|
+
this.attachments = this.attachments.filter((t) => t.id !== e);
|
|
506
517
|
try {
|
|
507
|
-
await this.client.deleteAttachment(e)
|
|
518
|
+
await this.client.deleteAttachment(e);
|
|
508
519
|
} catch (e) {
|
|
509
|
-
|
|
510
|
-
|
|
520
|
+
this.attachments = t;
|
|
521
|
+
let n = e instanceof Error ? e : Error(String(e));
|
|
522
|
+
throw this.error = n, n;
|
|
511
523
|
}
|
|
512
524
|
}
|
|
513
525
|
};
|
package/package.json
CHANGED
|
@@ -129,10 +129,12 @@ export class TaskActivityState {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
async deleteComment(id: string) {
|
|
132
|
+
const previous = this.comments;
|
|
133
|
+
this.comments = this.comments.filter((c) => c.id !== id);
|
|
132
134
|
try {
|
|
133
135
|
await this.client.deleteComment(id);
|
|
134
|
-
this.comments = this.comments.filter((c) => c.id !== id);
|
|
135
136
|
} catch (err) {
|
|
137
|
+
this.comments = previous;
|
|
136
138
|
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
137
139
|
this.error = errorObj;
|
|
138
140
|
throw errorObj;
|
|
@@ -140,10 +142,12 @@ export class TaskActivityState {
|
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
async deleteAttachment(id: string) {
|
|
145
|
+
const previous = this.attachments;
|
|
146
|
+
this.attachments = this.attachments.filter((a) => a.id !== id);
|
|
143
147
|
try {
|
|
144
148
|
await this.client.deleteAttachment(id);
|
|
145
|
-
this.attachments = this.attachments.filter((a) => a.id !== id);
|
|
146
149
|
} catch (err) {
|
|
150
|
+
this.attachments = previous;
|
|
147
151
|
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
148
152
|
this.error = errorObj;
|
|
149
153
|
throw errorObj;
|
|
@@ -43,10 +43,12 @@ export class AttachmentState {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async deleteAttachment(id: string) {
|
|
46
|
+
const previous = this.data;
|
|
47
|
+
this.data = this.data.filter((a) => a.id !== id);
|
|
46
48
|
try {
|
|
47
49
|
await this.client.deleteAttachment(id);
|
|
48
|
-
this.data = this.data.filter((a) => a.id !== id);
|
|
49
50
|
} catch (err) {
|
|
51
|
+
this.data = previous;
|
|
50
52
|
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
51
53
|
this.error = errorObj;
|
|
52
54
|
throw errorObj;
|
|
@@ -79,10 +79,12 @@ export class CommentState {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
async deleteComment(id: string) {
|
|
82
|
+
const previous = this.data;
|
|
83
|
+
this.data = this.data.filter((c) => c.id !== id);
|
|
82
84
|
try {
|
|
83
85
|
await this.client.deleteComment(id);
|
|
84
|
-
this.data = this.data.filter((c) => c.id !== id);
|
|
85
86
|
} catch (err) {
|
|
87
|
+
this.data = previous;
|
|
86
88
|
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
87
89
|
this.error = errorObj;
|
|
88
90
|
throw errorObj;
|
package/src/index.test.ts
CHANGED
|
@@ -259,6 +259,32 @@ describe('@critical-path/svelte Svelte 5 Runes Test Suite', () => {
|
|
|
259
259
|
await attachmentState.deleteAttachment('att_1');
|
|
260
260
|
expect(attachmentState.data).toEqual([]);
|
|
261
261
|
});
|
|
262
|
+
|
|
263
|
+
it('rolls back optimistic deletion if deleteAttachment fails', async () => {
|
|
264
|
+
const mockAttachment = {
|
|
265
|
+
id: 'att_2',
|
|
266
|
+
filename: 'notes.txt',
|
|
267
|
+
mimeType: 'text/plain',
|
|
268
|
+
sizeBytes: 100,
|
|
269
|
+
url: 'https://storage.example.com/notes.txt',
|
|
270
|
+
uploaderId: 'u1',
|
|
271
|
+
uploaderType: 'user' as const,
|
|
272
|
+
createdAt: '2026-01-01',
|
|
273
|
+
updatedAt: '2026-01-01'
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const mockClient = {
|
|
277
|
+
getAttachments: vi.fn().mockResolvedValue([mockAttachment]),
|
|
278
|
+
deleteAttachment: vi.fn().mockRejectedValue(new Error('Network error'))
|
|
279
|
+
} as unknown as CriticalPathClient;
|
|
280
|
+
|
|
281
|
+
const attachmentState = new AttachmentState(mockClient, { taskId: 'task_1' });
|
|
282
|
+
await attachmentState.fetch();
|
|
283
|
+
|
|
284
|
+
expect(attachmentState.data).toHaveLength(1);
|
|
285
|
+
await expect(attachmentState.deleteAttachment('att_2')).rejects.toThrow('Network error');
|
|
286
|
+
expect(attachmentState.data).toEqual([mockAttachment]);
|
|
287
|
+
});
|
|
262
288
|
});
|
|
263
289
|
|
|
264
290
|
describe('TaskActivityState', () => {
|
|
@@ -304,6 +330,10 @@ describe('@critical-path/svelte Svelte 5 Runes Test Suite', () => {
|
|
|
304
330
|
expect(activityState.threads).toHaveLength(1);
|
|
305
331
|
expect(activityState.threads[0].attachments).toEqual([mockAttachment]);
|
|
306
332
|
expect(activityState.standaloneAttachments).toHaveLength(0);
|
|
333
|
+
|
|
334
|
+
await activityState.deleteAttachment('att_1');
|
|
335
|
+
expect(activityState.attachments).toEqual([]);
|
|
336
|
+
expect(activityState.threads[0].attachments).toEqual([]);
|
|
307
337
|
});
|
|
308
338
|
});
|
|
309
339
|
});
|