| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | import * as SqlClient from "effect/unstable/sql/SqlClient"; | 1 | import * as SqlClient from "effect/unstable/sql/SqlClient"; |
| 2 | import * as SqlSchema from "effect/unstable/sql/SqlSchema"; | 2 | import * as SqlSchema from "effect/unstable/sql/SqlSchema"; |
| 3 | import { Effect, Layer, Schema } from "effect"; | 3 | import { Effect, Layer, Schema, Struct } from "effect"; |
| 4 | import { ChatAttachment } from "@t3tools/contracts"; | 4 | import { ChatAttachment } from "@t3tools/contracts"; |
| 5 | | 5 | |
| 6 | import { toPersistenceSqlError } from "../Errors.ts"; | 6 | import { toPersistenceSqlError } from "../Errors.ts"; |
| ... | @@ -12,11 +12,12 @@ import { | ... | @@ -12,11 +12,12 @@ import { |
| 12 | ProjectionThreadMessage, | 12 | ProjectionThreadMessage, |
| 13 | } from "../Services/ProjectionThreadMessages.ts"; | 13 | } from "../Services/ProjectionThreadMessages.ts"; |
| 14 | | 14 | |
| 15 | const ProjectionThreadMessageDbRowSchema = Schema.Struct({ | 15 | const ProjectionThreadMessageDbRowSchema = ProjectionThreadMessage.mapFields( |
| 16 | ...ProjectionThreadMessage.fields, | 16 | Struct.assign({ |
| 17 | isStreaming: Schema.Number, | 17 | isStreaming: Schema.Number, |
| 18 | attachments: Schema.NullOr(Schema.fromJsonString(Schema.Array(ChatAttachment))), | 18 | attachments: Schema.NullOr(Schema.fromJsonString(Schema.Array(ChatAttachment))), |
| 19 | }); | 19 | }), |
| | 20 | ); |
| 20 | | 21 | |
| 21 | const makeProjectionThreadMessageRepository = Effect.gen(function* () { | 22 | const makeProjectionThreadMessageRepository = Effect.gen(function* () { |
| 22 | const sql = yield* SqlClient.SqlClient; | 23 | const sql = yield* SqlClient.SqlClient; |
| ... | @@ -24,7 +25,8 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () { | ... | @@ -24,7 +25,8 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () { |
| 24 | const upsertProjectionThreadMessageRow = SqlSchema.void({ | 25 | const upsertProjectionThreadMessageRow = SqlSchema.void({ |
| 25 | Request: ProjectionThreadMessage, | 26 | Request: ProjectionThreadMessage, |
| 26 | execute: (row) => { | 27 | execute: (row) => { |
| 27 | const nextAttachmentsJson = row.attachments !== undefined ? JSON.stringify(row.attachments) : null; | 28 | const nextAttachmentsJson = |
| | 29 | row.attachments !== undefined ? JSON.stringify(row.attachments) : null; |
| 28 | return sql` | 30 | return sql` |
| 29 | INSERT INTO projection_thread_messages ( | 31 | INSERT INTO projection_thread_messages ( |
| 30 | message_id, | 32 | message_id, |