(
storage: OpenADEYjsMutationStorageAdapter,
taskId: string,
taskDoc: Y.Doc,
updatedAt: string,
usage?: unknown
)
| 351 | } |
| 352 | |
| 353 | async function syncTaskMetadataPreview( |
| 354 | storage: OpenADEYjsMutationStorageAdapter, |
| 355 | taskId: string, |
| 356 | taskDoc: Y.Doc, |
| 357 | updatedAt: string, |
| 358 | usage?: unknown |
| 359 | ): Promise<void> { |
| 360 | const meta = taskDoc.getMap("task:meta") |
| 361 | const repoId = stringValue(meta.get("repoId")) |
| 362 | if (!repoId) throw new Error(`Task ${taskId} is missing repoId`) |
| 363 | |
| 364 | const reposDoc = await loadDoc(storage, "code:repos") |
| 365 | try { |
| 366 | const repoMap = findRepoMap(reposDoc, repoId) |
| 367 | if (!repoMap) throw new Error(`Repository ${repoId} not found`) |
| 368 | const lastNonSnapshot = getLastNonSnapshotEvent(taskDoc) |
| 369 | const lastEventAt = typeof meta.get("lastEventAt") === "string" ? (meta.get("lastEventAt") as string) : undefined |
| 370 | const lastEvent = lastNonSnapshot ? getNonSnapshotEventPreview(lastNonSnapshot, lastEventAt ?? stringValue(lastNonSnapshot.get("createdAt"), updatedAt)) : undefined |
| 371 | reposDoc.transact(() => { |
| 372 | updateTaskPreview( |
| 373 | repoMap, |
| 374 | taskId, |
| 375 | { |
| 376 | title: stringValue(meta.get("title"), "Untitled task"), |
| 377 | closed: meta.get("closed"), |
| 378 | lastViewedAt: meta.get("lastViewedAt"), |
| 379 | lastEventAt, |
| 380 | lastEvent, |
| 381 | ...(usage !== undefined ? { usage } : {}), |
| 382 | }, |
| 383 | updatedAt |
| 384 | ) |
| 385 | }) |
| 386 | await saveDoc(storage, "code:repos", reposDoc) |
| 387 | } finally { |
| 388 | reposDoc.destroy() |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | async function syncActionEventPreview( |
| 393 | storage: OpenADEYjsMutationStorageAdapter, |
no test coverage detected