| 3575 | * @since 4.0.0 |
| 3576 | */ |
| 3577 | export function readJSDocModel(filename: string): Result<JSDocModel, string> { |
| 3578 | if (!fs.existsSync(filename)) return { _tag: "Failure", error: "missing" } |
| 3579 | try { |
| 3580 | const parsed = JSON.parse(fs.readFileSync(filename, "utf8")) as JSDocModel |
| 3581 | if (parsed.version !== 3) return { _tag: "Failure", error: "Unsupported jsdocs model version" } |
| 3582 | if (!Array.isArray(parsed.files)) return { _tag: "Failure", error: "Invalid jsdocs model: files must be an array" } |
| 3583 | if (!Array.isArray(parsed.apis)) return { _tag: "Failure", error: "Invalid jsdocs model: apis must be an array" } |
| 3584 | return { _tag: "Success", value: parsed } |
| 3585 | } catch (error) { |
| 3586 | return { _tag: "Failure", error: `Invalid jsdocs model: ${error instanceof Error ? error.message : String(error)}` } |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | /** |
| 3591 | * Computes the content hash stored for a source file in a JSDoc model. |