1import * as Schema from "effect/Schema";
2import { EnvironmentId, PastedTextAttachmentSource } from "@t3tools/contracts";
3
4export const DraftComposerImageAttachmentSchema = Schema.Struct({
5 id: Schema.String,
6 previewUri: Schema.String,
7 type: Schema.Literal("image"),
8 name: Schema.String,
9 mimeType: Schema.String,
10 sizeBytes: Schema.Number,
11 // Accept future file-backed records before enabling the new image writers.
12 fileUri: Schema.optional(Schema.String.check(Schema.isNonEmpty())),
13 dataUrl: Schema.optional(Schema.String.check(Schema.isNonEmpty())),
14 uploadedAttachmentId: Schema.optional(Schema.String),
15 uploadEnvironmentId: Schema.optional(EnvironmentId),
16}).check(
17 Schema.makeFilter(
18 ({ fileUri, dataUrl }) =>
19 fileUri !== undefined ||
20 dataUrl !== undefined ||
21 "Image attachment has no file or inline bytes.",
22 ),
23);
24
25export const DraftComposerFileAttachmentSchema = Schema.Struct({
26 id: Schema.String,
27 type: Schema.Literal("file"),
28 name: Schema.String,
29 mimeType: Schema.String,
30 sizeBytes: Schema.Number,
31 fileUri: Schema.String,
32 source: Schema.optional(PastedTextAttachmentSource),
33 uploadedAttachmentId: Schema.optional(Schema.String),
34 uploadEnvironmentId: Schema.optional(EnvironmentId),
35});
36
37export const DraftComposerAttachmentSchema = Schema.Union([
38 DraftComposerImageAttachmentSchema,
39 DraftComposerFileAttachmentSchema,
40]);