* Parse and validate YAML document in a single pass. * Checks for duplicate keys and other parsing errors, then converts to JavaScript object.
(yamlContent: string)
| 95 | * Checks for duplicate keys and other parsing errors, then converts to JavaScript object. |
| 96 | */ |
| 97 | function parseAndValidate(yamlContent: string): unknown { |
| 98 | const doc = parseDocument(yamlContent, { |
| 99 | strict: true, |
| 100 | uniqueKeys: true, |
| 101 | version: '1.2', |
| 102 | }) |
| 103 | |
| 104 | if (doc.errors.length > 0) { |
| 105 | const duplicateKeyError = doc.errors.find(err => err.message.includes('duplicate') || err.message.includes('key')) |
| 106 | if (duplicateKeyError) { |
| 107 | throw new YamlParseError(`Duplicate keys detected in Deepnote file: ${duplicateKeyError.message}`) |
| 108 | } |
| 109 | throw new YamlParseError(`YAML parsing error: ${doc.errors[0].message}`) |
| 110 | } |
| 111 | |
| 112 | return doc.toJS() |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Parse YAML content with strict validation rules: |