@@ -24,9 +24,11 @@ import {
2424 ProjectId ,
2525 ThreadId ,
2626} from "@t3tools/contracts" ;
27+ import * as Arr from "effect/Array" ;
2728import * as Effect from "effect/Effect" ;
2829import * as Layer from "effect/Layer" ;
2930import * as Option from "effect/Option" ;
31+ import * as Result from "effect/Result" ;
3032import * as Schema from "effect/Schema" ;
3133import * as Struct from "effect/Struct" ;
3234import * as SqlClient from "effect/unstable/sql/SqlClient" ;
@@ -1488,34 +1490,36 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
14881490
14891491 const snapshot = {
14901492 snapshotSequence : computeSnapshotSequence ( stateRows ) ,
1491- projects : projectRows
1492- . filter ( ( row ) => row . deletedAt === null )
1493- . map ( ( row ) =>
1494- mapProjectShellRow ( row , repositoryIdentities . get ( row . projectId ) ?? null ) ,
1495- ) ,
1496- threads : threadRows
1497- . filter ( ( row ) => row . deletedAt === null )
1498- . map (
1499- ( row ) : OrchestrationThreadShell => ( {
1500- id : row . threadId ,
1501- projectId : row . projectId ,
1502- title : row . title ,
1503- modelSelection : row . modelSelection ,
1504- runtimeMode : row . runtimeMode ,
1505- interactionMode : row . interactionMode ,
1506- branch : row . branch ,
1507- worktreePath : row . worktreePath ,
1508- latestTurn : latestTurnByThread . get ( row . threadId ) ?? null ,
1509- createdAt : row . createdAt ,
1510- updatedAt : row . updatedAt ,
1511- archivedAt : row . archivedAt ,
1512- session : sessionByThread . get ( row . threadId ) ?? null ,
1513- latestUserMessageAt : row . latestUserMessageAt ,
1514- hasPendingApprovals : row . pendingApprovalCount > 0 ,
1515- hasPendingUserInput : row . pendingUserInputCount > 0 ,
1516- hasActionableProposedPlan : row . hasActionableProposedPlan > 0 ,
1517- } ) ,
1518- ) ,
1493+ projects : Arr . filterMap ( projectRows , ( row ) =>
1494+ row . deletedAt === null
1495+ ? Result . succeed (
1496+ mapProjectShellRow ( row , repositoryIdentities . get ( row . projectId ) ?? null ) ,
1497+ )
1498+ : Result . failVoid ,
1499+ ) ,
1500+ threads : Arr . filterMap ( threadRows , ( row ) =>
1501+ row . deletedAt === null
1502+ ? Result . succeed ( {
1503+ id : row . threadId ,
1504+ projectId : row . projectId ,
1505+ title : row . title ,
1506+ modelSelection : row . modelSelection ,
1507+ runtimeMode : row . runtimeMode ,
1508+ interactionMode : row . interactionMode ,
1509+ branch : row . branch ,
1510+ worktreePath : row . worktreePath ,
1511+ latestTurn : latestTurnByThread . get ( row . threadId ) ?? null ,
1512+ createdAt : row . createdAt ,
1513+ updatedAt : row . updatedAt ,
1514+ archivedAt : row . archivedAt ,
1515+ session : sessionByThread . get ( row . threadId ) ?? null ,
1516+ latestUserMessageAt : row . latestUserMessageAt ,
1517+ hasPendingApprovals : row . pendingApprovalCount > 0 ,
1518+ hasPendingUserInput : row . pendingUserInputCount > 0 ,
1519+ hasActionableProposedPlan : row . hasActionableProposedPlan > 0 ,
1520+ } satisfies OrchestrationThreadShell )
1521+ : Result . failVoid ,
1522+ ) ,
15191523 updatedAt : updatedAt ?? "1970-01-01T00:00:00.000Z" ,
15201524 } ;
15211525
@@ -1621,11 +1625,13 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
16211625
16221626 const snapshot = {
16231627 snapshotSequence : computeSnapshotSequence ( stateRows ) ,
1624- projects : projectRows
1625- . filter ( ( row ) => row . deletedAt === null && activeProjectIds . has ( row . projectId ) )
1626- . map ( ( row ) =>
1627- mapProjectShellRow ( row , repositoryIdentities . get ( row . projectId ) ?? null ) ,
1628- ) ,
1628+ projects : Arr . filterMap ( projectRows , ( row ) =>
1629+ row . deletedAt === null && activeProjectIds . has ( row . projectId )
1630+ ? Result . succeed (
1631+ mapProjectShellRow ( row , repositoryIdentities . get ( row . projectId ) ?? null ) ,
1632+ )
1633+ : Result . failVoid ,
1634+ ) ,
16291635 threads : threadRows . map (
16301636 ( row ) : OrchestrationThreadShell => ( {
16311637 id : row . threadId ,
0 commit comments