(db: Database, input: SnapshotCreateInput)
| 370 | } |
| 371 | |
| 372 | export function createSnapshot(db: Database, input: SnapshotCreateInput): DesignSnapshot { |
| 373 | return mutateStore(db, (data) => { |
| 374 | requireDesignIndex(data, input.designId); |
| 375 | const now = nowIso(); |
| 376 | const snapshot: DesignSnapshot = { |
| 377 | schemaVersion: 1, |
| 378 | id: crypto.randomUUID(), |
| 379 | designId: input.designId, |
| 380 | parentId: input.parentId, |
| 381 | type: input.type, |
| 382 | prompt: input.prompt, |
| 383 | artifactType: input.artifactType, |
| 384 | artifactSource: input.artifactSource, |
| 385 | createdAt: now, |
| 386 | ...(input.message !== undefined ? { message: input.message } : {}), |
| 387 | }; |
| 388 | data.snapshots.push(snapshot); |
| 389 | const designIdx = requireDesignIndex(data, input.designId); |
| 390 | const design = data.designs[designIdx]; |
| 391 | if (design === undefined) throw new Error(`Design not found: ${input.designId}`); |
| 392 | data.designs[designIdx] = { ...design, updatedAt: now }; |
| 393 | return snapshot; |
| 394 | }); |
| 395 | } |
| 396 | |
| 397 | export function listSnapshots(db: Database, designId: string): DesignSnapshot[] { |
| 398 | return readStore(db) |
no test coverage detected