File
Blob: src/worker/openapi/schemas.ts
| 1 | import { z } from "zod"; |
| 2 | |
| 3 | export const ErrorResponseSchema = z.object({ |
| 4 | error: z.object({ |
| 5 | code: z.string(), |
| 6 | message: z.string(), |
| 7 | }), |
| 8 | }); |
| 9 | |
| 10 | export const HealthResponseSchema = z.object({ |
| 11 | ok: z.literal(true), |
| 12 | service: z.literal("dab"), |
| 13 | }); |
| 14 | |
| 15 | export const DavScopeSchema = z.enum([ |
| 16 | "dav:files:read", |
| 17 | "dav:files:write", |
| 18 | "dav:caldav:read", |
| 19 | "dav:caldav:write", |
| 20 | "dav:carddav:read", |
| 21 | "dav:carddav:write", |
| 22 | ]); |
| 23 | |
| 24 | export const PatCreateRequestSchema = z.object({ |
| 25 | name: z.string().min(1), |
| 26 | scopes: z.array(z.string()).min(1), |
| 27 | expires_at: z.string().datetime().optional(), |
| 28 | }); |
| 29 | |
| 30 | export const PatPatchRequestSchema = z.object({ |
| 31 | name: z.string().min(1).optional(), |
| 32 | expires_at: z.string().datetime().nullable().optional(), |
| 33 | }); |
| 34 | |
| 35 | export const PatResponseSchema = z.object({ |
| 36 | id: z.string(), |
| 37 | name: z.string(), |
| 38 | scopes: z.array(DavScopeSchema), |
| 39 | created_at: z.string().datetime(), |
| 40 | expires_at: z.string().datetime().nullable(), |
| 41 | revoked_at: z.string().datetime().nullable().optional(), |
| 42 | last_used_at: z.string().datetime().nullable().optional(), |
| 43 | }); |
| 44 | |
| 45 | export const PatCreateResponseSchema = PatResponseSchema.extend({ |
| 46 | token: z.string(), |
| 47 | }); |
| 48 | |
| 49 | export const MeResponseSchema = z.object({ |
| 50 | subject_id: z.string(), |
| 51 | host_label: z.string(), |
| 52 | control_plane_host: z.string(), |
| 53 | dav_host: z.string(), |
| 54 | urls: z.object({ |
| 55 | api: z.string().url(), |
| 56 | root: z.string().url(), |
| 57 | files: z.string().url(), |
| 58 | caldav: z.string().url(), |
| 59 | carddav: z.string().url(), |
| 60 | }), |
| 61 | }); |
| 62 | |
| 63 | export const LogoutResponseSchema = z.object({ |
| 64 | ok: z.literal(true), |
| 65 | }); |
| 66 | |
| 67 | export const NamedResourceRequestSchema = z.object({ |
| 68 | name: z.string().min(1), |
| 69 | }); |
| 70 | |
| 71 | export const AddressbookCreateRequestSchema = z.object({ |
| 72 | name: z.string().min(1).max(128), |
| 73 | display_name: z.string().min(1).max(256).optional(), |
| 74 | description: z.string().max(4096).nullable().optional(), |
| 75 | }); |
| 76 | |
| 77 | export const AddressbookPatchRequestSchema = z.object({ |
| 78 | display_name: z.string().min(1).max(256).optional(), |
| 79 | description: z.string().max(4096).nullable().optional(), |
| 80 | }); |
| 81 | |
| 82 | export const AddressbookResponseSchema = z.object({ |
| 83 | id: z.string(), |
| 84 | name: z.string(), |
| 85 | display_name: z.string(), |
| 86 | description: z.string().nullable(), |
| 87 | href: z.string(), |
| 88 | created_at: z.string().datetime(), |
| 89 | modified_at: z.string().datetime(), |
| 90 | sync_token: z.string(), |
| 91 | }); |
| 92 | |
| 93 | export const CalendarCreateRequestSchema = z.object({ |
| 94 | name: z.string().min(1).max(128), |
| 95 | display_name: z.string().min(1).max(256).optional(), |
| 96 | description: z.string().max(4096).nullable().optional(), |
| 97 | color: z.string().max(64).nullable().optional(), |
| 98 | order_index: z.number().int().optional(), |
| 99 | timezone_ical: z.string().max(65536).nullable().optional(), |
| 100 | }); |
| 101 | |
| 102 | export const CalendarPatchRequestSchema = z.object({ |
| 103 | display_name: z.string().min(1).max(256).optional(), |
| 104 | description: z.string().max(4096).nullable().optional(), |
| 105 | color: z.string().max(64).nullable().optional(), |
| 106 | order_index: z.number().int().optional(), |
| 107 | timezone_ical: z.string().max(65536).nullable().optional(), |
| 108 | }); |
| 109 | |
| 110 | export const CalendarResponseSchema = z.object({ |
| 111 | id: z.string(), |
| 112 | name: z.string(), |
| 113 | display_name: z.string(), |
| 114 | description: z.string().nullable(), |
| 115 | href: z.string(), |
| 116 | color: z.string().nullable(), |
| 117 | order_index: z.number().int(), |
| 118 | timezone_ical: z.string().nullable(), |
| 119 | created_at: z.string().datetime(), |
| 120 | modified_at: z.string().datetime(), |
| 121 | sync_token: z.string(), |
| 122 | }); |
| 123 | |
| 124 | export const FileMetadataResponseSchema = z.object({ |
| 125 | href: z.string(), |
| 126 | path: z.string(), |
| 127 | name: z.string(), |
| 128 | kind: z.enum(["collection", "file"]), |
| 129 | size: z.number().int(), |
| 130 | content_type: z.string().nullable(), |
| 131 | content_language: z.string().nullable(), |
| 132 | etag: z.string().nullable(), |
| 133 | created_at: z.string().datetime(), |
| 134 | modified_at: z.string().datetime(), |
| 135 | }); |
| 136 | |
| 137 | export const FileListResponseSchema = z.object({ |
| 138 | directory: FileMetadataResponseSchema, |
| 139 | entries: z.array(FileMetadataResponseSchema), |
| 140 | }); |
| 141 | |
| 142 | export const FileMetadataQuerySchema = z.object({ |
| 143 | path: z.string().optional(), |
| 144 | }); |
| 145 | |
| 146 | export const FileListQuerySchema = z.object({ |
| 147 | path: z.string().optional(), |
| 148 | }); |
| 149 | |
| 150 | export const FileMkdirRequestSchema = z.object({ |
| 151 | path: z.string().min(1), |
| 152 | }); |
| 153 | |
| 154 | export const FileRenameRequestSchema = z.object({ |
| 155 | from: z.string().min(1), |
| 156 | to: z.string().min(1), |
| 157 | }); |
| 158 | |
| 159 | export const FileDeleteRequestSchema = z.object({ |
| 160 | path: z.string().min(1), |
| 161 | }); |