| 3485 | * @since 4.0.0 |
| 3486 | */ |
| 3487 | export function readJSDocModel(filename: string): Result<JSDocModel, string> { |
| 3488 | if (!fs.existsSync(filename)) return { _tag: "Failure", error: "missing" } |
| 3489 | try { |
| 3490 | const parsed = JSON.parse(fs.readFileSync(filename, "utf8")) as JSDocModel |
| 3491 | if (parsed.version !== 2) return { _tag: "Failure", error: "Unsupported jsdocs model version" } |
| 3492 | if (!Array.isArray(parsed.files)) return { _tag: "Failure", error: "Invalid jsdocs model: files must be an array" } |
| 3493 | if (!Array.isArray(parsed.apis)) return { _tag: "Failure", error: "Invalid jsdocs model: apis must be an array" } |
| 3494 | return { _tag: "Success", value: parsed } |
| 3495 | } catch (error) { |
| 3496 | return { _tag: "Failure", error: `Invalid jsdocs model: ${error instanceof Error ? error.message : String(error)}` } |
| 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | /** |
| 3501 | * Computes the content hash stored for a source file in a JSDoc model. |