|
| 1 | +/** |
| 2 | + * Zod schemas for CLI validation |
| 3 | + */ |
| 4 | + |
| 5 | +import { z } from "zod" |
| 6 | + |
| 7 | +/** |
| 8 | + * Static entity type schema - validates supported entity types |
| 9 | + */ |
| 10 | +export const StaticEntityTypeSchema = z.enum([ |
| 11 | + "authors", |
| 12 | + "works", |
| 13 | + "institutions", |
| 14 | + "topics", |
| 15 | + "publishers", |
| 16 | + "funders", |
| 17 | +]) |
| 18 | + |
| 19 | +/** |
| 20 | + * Query result item schema for display |
| 21 | + */ |
| 22 | +export const QueryResultItemSchema = z |
| 23 | + .object({ |
| 24 | + display_name: z.string().optional(), |
| 25 | + id: z.string().optional(), |
| 26 | + }) |
| 27 | + .strict() |
| 28 | + |
| 29 | +/** |
| 30 | + * Query result schema for API responses |
| 31 | + */ |
| 32 | +export const QueryResultSchema = z |
| 33 | + .object({ |
| 34 | + results: z.array(QueryResultItemSchema), |
| 35 | + meta: z |
| 36 | + .object({ |
| 37 | + count: z.number().optional(), |
| 38 | + }) |
| 39 | + .strict() |
| 40 | + .optional(), |
| 41 | + }) |
| 42 | + .strict() |
| 43 | + |
| 44 | +/** |
| 45 | + * List command options schema |
| 46 | + */ |
| 47 | +export const ListCommandOptionsSchema = z.object({ |
| 48 | + count: z.boolean().optional(), |
| 49 | + format: z.string().optional(), |
| 50 | +}) |
| 51 | + |
| 52 | +/** |
| 53 | + * Search command options schema |
| 54 | + */ |
| 55 | +export const SearchCommandOptionsSchema = z.object({ |
| 56 | + limit: z.union([z.string(), z.undefined()]).optional(), |
| 57 | + format: z.string().optional(), |
| 58 | +}) |
| 59 | + |
| 60 | +/** |
| 61 | + * Get typed command options schema |
| 62 | + */ |
| 63 | +export const GetTypedCommandOptionsSchema = z.object({ |
| 64 | + format: z.string().optional(), |
| 65 | + pretty: z.boolean().optional(), |
| 66 | + noCache: z.boolean().optional(), |
| 67 | + noSave: z.boolean().optional(), |
| 68 | + cacheOnly: z.boolean().optional(), |
| 69 | +}) |
| 70 | + |
| 71 | +/** |
| 72 | + * Stats command options schema |
| 73 | + */ |
| 74 | +export const StatsCommandOptionsSchema = z.object({ |
| 75 | + format: z.string().optional(), |
| 76 | +}) |
| 77 | + |
| 78 | +/** |
| 79 | + * Cache stats command options schema |
| 80 | + */ |
| 81 | +export const CacheStatsCommandOptionsSchema = z.object({ |
| 82 | + format: z.string().optional(), |
| 83 | +}) |
| 84 | + |
| 85 | +/** |
| 86 | + * Cache field coverage command options schema |
| 87 | + */ |
| 88 | +export const CacheFieldCoverageCommandOptionsSchema = z.object({ |
| 89 | + format: z.string().optional(), |
| 90 | +}) |
| 91 | + |
| 92 | +/** |
| 93 | + * Cache popular entities command options schema |
| 94 | + */ |
| 95 | +export const CachePopularEntitiesCommandOptionsSchema = z.object({ |
| 96 | + limit: z.union([z.string(), z.undefined()]).optional(), |
| 97 | + format: z.string().optional(), |
| 98 | +}) |
| 99 | + |
| 100 | +/** |
| 101 | + * Cache popular collections command options schema |
| 102 | + */ |
| 103 | +export const CachePopularCollectionsCommandOptionsSchema = z.object({ |
| 104 | + limit: z.union([z.string(), z.undefined()]).optional(), |
| 105 | + format: z.string().optional(), |
| 106 | +}) |
| 107 | + |
| 108 | +/** |
| 109 | + * Cache clear command options schema |
| 110 | + */ |
| 111 | +export const CacheClearCommandOptionsSchema = z.object({ |
| 112 | + confirm: z.boolean().optional(), |
| 113 | +}) |
| 114 | + |
| 115 | +/** |
| 116 | + * Static analyze command options schema |
| 117 | + */ |
| 118 | +export const StaticAnalyzeCommandOptionsSchema = z.object({ |
| 119 | + format: z.string().optional(), |
| 120 | +}) |
| 121 | + |
| 122 | +/** |
| 123 | + * Static generate command options schema |
| 124 | + */ |
| 125 | +export const StaticGenerateCommandOptionsSchema = z.object({ |
| 126 | + entityType: z.string().optional(), |
| 127 | + dryRun: z.boolean().optional(), |
| 128 | + force: z.boolean().optional(), |
| 129 | +}) |
| 130 | + |
| 131 | +/** |
| 132 | + * Cache generate static command options schema |
| 133 | + */ |
| 134 | +export const CacheGenerateStaticCommandOptionsSchema = z.object({ |
| 135 | + entityType: z.string().optional(), |
| 136 | + limit: z.union([z.string(), z.undefined()]).optional(), |
| 137 | + force: z.boolean().optional(), |
| 138 | + dryRun: z.boolean().optional(), |
| 139 | + format: z.string().optional(), |
| 140 | +}) |
| 141 | + |
| 142 | +/** |
| 143 | + * Cache validate static command options schema |
| 144 | + */ |
| 145 | +export const CacheValidateStaticCommandOptionsSchema = z.object({ |
| 146 | + format: z.string().optional(), |
| 147 | + verbose: z.boolean().optional(), |
| 148 | +}) |
| 149 | + |
| 150 | +/** |
| 151 | + * Cache clear static command options schema |
| 152 | + */ |
| 153 | +export const CacheClearStaticCommandOptionsSchema = z.object({ |
| 154 | + entityType: z.string().optional(), |
| 155 | + confirm: z.boolean().optional(), |
| 156 | +}) |
| 157 | + |
| 158 | +/** |
| 159 | + * Fetch command options schema |
| 160 | + */ |
| 161 | +export const FetchCommandOptionsSchema = z.object({ |
| 162 | + perPage: z.union([z.string(), z.undefined()]).optional(), |
| 163 | + page: z.union([z.string(), z.undefined()]).optional(), |
| 164 | + filter: z.string().optional(), |
| 165 | + select: z.string().optional(), |
| 166 | + sort: z.string().optional(), |
| 167 | + noCache: z.boolean().optional(), |
| 168 | + noSave: z.boolean().optional(), |
| 169 | + cacheOnly: z.boolean().optional(), |
| 170 | + format: z.string().optional(), |
| 171 | +}) |
| 172 | + |
| 173 | +// Export inferred types |
| 174 | +export type GetTypedCommandOptions = z.infer<typeof GetTypedCommandOptionsSchema> |
| 175 | +export type FetchCommandOptions = z.infer<typeof FetchCommandOptionsSchema> |
| 176 | +export type ListCommandOptions = z.infer<typeof ListCommandOptionsSchema> |
| 177 | +export type SearchCommandOptions = z.infer<typeof SearchCommandOptionsSchema> |
| 178 | +export type StatsCommandOptions = z.infer<typeof StatsCommandOptionsSchema> |
| 179 | +export type CacheStatsCommandOptions = z.infer<typeof CacheStatsCommandOptionsSchema> |
| 180 | +export type CacheFieldCoverageCommandOptions = z.infer<typeof CacheFieldCoverageCommandOptionsSchema> |
| 181 | +export type CachePopularEntitiesCommandOptions = z.infer<typeof CachePopularEntitiesCommandOptionsSchema> |
| 182 | +export type CachePopularCollectionsCommandOptions = z.infer<typeof CachePopularCollectionsCommandOptionsSchema> |
| 183 | +export type CacheClearCommandOptions = z.infer<typeof CacheClearCommandOptionsSchema> |
| 184 | +export type StaticAnalyzeCommandOptions = z.infer<typeof StaticAnalyzeCommandOptionsSchema> |
| 185 | +export type StaticGenerateCommandOptions = z.infer<typeof StaticGenerateCommandOptionsSchema> |
| 186 | +export type CacheGenerateStaticCommandOptions = z.infer<typeof CacheGenerateStaticCommandOptionsSchema> |
| 187 | +export type CacheValidateStaticCommandOptions = z.infer<typeof CacheValidateStaticCommandOptionsSchema> |
| 188 | +export type CacheClearStaticCommandOptions = z.infer<typeof CacheClearStaticCommandOptionsSchema> |
0 commit comments