File size: 6,954 Bytes
c09f67c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | import { z } from "@hono/zod-openapi";
export const getDocumentsSchema = z
.object({
cursor: z.string().nullable().optional().openapi({
description:
"A cursor for pagination. Pass the value returned from the previous response to get the next page.",
example: "20",
}),
sort: z
.array(z.string().min(1))
.max(2)
.min(2)
.nullable()
.optional()
.openapi({
description:
"Sorting order as a tuple: [field, direction]. Example: ['name', 'asc'].",
param: {
in: "query",
},
}),
pageSize: z.coerce.number().min(1).max(100).optional().openapi({
description: "Number of documents to return per page.",
example: 20,
}),
q: z.string().nullable().optional().openapi({
description: "Search query string to filter documents by text.",
example: "invoice",
}),
tags: z
.array(z.string())
.nullable()
.optional()
.openapi({
description: "Array of tag IDs to filter documents by tags.",
example: ["tag1", "tag2"],
}),
})
.openapi({
description: "Query parameters for listing documents.",
});
export const getDocumentSchema = z.object({
id: z
.string()
.nullable()
.optional()
.openapi({
param: {
in: "path",
name: "id",
required: true,
},
}),
filePath: z.string().nullable().optional(),
});
export const getRelatedDocumentsSchema = z.object({
id: z.string().openapi({
param: {
in: "path",
name: "id",
},
}),
pageSize: z.coerce.number().min(1).max(100),
});
export const deleteDocumentSchema = z.object({
id: z.string().openapi({
param: {
in: "path",
name: "id",
},
}),
});
export const deleteDocumentResponseSchema = z.object({
id: z.string(),
});
export const reprocessDocumentSchema = z.object({
id: z
.string()
.uuid()
.openapi({
description: "The ID of the document to reprocess",
param: {
in: "path",
name: "id",
},
}),
});
export const processDocumentSchema = z.array(
z.object({
mimetype: z.string(),
size: z.number(),
filePath: z.array(z.string()),
}),
);
export const signedUrlSchema = z.object({
filePath: z.string(),
expireIn: z.number(),
});
export const signedUrlsSchema = z.array(z.string());
export const getDocumentPreSignedUrlSchema = z.object({
id: z
.string()
.uuid()
.openapi({
description:
"Unique identifier of the document to generate a pre-signed URL for",
example: "b3b7c1e2-4c2a-4e7a-9c1a-2b7c1e24c2a4",
param: {
in: "path",
name: "id",
},
}),
download: z.coerce
.boolean()
.optional()
.openapi({
description:
"Whether to force download the file. If true, the file will be downloaded. If false or omitted, the file will be displayed in the browser if possible.",
example: true,
param: {
in: "query",
name: "download",
},
}),
});
export const preSignedUrlResponseSchema = z.object({
url: z.string().url().openapi({
description:
"Pre-signed URL for accessing the document, valid for 60 seconds",
example:
"https://service.midday.ai/storage/v1/object/sign/vault/documents/2024/invoice.pdf?token=abc123&expires=1640995200",
}),
expiresAt: z.string().datetime().openapi({
description: "ISO 8601 timestamp when the URL expires",
example: "2024-04-15T10:01:00.000Z",
}),
fileName: z.string().nullable().openapi({
description: "Original filename of the document",
example: "invoice-april-2024.pdf",
}),
});
export const documentResponseSchema = z
.object({
id: z.string().openapi({
description: "Unique identifier for the document.",
example: "doc_1234567890abcdef",
}),
title: z.string().nullable().openapi({
description: "Title of the document.",
example: "Invoice April 2024",
}),
pathTokens: z.array(z.string()).openapi({
description: "Array of path tokens representing the document's location.",
example: ["invoices", "2024", "april", "invoice-123.pdf"],
}),
metadata: z
.object({
size: z.number().nullable().openapi({
description: "Size of the document in bytes.",
example: 204800,
}),
mimetype: z.string().nullable().openapi({
description: "MIME type of the document.",
example: "application/pdf",
}),
})
.nullable()
.openapi({
description: "Metadata about the document.",
}),
processingStatus: z.string().openapi({
description: "Processing status of the document.",
example: "processed",
}),
summary: z.string().nullable().openapi({
description: "Summary or extracted content from the document.",
example: "Invoice for April 2024, total $1,200.00",
}),
date: z.string().nullable().openapi({
description: "Date associated with the document (ISO 8601).",
example: "2024-04-30",
}),
})
.openapi({
description: "A single document object response.",
example: {
id: "doc_1234567890abcdef",
title: "Invoice April 2024",
pathTokens: ["invoices", "2024", "april", "invoice-123.pdf"],
metadata: {
size: 204800,
mimetype: "application/pdf",
},
processingStatus: "processed",
summary: "Invoice for April 2024, total $1,200.00",
date: "2024-04-30",
},
});
export const documentsResponseSchema = z
.object({
meta: z
.object({
cursor: z.string().nullable().optional().openapi({
description: "Cursor for pagination.",
example: "20",
}),
hasPreviousPage: z.boolean().openapi({
description: "Whether there is a previous page.",
example: false,
}),
hasNextPage: z.boolean().openapi({
description: "Whether there is a next page.",
example: true,
}),
})
.openapi({
description: "Pagination metadata for the documents list.",
}),
data: z.array(documentResponseSchema).openapi({
description: "Array of document objects.",
}),
})
.openapi({
description:
"Response containing a list of documents and pagination metadata.",
example: {
meta: {
cursor: "20",
hasPreviousPage: false,
hasNextPage: true,
},
data: [
{
id: "doc_1234567890abcdef",
title: "Invoice April 2024",
pathTokens: ["invoices", "2024", "april", "invoice-123.pdf"],
metadata: {
size: 204800,
mimetype: "application/pdf",
},
processingStatus: "processed",
summary: "Invoice for April 2024, total $1,200.00",
date: "2024-04-30",
},
],
},
});
|