(schemaPath: string)
| 137 | } |
| 138 | |
| 139 | async function readSchemaFromFileOrDirectory(schemaPath: string): Promise<LookupResult> { |
| 140 | let stats: fs.Stats |
| 141 | try { |
| 142 | stats = await stat(schemaPath) |
| 143 | } catch (e) { |
| 144 | if (e.code === 'ENOENT') { |
| 145 | return { ok: false, error: { kind: 'NotFound', path: schemaPath } } |
| 146 | } |
| 147 | throw e |
| 148 | } |
| 149 | |
| 150 | if (stats.isFile()) { |
| 151 | return readSchemaFromSingleFile(schemaPath) |
| 152 | } |
| 153 | |
| 154 | if (stats.isDirectory()) { |
| 155 | return readSchemaFromDirectory(schemaPath) |
| 156 | } |
| 157 | |
| 158 | return { ok: false, error: { kind: 'WrongType', path: schemaPath, expectedTypes: ['file', 'directory'] } } |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Tries to load schema from either provided |
no test coverage detected