Skip to content

Commit 896a463

Browse files
committed
Deduplicate DB row schemas for projects and threads
Export ProjectionProjectDbRow and ProjectionThreadDbRow from their respective repository Layer files and reuse them in ProjectionSnapshotQuery instead of redefining identical schemas. This eliminates the risk of the two read paths silently diverging if the mapFields transforms are updated in one place but not the other.
1 parent 3701c8b commit 896a463

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
OrchestrationCheckpointFile,
77
OrchestrationProposedPlanId,
88
OrchestrationReadModel,
9-
ProjectScript,
109
ThreadId,
1110
TurnId,
1211
type OrchestrationCheckpointSummary,
@@ -17,7 +16,6 @@ import {
1716
type OrchestrationSession,
1817
type OrchestrationThread,
1918
type OrchestrationThreadActivity,
20-
ModelSelection,
2119
} from "@t3tools/contracts";
2220
import { Effect, Layer, Schema, Struct } from "effect";
2321
import * as SqlClient from "effect/unstable/sql/SqlClient";
@@ -29,8 +27,9 @@ import {
2927
toPersistenceSqlError,
3028
type ProjectionRepositoryError,
3129
} from "../../persistence/Errors.ts";
30+
import { ProjectionProjectDbRow } from "../../persistence/Layers/ProjectionProjects.ts";
31+
import { ProjectionThreadDbRow } from "../../persistence/Layers/ProjectionThreads.ts";
3232
import { ProjectionCheckpoint } from "../../persistence/Services/ProjectionCheckpoints.ts";
33-
import { ProjectionProject } from "../../persistence/Services/ProjectionProjects.ts";
3433
import { ProjectionState } from "../../persistence/Services/ProjectionState.ts";
3534
import { ProjectionThreadActivity } from "../../persistence/Services/ProjectionThreadActivities.ts";
3635
import { ProjectionThreadMessage } from "../../persistence/Services/ProjectionThreadMessages.ts";
@@ -44,24 +43,15 @@ import {
4443
} from "../Services/ProjectionSnapshotQuery.ts";
4544

4645
const decodeReadModel = Schema.decodeUnknownEffect(OrchestrationReadModel);
47-
const ProjectionProjectDbRowSchema = ProjectionProject.mapFields(
48-
Struct.assign({
49-
defaultModelSelection: Schema.NullOr(Schema.fromJsonString(ModelSelection)),
50-
scripts: Schema.fromJsonString(Schema.Array(ProjectScript)),
51-
}),
52-
);
46+
const ProjectionProjectDbRowSchema = ProjectionProjectDbRow;
5347
const ProjectionThreadMessageDbRowSchema = ProjectionThreadMessage.mapFields(
5448
Struct.assign({
5549
isStreaming: Schema.Number,
5650
attachments: Schema.NullOr(Schema.fromJsonString(Schema.Array(ChatAttachment))),
5751
}),
5852
);
5953
const ProjectionThreadProposedPlanDbRowSchema = ProjectionThreadProposedPlan;
60-
const ProjectionThreadDbRowSchema = ProjectionThread.mapFields(
61-
Struct.assign({
62-
modelSelection: Schema.fromJsonString(ModelSelection),
63-
}),
64-
);
54+
const ProjectionThreadDbRowSchema = ProjectionThreadDbRow;
6555
const ProjectionThreadActivityDbRowSchema = ProjectionThreadActivity.mapFields(
6656
Struct.assign({
6757
payload: Schema.fromJsonString(Schema.Unknown),

apps/server/src/persistence/Layers/ProjectionProjects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
type ProjectionProjectRepositoryShape,
1313
} from "../Services/ProjectionProjects.ts";
1414

15-
const ProjectionProjectDbRow = ProjectionProject.mapFields(
15+
export const ProjectionProjectDbRow = ProjectionProject.mapFields(
1616
Struct.assign({
1717
defaultModelSelection: Schema.NullOr(Schema.fromJsonString(ModelSelection)),
1818
scripts: Schema.fromJsonString(Schema.Array(ProjectScript)),

apps/server/src/persistence/Layers/ProjectionThreads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "../Services/ProjectionThreads.ts";
1414
import { ModelSelection } from "@t3tools/contracts";
1515

16-
const ProjectionThreadDbRow = ProjectionThread.mapFields(
16+
export const ProjectionThreadDbRow = ProjectionThread.mapFields(
1717
Struct.assign({
1818
modelSelection: Schema.fromJsonString(ModelSelection),
1919
}),

0 commit comments

Comments
 (0)